Multitouch and Touch events together

Hello everybody, its been a while since I don’t ask anything here.

I’m with a problem in a app that I’m developing. This app should be an online magzine reader, so it need to pinch zoom, pan map and also “slide” listener, so I can zoom the pages, pass to another and etc.

So I’ve searched online for an multitouch library and I found this one :

It seems to work fine, but since it’s activateded my slide listener stop working. Also, I’ve tried to do something just like : http://developer.coronalabs.com/code/multi-point-pinch-zoom-rotate

 function multitouch(e) if (#e.list \> 1) then if(e.phase == "began") then doPinchZoom(e.target,e.list,true,false,true) elseif (e.phase == "moved") then doPinchZoom(e.target,e.list,true,false,true) else doPinchZoom(e.target,e.list,true,false,true) end end if (#e.list == 1) then if(e.y - e.yStart \< 0) then --slide backward elseif (e.y - yStart \> 0) then --slide foward end print(e.list[1].y) end return true end

But it doesn’t work since it can’t detect event phases with just one touch. I’ve tried so many thing and I couldn’t have sucess, so thats why I’m here. I’ll post the full code here so I can be easy to help me.

local storyboard = require( "storyboard" ) require ("alagartaFunctions") require ("multitouch") require ("pinchlib") system.activate("multitouch") local scene = storyboard.newScene() local page local yStart = nil function scene:createScene( event ) local group = self.view end function scene:enterScene( event ) touchCount = 0 print("readingScene") local group = self.view print("page number: ",event.params.page) print("edition number: ",event.params.numberOfEdition) print("Scene before: ",event.params.sceneBefore) numberE = event.params.numberOfEdition storyboard.removeScene("downloadScene") local extension = extension(numberE) if event.params.sceneBefore == "menuScene" then page = display.newImage("cover"..event.params.numberOfEdition..extension,system.DocumentsDirectory,halfW,halfH) page.isVisible = false local proportion = page.height/page.width page = display.newImageRect("cover"..event.params.numberOfEdition..extension,system.DocumentsDirectory,560,560\*proportion) page.id = event.params.page page:rotate(-90) page.x = halfW page.y = halfH transition.fadeIn(page , {time = 1000, x= halfW, y=halfH}) elseif event.params.sceneBefore == "downloadScene" or event.params.sceneBefore == "readingSceneZoom" or event.params.sceneBefore == "readingSceneMenu" then page = display.newImage("page-"..event.params.numberOfEdition.."-"..event.params.page..extension,system.DocumentsDirectory,halfW,halfH) page.isVisible = false local proportion = page.height/page.width page = display.newImageRect("page-"..event.params.numberOfEdition.."-"..event.params.page..extension,system.DocumentsDirectory,560,560\*proportion) page.id = event.params.page page:rotate(-90) page.x = halfW page.y = halfH transition.to(page , {time = 1000, alpha = 1, x= halfW, y=halfH}) end system.activate("multitouch") pages = display.newGroup() pages:insert(page) menuTab = display.newImage("menuTab.png",17,halfH) menuTab:rotate(-90) menuTab.alpha = 0.8 function tapMenuTab (e) if (e.numTaps == 1) then --open menu local options = { effect = "crossFade", time = 500, params = { numberOfEdition = numberE, page = page.id, sceneBefore = "readingScene"} } storyboard.gotoScene("readingSceneMenu",options) end end function slide (e) print("slide") print("Start:",e.yStart,"End:",e.y) if(touchCount == 1) then if(page.xScale == 1) then if (e.y - e.yStart) \< 0 then --print(page.id) if page.id == 1 then --first page else local options = { effect = "crossFade", time = 500, params = { numberOfEdition = numberE, page = page.id - 1, sceneBefore = "readingScene"} } --print(1) -- backward storyboard.gotoScene("downloadScene", options) return true end elseif (e.y - e.yStart \> 0) then --print(page.id) if page.id == Data[numberE].numberOfPages then --last page on the screen else local options = { effect = "crossFade", time = 500, params = { numberOfEdition = numberE, page = page.id + 1, sceneBefore = "readingScene"} } --print(2) -- foward storyboard.gotoScene("downloadScene", options) return true end end end end if (event.phase == "ended") then print("acabo") end end function countTouch(event) print(touchCount) if (event.phase == "began") then --print("begin") touchCount = touchCount +1 elseif (event.phase == "ended") then touchCount = touchCount -1 end if (touchCount \> 1) then system.activate("multitouch") else system.deactivate("multitouch") end end function multitouch(e) if (#e.list \> 1) then if(e.phase == "began") then doPinchZoom(e.target,e.list,true,false,true) elseif (e.phase == "moved") then doPinchZoom(e.target,e.list,true,false,true) else doPinchZoom(e.target,e.list,true,false,true) end end if (#e.list == 1) then if (yStart == nil) then yStart = e.y print("yStart") else if(e.y - yStart \< 0) then elseif (e.y - yStart \> 0) then end end print(e.list[1].y) end return true end pages:addEventListener("touch",slide) --pages:addEventListener("touch",countTouch) pages:addEventListener("multitouch",multitouch) menuTab:addEventListener("tap",tapMenuTab) end function scene:willExitScene( event ) end function scene:exitScene( event ) local function removePage() pages:removeSelf() pages = nil page:removeSelf() page = nil menuTab:removeSelf() menuTab = nil end transition.fadeOut(page , {time = 500, onComplete = removePage}) end function scene:destroyScene( event ) end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "willExitScene", scene) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

Hi @pedrogabriellancelloti,

As a general comment, multi-touch really isn’t “different” than single touch, except that you need to more carefully handle the IDs of each touch. When you use multi-touch, it provides you with an “event.id” which identifies which touch is being tracked, plus all of the usual phases.

http://docs.coronalabs.com/guide/events/touchMultitouch/index.html#multitouch

That being said, I’m not sure if the module you located will help handle this. You’ll probably need to implement a combination of both the module and some custom touch handling for your single touches.

Hope this helps slightly,

Brent

Hi Brent, thanks for your help. I’ve done another searchs at Corona page’s, and I found another multitouch and pan map, this one was simpler and work without problems :slight_smile:

Here’s the link for anyone who find this post:

https://developer.coronalabs.com/code/pinch-zoom-xl

Thanks again for your help :slight_smile:

Hi @pedrogabriellancelloti,

As a general comment, multi-touch really isn’t “different” than single touch, except that you need to more carefully handle the IDs of each touch. When you use multi-touch, it provides you with an “event.id” which identifies which touch is being tracked, plus all of the usual phases.

http://docs.coronalabs.com/guide/events/touchMultitouch/index.html#multitouch

That being said, I’m not sure if the module you located will help handle this. You’ll probably need to implement a combination of both the module and some custom touch handling for your single touches.

Hope this helps slightly,

Brent

Hi Brent, thanks for your help. I’ve done another searchs at Corona page’s, and I found another multitouch and pan map, this one was simpler and work without problems :slight_smile:

Here’s the link for anyone who find this post:

https://developer.coronalabs.com/code/pinch-zoom-xl

Thanks again for your help :slight_smile: