I just finished building the Astroid game tutorial and loved.
I’ve been tying with adding left right arrow key controls for the desktop version and could not get it to work.
Any ideals?
Thanks in advance.
local function dragShip( event )
local ship = event.target
local phase = event.phase
if ( “began” == phase ) then
– Set touch focus on the ship
display.currentStage:setFocus( ship )
– Store initial offset position
ship.touchOffsetX = event.x - ship.x
elseif ( “moved” == phase ) then
– Move the ship to the new touch position
ship.x = event.x - ship.touchOffsetX
elseif ( “ended” == phase or “cancelled” == phase ) then
– Release touch focus on the ship
display.currentStage:setFocus( nil )
end
return true – Prevents touch propagation to underlying objects
end