Particle Help

I was planning on making a particle/animation appear when my objects collide, but I’m not sure what the best way to do it is. What do you guys suggest? It will be put into the code below.

[lua]function createPiggyBank()
local piggyBankSheet = sprite.newSpriteSheet(“images/game_piggybank.png”, 96, 96)
local piggyBankSet = sprite.newSpriteSet(piggyBankSheet, 1, 8)
sprite.add(piggyBankSet, “pigsleft”, 1, 1, 60000, 0)
sprite.add(piggyBankSet, “pigmleft”, 2, 3, 150, 0)
sprite.add(piggyBankSet, “pigsright”, 5, 1, 60000, 0)
sprite.add(piggyBankSet, “pigmright”, 6, 3, 150, 0)
piggyBank = sprite.newSprite(piggyBankSet)
physics.addBody(piggyBank, “static”)
piggyBank.x = display.contentWidth / 2
piggyBank.y = 397
function piggyBank:collision(event)
if( event.other.type == “coinbronze”) then
scorePlaceThree = scorePlaceThree + 1
audio.play(coinSound)
elseif (event.other.type == “coinsilver”) then
scorePlaceThree = scorePlaceThree + 5
audio.play(coinSound)
elseif (event.other.type == “coingold”) then
scorePlaceTwo = scorePlaceTwo + 1
audio.play(coinSound)
elseif (event.other.type == “rock”) then

end
event.other:removeSelf()
end
piggyBank:addEventListener(“collision”, piggyBank)
end[/lua] [import]uid: 103624 topic_id: 18427 reply_id: 318427[/import]

Have you considered Particle Candy? Alternatively here’s something Jstrahan has been working on; http://developer.anscamobile.com/forum/2011/10/04/graffiti-particle-system-now-beta-testing

Peach :slight_smile: [import]uid: 52491 topic_id: 18427 reply_id: 70743[/import]

graffiti PS works pretty well and is free. I am using it in the game I’m currently working on. Particle Candy is probably better if you’re willing to shell out money and need more advanced stuff. (In fairness, the paid version of graffiti PS may well end up being better than Particle Candy, but it’s not out yet).
[import]uid: 36054 topic_id: 18427 reply_id: 70747[/import]

Now that I think about it, it’s not really a particle that I plan on using. I could probably get away with making an animating sprite and using a timer. Or is there a way to kill the sprite after it finishes animating? [import]uid: 103624 topic_id: 18427 reply_id: 72185[/import]

You can have the sprite listen for when it’s ended and then do whatever you like, yes.

Example;

[lua]local function spriteDone (event)
if event.phase == “end” then
print “sprite finished”
– do stuff here
end
end
instance1:addEventListener(“sprite”, spriteDone)[/lua]

Careful not to type “ended” rather than “end” - it’s easy to do because it is what we’re normally using in event phases.

Peach :slight_smile: [import]uid: 52491 topic_id: 18427 reply_id: 72337[/import]