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 DaveVoyles

How can I store the player's location during death, so that I can respawn the player at that location, instead of from the beginning of the level again? I'm crafting a side-scrolling 2d shmup if that helps to give you a better idea.

I'm grabbing my player's current location and storing it in the update function for ig.game like so:

update: function (){
....
// Grab player's current location
var player = this.getEntitiesByType(EntityPlayer);
this.playerRestartPOS = this.player.pos;
console.log(this.player.pos);
....
}

Now obviously the player dies, and this returns to 0,0 because there is no player to access. How can I store the location just BEFORE the player died?

I want to take that, pass it back to the player, and have it restart at that point.

1 decade ago by Joncom

// player.js
kill: function() {
    ig.game.player_pos_at_death = this.pos; // save the player position
    this.parent(); // kill the player as usual
}

Then, when you spawn the player again, just use:
ig.game.player_pos_at_death.x
ig.game.player_pos_at_death.y

1 decade ago by DaveVoyles

Wow.

That was 100x easier than what I was using. Thanks!
Page 1 of 1
« first « previous next › last »