force oject to move to a point while prevent change it direction till it reach that point

i have a control button left,right,up,down

and i want when i press any of these button to move an object from a point to point from that direction . but i want in the same time to prvenet any input to other direction till i reach that point

i am using this code

local function leftArrowMove(event) motionx = -speed end -- When right arrow is touched, move character right local function rightArrowMove(event) motionx = speed end local function upArrowMove(event) motiony = -speedy end -- When right arrow is touched, move character right local function downArrowMove(event) motiony = speedy end RightArrow:addEventListener("touch",rightArrowMove) leftArrow:addEventListener("touch",leftArrowMove) upArrow:addEventListener("touch",upArrowMove) downArrow:addEventListener("touch",downArrowMove) local function moveOrange5 (event) Orange5.x = Orange5.x + motionx Orange5.y = Orange5.y + motiony end Runtime:addEventListener("enterFrame", moveOrange5)

speed and speedy and motionx and y already defined .

now example .

i want to move the object from point .x1 to .x2 and if the user press any other key ( right,up,down ) while the object move it will not effect its direction till it reaches .x2

hmmm i just got something in my mind . but i dont know if it will efficient

i can remove the listener for the other controls just after the object move and i can put activate it back when it reaches its X2 . but i dont think this will be good idea.

Here’s a small example using transitions:

local orange = display.newCircle(160, 240, 20) orange.isMoving = false local upButton, downButton, leftButton, rightButton upButton = display.newRect(160, 370, 40, 40) downButton = display.newRect(160, 460, 40, 40) leftButton = display.newRect(100, 415, 40, 40) rightButton = display.newRect(220, 415, 40, 40) local function setOrangeNotMoving()     orange.isMoving = false end local function buttonTap(event)     if orange.isMoving then return true     end     orange.isMoving = true     if event.target == upButton then transition.to(orange, { y = orange.y - 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == downButton then transition.to(orange, { y = orange.y + 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == leftButton then transition.to(orange, { x = orange.x - 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == rightButton then transition.to(orange, { x = orange.x + 50, time = 1000, onComplete = setOrangeNotMoving })     end end upButton:addEventListener("tap", buttonTap) downButton:addEventListener("tap", buttonTap) leftButton:addEventListener("tap", buttonTap) rightButton:addEventListener("tap", buttonTap)

If you have to use the enterFrame listener, then obviously you’ll need to do things a little bit different, but it’s easily done. Just check for when the orange is in the right position, then set orange.isMoving = false

hmmm i just got something in my mind . but i dont know if it will efficient

i can remove the listener for the other controls just after the object move and i can put activate it back when it reaches its X2 . but i dont think this will be good idea.

Here’s a small example using transitions:

local orange = display.newCircle(160, 240, 20) orange.isMoving = false local upButton, downButton, leftButton, rightButton upButton = display.newRect(160, 370, 40, 40) downButton = display.newRect(160, 460, 40, 40) leftButton = display.newRect(100, 415, 40, 40) rightButton = display.newRect(220, 415, 40, 40) local function setOrangeNotMoving()     orange.isMoving = false end local function buttonTap(event)     if orange.isMoving then return true     end     orange.isMoving = true     if event.target == upButton then transition.to(orange, { y = orange.y - 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == downButton then transition.to(orange, { y = orange.y + 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == leftButton then transition.to(orange, { x = orange.x - 50, time = 1000, onComplete = setOrangeNotMoving })     elseif event.target == rightButton then transition.to(orange, { x = orange.x + 50, time = 1000, onComplete = setOrangeNotMoving })     end end upButton:addEventListener("tap", buttonTap) downButton:addEventListener("tap", buttonTap) leftButton:addEventListener("tap", buttonTap) rightButton:addEventListener("tap", buttonTap)

If you have to use the enterFrame listener, then obviously you’ll need to do things a little bit different, but it’s easily done. Just check for when the orange is in the right position, then set orange.isMoving = false