Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Lua by hrh ( 15 years ago )
local function X_axis( event ) -- Moves sprite when called by frame event listener on X-axis
--CHINMAY's EDIT STARTS
max_XSpeed = 2
if actor.direction == "left" and event.joyX ~= false then
actor.x = actor.x + event.joyX * max_XSpeed
if actor.xScale == 1 then
actor.xScale = -1 -- mirrors image if not facing left
end
elseif actor.direction == "right" and event.joyX ~= false then
actor.x = actor.x - event.joyX * max_XSpeed
if actor.xScale == -1 then
actor.xScale = 1 -- mirrors image if not facing right
end
end
end
local function activateXaxis( event ) -- Called whenever a button is pressed
local this = event.target
local phase = event.phase
local pos = event.target.pos -- Get the position of the button which was pressed
print( pos )
if "began" == phase then -- If the button has just been pressed
actor.direction = pos -- Set the sprite to the direction of the button
display.getCurrentStage():setFocus( this , event.pos )
this.isFocus = true -- Keep event focus on the button
Runtime:addEventListener( "enterFrame", X_axis) -- Start the event listener to move the sprite
elseif this.isFocus then
if "ended" == phase or "cancelled" == phase then -- If the button is no longer pressed
-- End Focus
display.getCurrentStage():setFocus( this , nil )
this.isFocus = false
Runtime:removeEventListener( "enterFrame", X_axis) -- Remove the event listener
end
end
end
Revise this Paste
Children: 32437