Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@coronarob
Created February 1, 2015 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coronarob/efc5d9a53fa7910d0ff0 to your computer and use it in GitHub Desktop.
Save coronarob/efc5d9a53fa7910d0ff0 to your computer and use it in GitHub Desktop.
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