Help spawning sprites with individual Health

I currently have a function that, when called every 2 seconds, spawns a new enemy ship that flies towards the player. I want each ship to have 2 health points, requiring two shots by the player to kill.

The problem is, the enemy (and its health) are created each time the function is called. The problem with this is that the health of an already spawned enemy flying towards the player is then reset to 2.

I know that I need to create the sprite outside of the function with its health and then just have the function call this sprite. Unfortunately, I just don’t know how to do this.

Hi!

I’m not sure I understand your problem right now. Remember that posting some code will help us to understand the problem :slight_smile:

I assume you’re storing the health in a global (or otherwise shared) variable? You should store each ship’s health on the ship object itself, then operate on that. You could either store it using the Data Manager (ship.data) or, for a simpler solution, directly on the ship itself (for example, in a health property - ship.health).

As Aitorman said, however, this is just a wild guess without seeing any code. At the very least, the spawning function and the collision handling functions should be sufficient.