Jump to content

Phaser apply velocity changes to multiple sprites at the same time


The_dude8080
 Share

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

 Share

  • Recently Browsing   0 members

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