Hello everyone.
Is there a way I can track the x and y coordinates of each simultaneous touch?
Hello everyone.
Is there a way I can track the x and y coordinates of each simultaneous touch?
Here’s the best tutorial to handle this:
http://docs.coronalabs.com/guide/events/detectEvents/index.html
Short answer: using a Runtime listener with print functions showing event.x and event.y would work well.
Ok but, if multitouch is enabled, event.x and event.y should be tables containing all the simultaneous positions, shouldn’t they? The point is that, since multitouch doesn’t work on the simulator and I don’t have a mac (Xcode to handle the multitouch) I cannot test it with the terminal (I know, I’m lazy)
If I’m understanding you correctly, I think you want to keep track of the points you touch. To do this, you’d need to add each touch into a table, as they aren’t automatically entered. If I misunderstand, let me know.
No. If I want to get the x-coordinate of a point when multitouch is DISABLED, e.x returns a SINGLE value, let’s say 130. But if multitouch is ENABLED I may guess that e.x will be a table containing all the x-coordinates of the points being touched at an instant. Am I correct? (Thank you for your patience)
Ah, I think I understand. I have to assume the coordinates would be recorded; I do not know how you would access that record without creating your own record-keeping function. I think it would just be better to create your own function to throw every x touch coordinate into a table to access at your leisure.
I can tell you for a fact that Corona SDK built-in multi-touch wasn’t ideal when I first implemented it for my apps, so I had to use a bunch from the code exchange until I found the best mix. Here’s the one that I’m the biggest fan of. It seems complicated at first, but it’s the best solution that I found.
Thank You
Here’s the best tutorial to handle this:
http://docs.coronalabs.com/guide/events/detectEvents/index.html
Short answer: using a Runtime listener with print functions showing event.x and event.y would work well.
Ok but, if multitouch is enabled, event.x and event.y should be tables containing all the simultaneous positions, shouldn’t they? The point is that, since multitouch doesn’t work on the simulator and I don’t have a mac (Xcode to handle the multitouch) I cannot test it with the terminal (I know, I’m lazy)
If I’m understanding you correctly, I think you want to keep track of the points you touch. To do this, you’d need to add each touch into a table, as they aren’t automatically entered. If I misunderstand, let me know.
No. If I want to get the x-coordinate of a point when multitouch is DISABLED, e.x returns a SINGLE value, let’s say 130. But if multitouch is ENABLED I may guess that e.x will be a table containing all the x-coordinates of the points being touched at an instant. Am I correct? (Thank you for your patience)
Ah, I think I understand. I have to assume the coordinates would be recorded; I do not know how you would access that record without creating your own record-keeping function. I think it would just be better to create your own function to throw every x touch coordinate into a table to access at your leisure.
I can tell you for a fact that Corona SDK built-in multi-touch wasn’t ideal when I first implemented it for my apps, so I had to use a bunch from the code exchange until I found the best mix. Here’s the one that I’m the biggest fan of. It seems complicated at first, but it’s the best solution that I found.
Thank You
Sorry guys…
I read all of this, and still I don’t get it.
I copy the “dmc_touchmanager.lua” and I have my iPad to test it but nothing happens…
I have this
-- setup our function-type event handler -- local handler = function( event ) local target = event.target if event.phase == 'began' then -- set focus if object should always receive this event TouchMgr:setFocus( target, event.id ) elseif event.phase == 'moved' then -- do stuff here local txPlay1 = display.newText( "I hope it works?", display.contentCenterX - 67, display.contentCenterY - 140, 300, 0, native.systemFont, 46 ) group:insert(txPlay1) txPlay1:setTextColor(255) elseif ( event.phase == 'canceled' or event.phase == 'ended' ) then -- unset focus when done if event.isFocused then TouchMgr:unsetFocus( target, event.id ) end end return true end local o = display.newRect( 350, 700, 300, 300 ) o:setFillColor( 255, 255, 255 ) TouchMgr:register( o, handler )
and I require this
local TouchMgr = require( "dmc\_touchmanager" )
nothing…
The idea it’s to create a BIG image with a map
and when people “Pinch” their fingers the image will scale down to a small size
if the “pinch” their fingers they can make the map bigger…
or scroll the image to see many areas of the map.
a common thing that you see in many games…
please help me out to make this work
@ Victor: ‘dmc_touchmanager’ isn’t for ‘pinch&zoom’.
What you want to do involves mildly-complex group&layer calculations.
Here is the camera module I use: http://developer.coronalabs.com/code/perspective
If you scroll down in the comments section you’ll see a few people that are using a ‘pinch&zoom’ feature.
Hope this helped.
-Saer
Sorry guys…
I read all of this, and still I don’t get it.
I copy the “dmc_touchmanager.lua” and I have my iPad to test it but nothing happens…
I have this
-- setup our function-type event handler -- local handler = function( event ) local target = event.target if event.phase == 'began' then -- set focus if object should always receive this event TouchMgr:setFocus( target, event.id ) elseif event.phase == 'moved' then -- do stuff here local txPlay1 = display.newText( "I hope it works?", display.contentCenterX - 67, display.contentCenterY - 140, 300, 0, native.systemFont, 46 ) group:insert(txPlay1) txPlay1:setTextColor(255) elseif ( event.phase == 'canceled' or event.phase == 'ended' ) then -- unset focus when done if event.isFocused then TouchMgr:unsetFocus( target, event.id ) end end return true end local o = display.newRect( 350, 700, 300, 300 ) o:setFillColor( 255, 255, 255 ) TouchMgr:register( o, handler )
and I require this
local TouchMgr = require( "dmc\_touchmanager" )
nothing…
The idea it’s to create a BIG image with a map
and when people “Pinch” their fingers the image will scale down to a small size
if the “pinch” their fingers they can make the map bigger…
or scroll the image to see many areas of the map.
a common thing that you see in many games…
please help me out to make this work
@ Victor: ‘dmc_touchmanager’ isn’t for ‘pinch&zoom’.
What you want to do involves mildly-complex group&layer calculations.
Here is the camera module I use: http://developer.coronalabs.com/code/perspective
If you scroll down in the comments section you’ll see a few people that are using a ‘pinch&zoom’ feature.
Hope this helped.
-Saer