[Resolved] Help with looping box animation for power gauge

I am new to lua and trying to program a power gauge box that expands and then shrinks and loops continually. Could someone look at my code and help me figure out why it stops? I’m trying to use the onComplete attribue of transition.to to call the other function.

Thanks!

[code]local powerGauge = display.newRect ( 550, 250, 50, 1)
powerGauge:setReferencePoint (display.BottomCenterReferencePoint)
powerGauge.yScale = 100

local function powerGaugeMoveBack()
print (“moveback”)
transition.to( powerGauge, { time=1500, yScale=100, onComplete=powerGaugeMove2 } )
end

local function powerGaugeMove()
print (“move”)
Runtime:removeEventListener(“enterFrame”, powerGaugeMove)
transition.to( powerGauge, { time=1500, yScale=1, onComplete=powerGaugeMoveBack } )
end

local function powerGaugeCall()
Runtime:removeEventListener(“enterFrame”, powerGaugeCall)
powerGauge.powerGaugeMoveBack = powerGaugeMoveBack()
powerGauge.powerGaugeMove = powerGaugeMove()
end

powerGaugeActive = 1
Runtime:addEventListener(“enterFrame”, powerGaugeCall)[/code] [import]uid: 153770 topic_id: 27225 reply_id: 327225[/import]

Might I suggest modifying this slightly?

[lua]local powerGauge = display.newRect ( 250, 250, 50, 1)
powerGauge:setReferencePoint (display.BottomCenterReferencePoint)
powerGauge.yScale = 100

local powerGaugeMoveBack
local powerGaugeMove

powerGaugeMoveBack = function()
print (“moveback”)
transition.to( powerGauge, { time=1500, yScale=100, onComplete=powerGaugeMove } )
end

powerGaugeMove = function()
print (“move”)
transition.to( powerGauge, { time=1500, yScale=1, onComplete=powerGaugeMoveBack } )
end

powerGaugeActive = 1
powerGaugeMove()[/lua]

Please let me know your thoughts.

Peach :slight_smile: [import]uid: 52491 topic_id: 27225 reply_id: 110621[/import]

Thanks a lot for the help Peach. Looks simple now! [import]uid: 153770 topic_id: 27225 reply_id: 110681[/import]

How do I mark this thread resolved? [import]uid: 153770 topic_id: 27225 reply_id: 110683[/import]

Done :slight_smile: [import]uid: 84637 topic_id: 27225 reply_id: 110705[/import]

No worries Travis - just FYI when we mark something as resolved we just do it manually by editing the thread title. That will change when we eventually upgrade our forum to something a little fancier :wink: [import]uid: 52491 topic_id: 27225 reply_id: 110826[/import]