Swipe a page, slide a finger

I want to learn how to use the swipe feature in Corona sdk and lua.

I saw a few places in corona gigHub but couldn’t find it

also in stockOverflow I saw one code, but the guy said it was not the “best”

way.

Like a normal book, and you “flip” pages with your finger

swipe left or right

in storyboard – goToScene – but instead of using a button

use the swipe momevent.

Thanks for your help

In corona you can detect touch events with phases: began, moved and ended. So you can create big invisible rectangle on the top of the screen and make it detect touch events. For example, if distance between began point and ended point is greater then some percentage (better then fixed value to target different devices) of screen and time between this phases is less then some small vale then you can say that there was the swipe. Comparing begin and end point you can tell swipe’s direction.

I have the idea, more or less.

But I think if I have

– object.isVisible = false – So I don’t see the big rectangle.

The listener doesn’t detect the rect.

and if I use alpha = .1 – it’s almost invisible, but you can still see something.

is that the only way?

you can set

.isVisible = false

.isHitTestable = true

second line will make it react to events

PS

You can always set alpha to 0.01 :stuck_out_tongue:

I put a .png transparent. the size of the window.

it works really good, If I touch and move the mouse.

could you tell me about the percentage %

how do I do that.

I have this code so far

local swipe = display.newImage( "swipe.png" )     group:insert (swipe)     swipe.x = display.contentWidth / 2 + 256     swipe.y = display.contentHeight / 2     swipe.id = "swipe"     function swipe:touch( event )         if event.phase == "began" then             print( "Touch event began on: " .. self.id )             -- set touch focus             display.getCurrentStage():setFocus( self )             self.isFocus = true         elseif self.isFocus then             if event.phase == "moved" then                 print( "Moved phase of touch event detected." )             elseif event.phase == "ended" or event.phase == "cancelled" then                          storyboard.gotoScene( "page2", "fromRight", 100 )             -- reset touch focus             display.getCurrentStage():setFocus( nil )             self.isFocus = nil             end         end     return true     end     swipe:addEventListener( "touch", swipe )

Thanks

In corona you can detect touch events with phases: began, moved and ended. So you can create big invisible rectangle on the top of the screen and make it detect touch events. For example, if distance between began point and ended point is greater then some percentage (better then fixed value to target different devices) of screen and time between this phases is less then some small vale then you can say that there was the swipe. Comparing begin and end point you can tell swipe’s direction.

I have the idea, more or less.

But I think if I have

– object.isVisible = false – So I don’t see the big rectangle.

The listener doesn’t detect the rect.

and if I use alpha = .1 – it’s almost invisible, but you can still see something.

is that the only way?

you can set

.isVisible = false

.isHitTestable = true

second line will make it react to events

PS

You can always set alpha to 0.01 :stuck_out_tongue:

I put a .png transparent. the size of the window.

it works really good, If I touch and move the mouse.

could you tell me about the percentage %

how do I do that.

I have this code so far

local swipe = display.newImage( "swipe.png" )     group:insert (swipe)     swipe.x = display.contentWidth / 2 + 256     swipe.y = display.contentHeight / 2     swipe.id = "swipe"     function swipe:touch( event )         if event.phase == "began" then             print( "Touch event began on: " .. self.id )             -- set touch focus             display.getCurrentStage():setFocus( self )             self.isFocus = true         elseif self.isFocus then             if event.phase == "moved" then                 print( "Moved phase of touch event detected." )             elseif event.phase == "ended" or event.phase == "cancelled" then                          storyboard.gotoScene( "page2", "fromRight", 100 )             -- reset touch focus             display.getCurrentStage():setFocus( nil )             self.isFocus = nil             end         end     return true     end     swipe:addEventListener( "touch", swipe )

Thanks