Swipe gesture and touch listener : a very simple proto

Hi  :slight_smile:

I need your help on a simple proto

Here the main.lua code. (You can download lineTouch.zip to test directly the code)

------------------------------------------------------------------------------------ -- main.lua ------------------------------------------------------------------------------------ --Touch listener local function touchListener(event) --Reference to the touch object local target = event.target --On "began" phase, we color the object in green if event.phase == "began" then target:setFillColor(0,1,0) --On "moved" phase, we color the object in red elseif event.phase == "moved" then target:setFillColor(1,0,0) end end -- We create 30 vertical lines, each one listen to the "touch" event for i = 1, 30 do local verticalLine = display.newRect( 0, 0, 5, 300 ) verticalLine:setFillColor(1,1,1) verticalLine.y = display.contentCenterY verticalLine.x = 33 \* i verticalLine:addEventListener("touch", touchListener) end

TEST PROCESS :

  • Firstly, swipe slowly on screen from the left to the right : you can see that each vertical line becomes red.  Ok.

  • Secondly, swipe quickly on screen from the left to the right : you can see that some vertical lines becomes red and some remain white.

Is there a way for all lines to turn red regardless of swipe speed?

Do you have an idea?

Any help would be great! 

Thanks!  :slight_smile:

Best,

Olivier

http://www.onetreehillstudio.com/

Little precision : of course relaunch the app before the second step.

Bump :slight_smile:
Help help
Thanks

For something like this, it might be best to put a touch handler on the stage and then check to see if the x, y of the touch is over one of your objects.  You can use this article:   http://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/

to detect if the touch is over another object and then process it accordingly.

Rob

Thank you Rob!

I’m going to check this article.

Best

Olivier

Little precision : of course relaunch the app before the second step.

Bump :slight_smile:
Help help
Thanks

For something like this, it might be best to put a touch handler on the stage and then check to see if the x, y of the touch is over one of your objects.  You can use this article:   http://coronalabs.com/blog/2013/07/23/tutorial-non-physics-collision-detection/

to detect if the touch is over another object and then process it accordingly.

Rob

Thank you Rob!

I’m going to check this article.

Best

Olivier