[SOLVED] Touch (Invisible Button) Movement Problem

Hello Community, I have a problem with the movement of my char (Left-Right or Right-Left) , I’ll explain it this way:

  1. Touch Left (Without Releasing).
  2. Tocuh Right (While I pressing Left, so the char continues moving to left)*
  3. Touch Left Ended (Without Releasing Touch Right).
  4. Here’s the Problem: My char should move to right, but the char doesn’t move to right, it just stops.

I don’t know if I should use multitouch or something else, please, somebody help me.

– I tested activating multitouch, but the problem with multitouch is:

  1. Touch Left (Without Releasing).
  2. Tocuh Right (While I pressing Left, the char changes its movement to Right)*
  3. Touch Left Ended (Without Releasing Touch Right)
  4. Here’s the Problem: My char should move to right, but the char doesn’t move to right, it just stops.

*Did you see the difference?

Here’s the code:

[code]
–Movement Direction
function moveDirection (e)
if ( e.x > (wScreen * 0.5) and e.x < wScreen ) then
motionX = speedX
elseif ( e.x > 0 and e.x < (wScreen * 0.5) ) then
motionX = -speedX
end
end
–Listener
Runtime:addEventListener ( “touch”, moveDirection )

–Movement
function movement ()
square.x = square.x + motionX
end
–Listener
Runtime:addEventListener ( “enterFrame”, movement )

–Stop Movement
function moveStop (e)
if ( e.phase == “ended” ) then
motionX = 0
end
end
–Listener
Runtime:addEventListener ( “touch”, moveStop )

–Movement Wrap
function moveWrap ()
if ( square.x < 12 ) then
square.x = 12
elseif ( square.x > (wScreen - 12) ) then
square.x = wScreen - 12
end
end
–Listener
Runtime:addEventListener ( “enterFrame”, moveWrap ) [import]uid: 81091 topic_id: 18097 reply_id: 318097[/import]

I’m a little confused, is there a reason a player needs to be able to press both at once? (I’m trying to picture it and work out how it might be handled but am having some difficulty.) [import]uid: 52491 topic_id: 18097 reply_id: 69285[/import]

No, I need that my player changes his direction when I stop the first touch, check this:

  1. I start to touch the screen on the left side (my player moves to left side).
  2. My player continues moving to left side, but I touch the screen on right side while he’s moving to left side (at this time I’m touching both sides of the screen and the player has to be moving to left side yet).
  3. I stop to touch the left side of the screen but I’m still touching the right side, so, my player should move to right side, but here is the problem, my player stops, I have to touch again to right to start his movement to right side. [import]uid: 81091 topic_id: 18097 reply_id: 69454[/import]

Perhaps use a flag when releasing one direction to see whether or not the other directional button is still pressed and if so act accordingly?

Peach :slight_smile: [import]uid: 52491 topic_id: 18097 reply_id: 69529[/import]

Sorry, what’s a flag? [import]uid: 81091 topic_id: 18097 reply_id: 70239[/import]

This is really basic article explaining them; http://techority.com/2011/10/30/flags-what-and-why/

You could have leftPressed = true and check for that when you released the right arrow, then if it’s true, move left, if it is false, do nothing.

Make sense?

Peach :slight_smile: [import]uid: 52491 topic_id: 18097 reply_id: 70270[/import]

Thanks Peach, I’ll test it. [import]uid: 81091 topic_id: 18097 reply_id: 70408[/import]

Oh my gosh, Finally… Thanks for your help Peach. :slight_smile: [import]uid: 81091 topic_id: 18097 reply_id: 70846[/import]

Excellent! No worries at all.

Peach :slight_smile: [import]uid: 52491 topic_id: 18097 reply_id: 70933[/import]