Multitouch strange behaviour

Hello, 

I’m still new to Corona but i noticed a strange behaviour about the multitouch function and i can’t understand what’s happening.

The problem is that if I touch a button (or any part of the screen) and at the same time while still holding the previous button I start touching multiple times any other part of the display then after some touches the multitouch stops registering the button I was holding.

This is a problem for me because I’m making a platform game and if i hold the run button and then touch the jump button multiple times (while still holding the run button) my character stops running after some jumps…

Any help will be appreciated  :slight_smile:

Read the guide on touches and it will clarify how to handle multi-touch correctly.

Dig Here:

  1. Firsthttps://docs.coronalabs.com/tutorial/events/tapTouchAnatomy/index.html
  2. Secondhttps://docs.coronalabs.com/guide/events/touchMultitouch/index.html

General Links You Should Use All The Time:

Thank you I readed it and In the second tutorial you posted there is an example that gives me the same problem I’m facing with my game:

[lua]

– Activate multitouch

system.activate( “multitouch” )

 

– Create two display objects on the screen

local newRect1 = display.newRect( display.contentCenterX, 160, 60, 60 )

newRect1:setFillColor( 1, 0, 0.3 )

local newRect2 = display.newRect( display.contentCenterX, 320, 60, 60 )

newRect2:setFillColor( 0.3, 0, 1 )

 

– Touch event listener

local function touchListener( event )

 

    print( "Unique touch ID: " … tostring(event.id) )

 

    if ( event.phase == “began” ) then

        event.target.alpha = 0.5

        – Set focus on object using unique touch ID

        display.getCurrentStage():setFocus( event.target, event.id )

 

    elseif ( event.phase == “ended” or event.phase == “cancelled” ) then

        event.target.alpha = 1

        – Release focus on object

        display.getCurrentStage():setFocus( event.target, nil )

    end

    return true

end

 

– Add a touch listener to each object

newRect1:addEventListener( “touch”, touchListener )

newRect2:addEventListener( “touch”, touchListener )

[/lua]

If I touch the newRect1 button and while still touching newRect1 (holding the button) I touch multiple times newRect2 after some touches to newRect2 the focus on newRect1 is gone, Why is this happening? 
 

If you want to be able to move and jump using separate buttons then do not use setFocus.  This is more for dragging - as only one object can ever be focused.

Just have one touch handler to move and another to jump.

I tried removing setFocus but the problem is still there after a while the first button I’m holding stops registering and my character stops moving, only the second button works at that point… :frowning:

You will need to use an enterFrame event and a variable to indicate if you have a move button pressed.  Do the movement in your enterFrame event.  when the user stops pressing the move button set the variable to false.

Read the guide on touches and it will clarify how to handle multi-touch correctly.

Dig Here:

  1. Firsthttps://docs.coronalabs.com/tutorial/events/tapTouchAnatomy/index.html
  2. Secondhttps://docs.coronalabs.com/guide/events/touchMultitouch/index.html

General Links You Should Use All The Time:

Thank you I readed it and In the second tutorial you posted there is an example that gives me the same problem I’m facing with my game:

[lua]

– Activate multitouch

system.activate( “multitouch” )

 

– Create two display objects on the screen

local newRect1 = display.newRect( display.contentCenterX, 160, 60, 60 )

newRect1:setFillColor( 1, 0, 0.3 )

local newRect2 = display.newRect( display.contentCenterX, 320, 60, 60 )

newRect2:setFillColor( 0.3, 0, 1 )

 

– Touch event listener

local function touchListener( event )

 

    print( "Unique touch ID: " … tostring(event.id) )

 

    if ( event.phase == “began” ) then

        event.target.alpha = 0.5

        – Set focus on object using unique touch ID

        display.getCurrentStage():setFocus( event.target, event.id )

 

    elseif ( event.phase == “ended” or event.phase == “cancelled” ) then

        event.target.alpha = 1

        – Release focus on object

        display.getCurrentStage():setFocus( event.target, nil )

    end

    return true

end

 

– Add a touch listener to each object

newRect1:addEventListener( “touch”, touchListener )

newRect2:addEventListener( “touch”, touchListener )

[/lua]

If I touch the newRect1 button and while still touching newRect1 (holding the button) I touch multiple times newRect2 after some touches to newRect2 the focus on newRect1 is gone, Why is this happening? 
 

If you want to be able to move and jump using separate buttons then do not use setFocus.  This is more for dragging - as only one object can ever be focused.

Just have one touch handler to move and another to jump.

I tried removing setFocus but the problem is still there after a while the first button I’m holding stops registering and my character stops moving, only the second button works at that point… :frowning:

You will need to use an enterFrame event and a variable to indicate if you have a move button pressed.  Do the movement in your enterFrame event.  when the user stops pressing the move button set the variable to false.