Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code From: Tutorial: Continuous Actions in Corona http://coronalabs.com/blog/2014/02/04/tutorial-continuous-actions-in-corona/
local function fireLasers()
local blaster = display.newImageRect("laserbeam.png", 8,24)
blaster.x = ship.x
blaster.y = ship.y
transition.to(blaster, {time=1000, y = 0 })
end
local needToFire = false
local function handleEnterFrame( event )
if ( needToFire == true ) then
fireLasers()
end
end
Runtime:addEventListener( "enterFrame", handleEnterFrame )
local fireButton = display.newImageRect( "firebutton.png", 64, 64 )
fireButton.x = 50
fireButton.y = display.contentHeight-50
local function handleFireButton( event )
if ( event.phase == "began" ) then
-- fire the weapon
needToFire = true
elseif ( event.phase == "ended" and needToFire == true ) then
-- stop the weapon
needToFire = false
end
return true
end
local fireButton = widget.newButton{
width = 64,
height = 64,
defaultFile = "firebutton.png",
overFile = "firebuttonDown.png",
onEvent = handleFireButton
}
fireButton.x = 50
fireButton.y = display.contentHeight-50
local function onKeyEvent( event )
if ( event.keyName == "buttonX" ) then
if ( event.phase == "down" ) then
needToFire = true
else
needToFire = false
end
return true
end
return false
end
Runtime:addEventListener( "key", onKeyEvent )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.