Hi, I have the following 3 functions:
local playerMoveDirection = "stop"; local playerMoveSpeed = 2; local playerMoveTime = 2; local stopOnce = true; -- Function that moves the player local function movePlayer(player, moveX, moveY, moveTime) transition.moveBy(player, {x = moveX, y = moveY, time = moveTime}) end -- Setup player touch listener M.touchListener = function(event) if (event.phase == "began" or event.phase == "moved") then display.getCurrentStage():setFocus(event.target) if (event.x \< display.contentCenterX and playerMoveDirection ~= "down") then playerMoveDirection = "down" elseif (event.x \> display.contentCenterX and playerMoveDirection ~= "up") then playerMoveDirection = "up" end elseif (event.phase == "ended" and playerMoveDirection ~= "stop") then playerMoveDirection = "stop" display.getCurrentStage():setFocus(nil) end return true end local function checkPlayerMoveStatus() if (playerMoveDirection == "down") then stopOnce = true movePlayer(playerObject, 0, playerMoveSpeed, playerMoveTime) elseif (playerMoveDirection == "up") then stopOnce = true movePlayer(playerObject, 0, -(playerMoveSpeed), playerMoveTime) elseif (playerMoveDirection == "stop" and stopOnce == true) then stopOnce = false movePlayer(playerObject, 0, 0, 0) end end Runtime:addEventListener("enterFrame", checkPlayerMoveStatus)
When I place _movePlayer(playerObject, 0, playerMoveSpeed, playerMoveTime) _inside the touchListener function, the playerObject does in fact move as expected. But when I do it the way I have shown above, the playerObject does not move. Can anyone help me understand why it does not work this way or am I missing something?
Thanks in advance.