Hello everyone,
I just started using Corona yesterday and I need some help.
Basically what I am trying to do is run an animation if the button is tapped or the user shakes the phone.
I have it so that it randomly picks up the shake so it may not start the animation on the first shake.
So far I have it working but I do not know how to stop it on a second shake or tap.
Here is my code so far:
– Require Libraries
local sprite = require(“sprite”)
local ui = require(“ui”)
– Set Still Frame Button
local button = display.newImage( “seq_00000.png” )
button.x = display.stageWidth / 2
button.y = display.stageHeight / 2
– Set Animation Array
myAnim = sprite.newAnim{ “seq_00000.png”, “seq_00001.png”, “seq_00002.png”, “seq_00003.png”, “seq_00004.png”, “seq_00005.png”, “seq_00006.png”, “seq_00007.png”, “seq_00008.png”}
myAnim.x = display.stageWidth / 2
myAnim.y = display.stageHeight / 2
– Set Button Tap Function
function button:tap( event )
myAnim:reverse()
local tween = transition.to(button, { time=0, alpha=100, transition = dissolve })
local tween = transition.to(myAnim, { time=0, alpha=0, transition = dissolve })
end
– Set Shake iPhone Function
local function onShake( event )
local x = math.random(1,2)
if x == 1 then
media.playEventSound( “choke.mp3” )
system.vibrate()
elseif x == 2 then
media.playEventSound( “startup.mp3” )
myAnim:play()
local tween = transition.to(button, { time=0, alpha=0, transition = dissolve })
local tween = transition.to(myAnim, { time=0, alpha=100, transition = dissolve })
system.vibrate()
end
end
– Add Listeners
button:addEventListener( “tap”, button )
Runtime:addEventListener(“accelerometer”,onShake) [import]uid: 5508 topic_id: 572 reply_id: 300572[/import]