Jump to content

Add sprite to another group keeping same x & y position.


GourmetGorilla
 Share

Recommended Posts

My group aliens is moving around. At some point I remove a single alien and put it in a deadAlien group like this:

deadAlien.add(alien);

However, my deadAlien group does not have the same x, y as the 'alive' aliens group. they just move to the top of the canvas. Ok thats's easy to fix right?

    deadAlien.x = aliens.x;    deadAlien.y = aliens.y;

However, now my deadAliens constantly move around in sync with the alive aliens.  Once an alien dies and is moved from the Aliens group into the deadAliens group, I need it to not change position (not to move to the top of the canvas), but also not have it's position dictated over time by the aliens group.

How do I accomplish this? 

 

Link to comment
Share on other sites

OK I tried the following:

    var deadAlien = alien;    deadAlien.x = alien.x;    deadAlien.y = alien.y;    deadAliens.add(deadAlien);

It's solved my scoring problem, as the scoring relies on living aliens, and when they're now in the deadAliens group, they're counted as dead.  

However, the deadAliens are not taking on the x, y position of the alien just as he was shot, the deadAlien is still jumping to the top of the page :(   
How do I stop them moving up there? 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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