Hi I need to use a static object in my game and I need to make a left and right continues movement with two button. But my object only move once. Help
here is the code of the left button:
local function leftBtnTouch( event ) local function moveLeft() box.x = boxX- 10 --where boxX is the inicial position of the box in scene:create() end if event.phase == "began" then print( "left button touch" ) moveBoxToLeft = timer.performWithDelay(100, moveLeft(), -1) elseif event.phase == "ended" then if moveBoxToLeft ~= nil then timer.cancel( moveBoxToLeft ) moveBoxToLeft = nil end end return true end
I set -1 timer interactions to repeat till “ended” phase come but the box only move once. To give a better example, I am trying to make a game where there is a box below that picks up the objects that fall from above and I need to move it from left to right to catch the objects. The box needs to be static, is the only way I can do my idea using the physics engine. I would not like the player to make multiple taps to move the box, rather I look for a continuous movement that stops at the “ended” phase.
It moves but not continuously. What I want is when the user leaves the button pressed, the box keeps moving and when the user releases the button, the movement stops.
How about dropping the timer and the “began” phase and having the moveLeft() function trigger continuously when the button is touched? You can then set the rate of movement inside moveLeft() and the action will stop when the button is released.
Could you show me correcting the code I have? I try to understand what you explain to me and if the language does not betray me, I consider it the same thing I am doing. Sorry but I’m not seeing what you want to explain to me. I really appreciate your help.