Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Attanar

I have made some maps with entities (kind of coins) that disappear once the player takes them.

The thing is, if the player dies, I want to restart the level and bring those entities back to where they were.

If I use entity.kill() to remove the entities when the player picks them, then I can't find a way to spawn them back into their original position. I am sure this must be a common mechanic to many games, but I can't find any explanation on how to do this, or any property in the Entity docs that matches what I want to do.

Is there anything like a boolean "exists", that can be set to true or false, so that the entity wont be drawn or checked for collisions in case it is false?

Thanks :)

1 decade ago by vincentpiel

Since what you are doing is a bit particular, do not rely on kill : remove your entities from your game.entities by yourself using splice.
Maybe you want to push() those entities to some array before removing them.




   // within your game update, before exiting
    if (died) {
            var gameEntities = ig.game.entities;
            for (var i=0; i< gameEntities.length; ) {
                 var ent =gameEntities[i];
                 if ( some condition on ent )
                          gameEntities.splice(i,1);
                 else 
                           i++;
             }


   // when a new game starts, in init :
  
   if  (arrayStoringCoins && arrayStoringCoins.length) {
            var gameEntities = ig.game.entities;
            var i=0,  ent = null;
            while ( ent = arrayStoringCoins[i++] ) gameEntities.push(ent);
   }

1 decade ago by Joncom

If you reload the level, then all the entities would be back in their original positions including the player.

1 decade ago by Attanar

Thanks both guys.

I don't want to reload the level since I want the camera to move back to the original point.

What I did was save a list of the entity position once they were killed, and then respawn them on that position. Thanks for your help :)
Page 1 of 1
« first « previous next › last »