Maybe I’m not understanding sprites well, but
In my init code, I do the following:
boomSpriteSheet = sprite.newSpriteSheet("explosionsprites.png", 61, 61)
boomSpriteSet = sprite.newSpriteSet(boomSpriteSheet,1,16)
sprite.add(boomSpriteSet, "boom", 1, 16, 500, 1)
sprite.add(boomSpriteSet, "bang", 12, 16, 250, 1)
At this point I have two variants of my explosion, a big boom and a small one.
I have a function to play a given explosion:
local function newExplosion(x,y,size)
local boomInstance
boomInstance = sprite.newSprite(boomSpriteSet)
if size == "large" then
boomInstance:prepare("boom")
else
boomInstance:prepare("bang")
end
boomInstance.x = x
boomInstance.y = y
boomInstance:play()
boomInstance:addEventListener( "animation", removeExplosion )
audio.play( boomSound )
end
Now I’m noticing little dots hanging around on the screen, which is the last frame of the sprite animation. I’m sure these instances are eating up resources. I can get rid of the dot by adding another frame to the spite sheet that is empty, but thats just hiding the problem.
After going through the examples, reading the docs and api reference and searching the forums, it seems adding the event listener (which is in the above code) should solve my problem, but it didn’t.
Print statements in the event handler are not printing, which tells me its not getting called.
local function removeExplosion(event)
print(event.phase)
if event.phase == "end" then
print ("end explosiion")
event.target:removeSelf()
event.target = nil
end
end
So why is removeExplosion not being called and is my attempt to remove the instance the right track?
Thanks
Rob
[import]uid: 19626 topic_id: 8568 reply_id: 308568[/import]