Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Problem with adding actions on a group of elements.


Lysssss
 Share

Recommended Posts

Still working on the Phaser, making your first Phaser game tutorial. I am not familiar with js so the question might be easy. I added 5 baddies as a group after the tutorial and I was trying to make it move and change direction every 1 sec. I used a Direction function to determine the direction for 1 baddie. However, I tried to put the time.event.loop function in my loop of creating baddies, only 1 baddie will move around. Others had a velocity of 0. There's my code.

2222.png

33333.png

Link to comment
Share on other sites

When you are creating your baddies, you are assigning them all to the same variable...

This is overwriting which baddie it is pointing to, so when you get to your Direction function, the variable is pointing at the last one you created...

I see you are creating them with the baddies group... You can look into the forEach functions that a group has to loop over the baddies and call Direction on each of them...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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