how can i animate falling object ?
Can you provide more details? Is this a physics object (causing it to fall)? What kind of animation do you want it to do?
Rob
yes sir… its falling object with the use of physics…
i want my object like to blink2 and big small big small…
something like that…
You can probably use transitions for this. See the transition library: http://docs.coronalabs.com/api/library/transition/index.html
Rob
physics = require "physics" physics.start() local things = {} timer.performWithDelay(100, function() local rect rect= display.newRect(0,0, 10,10) rect.anchorX = 0.5 rect.anchorY = 0.5 rect.pulse = true rect.x = math.random() \* display.contentWidth rect.y = math.random() \* display.contentHeight /2 physics.addBody(rect, "dynamic") table.insert(things,rect) local index = table.getn(things) transition.to(rect, {time=2000, onComplete=function(event) rect.dead = true end}) end,0) local ground = display.newRect(display.contentWidth/2, display.contentHeight-25, display.contentWidth\*1.5, 50) physics.addBody(ground, "static") Runtime:addEventListener("enterFrame", function() for i,rect in pairs(things) do if rect.dead then display.remove(rect) things[i] = nil else if rect.pulse then rect.xScale = rect.xScale + 0.2 rect.yScale = rect.xScale + 0.2 else rect.xScale = rect.xScale - 0.2 rect.yScale = rect.xScale + 0.2 end if rect.xScale \> 2 then rect.pulse = false elseif rect.xScale \< 0.5 then rect.pulse = true end end end end)
Like this!
If you’re going to use the enterFrame listener you probably don’t need the transition.to. If you’re going to use the transition.to then you would change the scale and alpha in the transition parameters.
Rob
Can you provide more details? Is this a physics object (causing it to fall)? What kind of animation do you want it to do?
Rob
yes sir… its falling object with the use of physics…
i want my object like to blink2 and big small big small…
something like that…
You can probably use transitions for this. See the transition library: http://docs.coronalabs.com/api/library/transition/index.html
Rob
physics = require "physics" physics.start() local things = {} timer.performWithDelay(100, function() local rect rect= display.newRect(0,0, 10,10) rect.anchorX = 0.5 rect.anchorY = 0.5 rect.pulse = true rect.x = math.random() \* display.contentWidth rect.y = math.random() \* display.contentHeight /2 physics.addBody(rect, "dynamic") table.insert(things,rect) local index = table.getn(things) transition.to(rect, {time=2000, onComplete=function(event) rect.dead = true end}) end,0) local ground = display.newRect(display.contentWidth/2, display.contentHeight-25, display.contentWidth\*1.5, 50) physics.addBody(ground, "static") Runtime:addEventListener("enterFrame", function() for i,rect in pairs(things) do if rect.dead then display.remove(rect) things[i] = nil else if rect.pulse then rect.xScale = rect.xScale + 0.2 rect.yScale = rect.xScale + 0.2 else rect.xScale = rect.xScale - 0.2 rect.yScale = rect.xScale + 0.2 end if rect.xScale \> 2 then rect.pulse = false elseif rect.xScale \< 0.5 then rect.pulse = true end end end end)
Like this!
If you’re going to use the enterFrame listener you probably don’t need the transition.to. If you’re going to use the transition.to then you would change the scale and alpha in the transition parameters.
Rob