Jump to content

Phaser apply velocity changes to multiple sprites at the same time


Recommended Posts

Hey. I am using phaser arcade physics. I want to make many sprites acts as one. That means that when I press one of my cursor keys (that adds velocity) all of the sprites should be applied the same properties. I did that with a group that included all the sprites (they were about 100) and did a for each when clicked on a cursor to get each of the group children. However I think it was too slow because the sprites didn't actually move at the same (the code didn't seem to tweak fast enough). I can't add them to a "null" parent sprite because I don't want them to get fixed-in-place positions related to the parent. I want them to freely interact with each other as individual sprites but the movement should be applied to all of them when cursor keys are clicked. Any idea on how to do this? Thank you

Link to comment
Share on other sites

pasting the code would help.
The normal way would be the one you already tried.

what would be possible too is:
make 2 variables: velX, velY.
by pressing your cursor keys, assign the values you want to the variables.

Each of your "movement" sprites have an update method, were you simply do:


this.body.velocity.x = velX;
this.body.velocity.y = velY;

regards :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...