Re-Spawning in same position with same enemy states [Help Needed]

Hey Everyone,

I have a question. I tried to add a lives system to my game where you have 2 lives and after you die you can re-spawn. and when you reach 0 lives you have to re-start. The problem that i am having is when i hit re-spawn, i can’t seem to figure out an efficient way of re-spawning enemies in the same position as they were when i died. and the same with the player. do you have any ideas on how to do this.

One theory i thought of was i could have the enemies & update method pause when i die and just have the re-spawn menu overlay the screen and when i hit respawn i plays the game again, what do you think. ?

Please help thanks :slight_smile:

You could save the spawn coords of the monster at some another var in each monster class. So, when you re-spawn set their coords to be equal to the spawn coords that you have set.

But the problem is, the enemies randomly spawn every level.

So add enemy constructor to take coordinates, or even better old enemy object, that’s what I would do.

I may be mistaken, but I think GlennBrann was asking how to keep htem in the same position as they were before the player died. In which case you should have a block of code in your update procedure that only runs when the player is alive, so if the player is dead the enemies stop moving and when he comes back they resume.

Thank you. That’s what i needed :slight_smile: