I've got a piece of code that checks if an enemy has been hurt, and if it has been hurt an animated sprite is created to show stars flashing around on the enemy, moving around in a random pattern following the enemy's position.
The problem is, the animated sprite only shows up every now and then, and most often not, but I never get an errormessage for trying to manipulate a sprite that doesn't exist when I set the sprite position or delete it.
Also, I've printed the enemy[n].hurt while playing and the flag shows up correctly. The depth of the enemy sprites is 10.
Here's the code:
for n = 1 to enemyAmount
if enemy[n].hurt = 1 then enemy[n].hurtTimer = enemy[n].hurtTimer + 1
if enemy[n].hurtTimer > 0
if getSpriteExists(enemy[n].sparkle) = 0
enemy[n].sparkle = cloneSprite(sparkle.ID)
setSpriteAnimation(enemy[n].sparkle, 64, 64, 5)
setSpriteDepth(enemy[n].sparkle, 5)
setSpriteSize(enemy[n].sparkle, 4, -1)
playSprite(enemy[n].sparkle, 10, 1, 1, 5)
endIf
rndX# = random(-20,20) * 0.1
rndY# = random(-20,20) * 0.1
setSpriteFrame(enemy[n].ID, 4)
setSpritePositionByOffset(enemy[n].sparkle, enemy[n].x# + rndX#, enemy[n].y# + rndY#)
endIf
if enemy[n].hurtTimer = 100
enemy[n].hurtTimer = 0
enemy[n].damaged = enemy[n].damaged + 1
enemy[n].hurt = 0
deleteSprite(enemy[n].sparkle)
endIf
next n
Is the problem that I create the sprite when it happens? I thought this would save a bit of resources instead of creating the "sparkle" sprite for each enemy beforehand and then just making it visible when I want it.
Thanks, Toby
My hovercraft is full of eels