[lua]
local composer = require( “composer” )
local scene = composer.newScene()
local function bulletMove(self, event)
if self.x == -95 then
display.remove( bullet )
else
self.x = self.x - 2
end
return true
end
local function gunTouched( event )
bullet = display.newImageRect( “bullet.png”, 50, 15 )
bullet.x = gunGun.x - 40
bullet.y = gunGun.y - 25
bullet.enterFrame = bulletMove
Runtime:addEventListener( “enterFrame”, bullet )
end
function scene:create( event )
local sceneGroup = self.view
gunGun = display.newImageRect( “LCP.png”, 100, 72)
gunGun.x = display.contentCenterX
gunGun.y = display.contentCenterY
gunGun:addEventListener( “touch”, gunTouched )
sceneGroup:insert( gunGun )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == “will” then
elseif phase == “did” then
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == “will” then
Runtime:removeEventListener( “enterFrame”, bullet )
elseif phase == “did” then
end
end
function scene:destroy( event )
local sceneGroup = self.view
if gunGun then
gunGun:removeSelf( )
gunGun = nil
end
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
I wrote this using composer not storyboard so the scene:create would be the same as scene:enterScene you have and so on with the scene:show, scene:hide, scene:destroy. Also I wrote this in about 30 minutes so its not pretty at all no background nothing just the basis of functionality you want. It creates a gun object in the center of the screen when its touched a bullet appears and moves until its off screen