Sprite animation loops constantly? Need it to stop!
-
@Martin yeah i need to start doing this delete sprite its just taking the plunge
-
Just a side note
The following code "should" do exactly the same and not use a sprite slot
// Do whatever you need to do // In your loop you can now say for n = 0 to len(enemies) loop if enemies[n] != false then // do all your stuff, including when you're done with it... removeSprite(enemies[n]) enemies[n] = false endif repeat
I just realised why this doesn't work and I am going to try to get it addressed in a future patch as to me it is very odd behaviour and 100% cannot be "by design"
You cannot compare a sprite object to anything other than another sprite object, so setting it to false , null, void, 1, "nothing" or anything else will not work... hence the requirement for an empty sprite
-
Thanks for all the replies, I'll check them out today!
Just had a thought laying here after just waking up, and that is;
// Do whatever you need to do
// In your loop you can now say
for n = 0 to len(enemies) loop
if enemies[n].sprite != visible then
If explosionSprite[n] frame count>60
removeSprite(enemies[n])
Endif
endif
repeatAs only destroyed aliens will ever be exploding?...
Anyways, thaanjs again. Will update how it's gone :)
-
-
@SwitchedOn sorry I did not look up the docs, but what is the variable visible? Is this pseudo code?
-
@SwitchedOn
As soon as i hit an enemy, i put it outside the screen area and make it static.sprite.y = -10000// shoud be enough to avoid any collision with other sprites setSpriteSpeed( sprite, {0.0} ) // i don't want the enemy to come back in the screen
I don't delete the sprite,
-
@spikey said in Sprite animation loops constantly? Need it to stop!:
@SwitchedOn sorry I did not look up the docs, but what is the variable visible? Is this pseudo code?
Yea it is, but its a 'get'
getSpriteVisibility(spriteName)
Can also use a 'set'
setSpriteVisibility(sprintName, Boolean)
-
@doumdoum said in Sprite animation loops constantly? Need it to stop!:
@SwitchedOn
As soon as i hit an enemy, i put it outside the screen area and make it static.sprite.y = -10000// shoud be enough to avoid any collision with other sprites setSpriteSpeed( sprite, {0.0} ) // i don't want the enemy to come back in the screen
I don't delete the sprite,
Whilst this works, I wouldn't approve of this as a best practice way of doing things.
-
@MikeDX said in Sprite animation loops constantly? Need it to stop!:
@doumdoum said in Sprite animation loops constantly? Need it to stop!:
@SwitchedOn
As soon as i hit an enemy, i put it outside the screen area and make it static.sprite.y = -10000// shoud be enough to avoid any collision with other sprites setSpriteSpeed( sprite, {0.0} ) // i don't want the enemy to come back in the screen
I don't delete the sprite,
Whilst this works, I wouldn't approve of this as a best practice way of doing things.
Yep, could end up being a bit of a memory hog - plus as they are still active to a degree, could cause issues in detections etc.
-
In practice, in a space invader/galaxian game, i have a constant number of enemies (50 max).
I recycle the sprites on the next stage, only by changing properties.(ecolo coding)
Since the sprites are static and far away, they don't collide with bullets, Ships etc.
I do the same with bullets, explosions.
I admit it's a rough method, but it works well.
Give me stack and list, and i'll make it better.