hi there,
I am new to lua and corona… I was trying out one of the samples regarding chaging the gear rotation speed demo…
everything works fine… but when the stop button is clicked i want the animation to gradually stop as opposed to just stopping suddenly… I added a delay function… which works… but the animation on the screen still stops straight away… what am I doing wrong?
local ui = require(“ui”)
local background = display.newImage(‘background.png’)
local gear = display.newImage(‘gear.jpg’)
gear.xScale = .5
gear.yScale = .5
gear.y = display.contentHeight/2
gear.x = display.contentWidth/2
local rotateAmount = 1
local function animate(event)
gear.rotation = gear.rotation + rotateAmount
gear.rotation = gear.rotation + rotateAmount
end
local function SlowRotation()
print (rotateAmount)
if rotateAmount > 0 then
rotateAmount = rotateAmount -1
elseif rotateAmount < 0 then
rotateAmount = rotateAmount + 1
end
end
local function wait(millisecond)
local timerTime = system.getTimer()
timerTime = timerTime + millisecond
local timeNow = system.getTimer()
while timeNow < timerTime do
timeNow = system.getTimer()
end
SlowRotation();
end
local buttonHandler = function (event)
if event.phase == “release” then
if event.id == “stop” then
while rotateAmount ~= 0 do
wait(2000)
end
elseif event.id == “+1” then
rotateAmount = rotateAmount + 1
elseif event.id == “-1” then
rotateAmount = rotateAmount -1
elseif event.id == “reverse” then
rotateAmount = rotateAmount * -1
end
end
end
Runtime:addEventListener(“enterFrame”, animate)
local button1 = ui.newButton{
default = “buttonGray.png”,
over = “buttonGrayOver.png”,
onEvent = buttonHandler,
text = “Stop”,
id=“stop”,
size=12,
emboss=true
}
local button2 = ui.newButton{
default = “buttonGray.png”,
over = “buttonGrayOver.png”,
onEvent = buttonHandler,
text = “+1”,
id="+1",
size=12,
emboss=true
}
local button3 = ui.newButton{
default = “buttonGray.png”,
over = “buttonGrayOver.png”,
onEvent = buttonHandler,
text = “-1”,
id="-1",
size=12,
emboss=true
}
local button4 = ui.newButton{
default = “buttonGray.png”,
over = “buttonGrayOver.png”,
onEvent = buttonHandler,
text = “Reverse”,
id=“reverse”,
size=12,
emboss=true
}
button1.x = (display.contentWidth / 4 * 1) - display.contentWidth / 8; button1.y = display.contentHeight - 20
button2.x = (display.contentWidth / 4 * 2) - display.contentWidth / 8; button2.y = display.contentHeight - 20
button3.x = (display.contentWidth / 4 * 3) - display.contentWidth / 8; button3.y = display.contentHeight - 20
button4.x = (display.contentWidth / 4 * 4) - display.contentWidth / 8; button4.y = display.contentHeight - 20 [import]uid: 67619 topic_id: 9835 reply_id: 42484[/import]