Explosion that disturbs the surrounding physical objects.
Combining both hgvyas123’s and Canupa’s codes, I needed particles to affect other physical objects, and I got the code below. Thanks everyone. This is indeed one of the easiest explosion/particles/fireworks code around.
[lua]local particleNum = 10
function createParticles(e)
local myRandom = math.random
for i=1,particleNum do
local circle = display.newCircle( 0, 0, 5 )
circle:setFillColor(myRandom(255),myRandom(255),myRandom(255))
circle.x = e.x
circle.y = e.y
local x1 = e.x + math.cos(myRandom(360)) * myRandom(20,70)
local y1 = e.y + math.cos(myRandom(360)) * myRandom(20,70)
physics.addBody( circle, { radius=circle.width*0.5, bounce=1.0 } )
transition.to(circle, {x = x1,y = y1, time = 1000; alpha = 0;
transition = easing.outQuad,
onComplete = function ()
physics.removeBody(circle)
circle:removeSelf()
end ;})
end
end
Runtime:addEventListener(“tap”,createParticles)
----Uncomment this to remove the listener if unused, later on.
–Runtime:removeEventListener(“tap”,createParticles)[/lua] [import]uid: 58387 topic_id: 13399 reply_id: 120253[/import]