Hello,
Does anyone know how I remove a specific object, that spawns every 0.2 seconds after transition?
local function spawnRings()
local ringNr = math.random(1, 5)
ring = display.newImage("ring"..ringNr..".png", ball.x - ringVar, ball.y - ringVar)
worldGroup:insert(2, ring)
ring:setReferencePoint(display.CenterReferencePoint)
ring.xScale = ballSize/120
ring.yScale = ballSize/120
transition.to(ring, { time=800, xScale=ring.xScale\*2, yScale=ring.yScale\*2, alpha=0 })
end
local spawnRingsTimer = performAfterDelay(0.2, spawnRings, 0, true)
I’ve tried using this function:
local function destroyObj(obj)
obj:removeSelf()
obj = nil
end
and call it once the transition is done, but it just makes the game freeze…
Thanks in advance, [import]uid: 14018 topic_id: 9674 reply_id: 309674[/import]
in your transition.to it should be like this:
transition.to(ring, { time=800, xScale=ring.xScale\*2, yScale=ring.yScale\*2, alpha=0, onComplete = function () ring:removeSelf(); ring = nil; end })
That defines the function directly in the transition line, so you don’t need to write a separate function to do this. Corona lets you define functions anywhere (in timers, transitions etc). [import]uid: 51654 topic_id: 9674 reply_id: 35232[/import]
Thanks for the quick reply Naveen. I tried the code you provided but it also freezes my game… [import]uid: 14018 topic_id: 9674 reply_id: 35233[/import]
Try making your “ring” local in the first line when you make it. Or are you referencing ring in other places too? [import]uid: 51654 topic_id: 9674 reply_id: 35240[/import]
Great! Thanks a lot mate! I forgot to redeclare the ring local after mixing with different solutions!
Thanks works great now
[import]uid: 14018 topic_id: 9674 reply_id: 35242[/import]