I made two invisible rectangles on the screen. one on the left side and one on the right side. I have a ball in the middle and I want it to move left or right when I touch them. It works. The problem: I want that if I press one of them and after thet I press the other (While the first still pressed) it will move the othe side but that not happed. for example: I press the right rectangle (The ball moves right) and while it pressed I press the left rectangle, but the ball still goes to the left.
code:
function moveLeft( e )
if (circle.x>_W*0.031 ) then
if (e.phase=="began") then
circle:setLinearVelocity( -800*v_circle, 0 )
end
if (e.phase=="ended") then
circle:setLinearVelocity( 0, 0 )
end
if (e.x>_W*0.44) then
circle:setLinearVelocity( 0, 0 )
end
end
end
function moveRight( e )
if (circle.x<_W*0.969) then
if (e.phase=="began") then
circle:setLinearVelocity( 800*v_circle, 0 )
end
if (e.phase=="ended") then
circle:setLinearVelocity( 0, 0 )
end
if (e.x<_W*0.556) then
circle:setLinearVelocity( 0, 0 )
end
end
end
clickLeft = display.newRect( _W*0.212, _H/2, _W*0.7, _H*1.2 )
clickRight = display.newRect( _W*0.78, _H/2, _W*0.7, _H*1.2 )
clickLeft.isVisible = false
clickRight.isVisible = false
clickLeft:addEventListener( "touch", moveLeft )
clickRight:addEventListener( "touch", moveRight )
I have found more - I have put this code in moveLeft function: (Between ****)
function moveLeft( e )
if (circle.x>_W*0.031 ) then
if (e.phase=="began") then
circle:setLinearVelocity( -800*v_circle, 0 )
**** txt = display.newText("@@@@@@@", _W/2, _H*0.57, "Wekar" , 115 ) ****
end
if (e.phase=="ended") then
circle:setLinearVelocity( 0, 0 )
end
if (e.x>_W*0.44) then
circle:setLinearVelocity( 0, 0 )
end
end
end
And if I press the right rectangle and after that I press the left (While the first still pressed) it doesn't show nothing. Namely, in this situation it doesn't even get into the moveLefr function. please someone can help me?