Multitouch?

How would you create a game where you can drag an object and press a button at the same time? This is what my code looks like, but it does not work:

[code]
system.activate(“multitouch”)

local function onTouch( event )
local t = event.target

– Print info about the event. For actual production code, you should
– not call this function because it wastes CPU resources.
– printTouch(event)

local phase = event.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t )

– Spurious events can be sent to the target, e.g. the user presses
– elsewhere on the screen and then moves the finger over the target.
– To prevent this, we add this flag. Only when it’s true will “move”
– events be sent to the target.
t.isFocus = true

– Store initial position

t.y0 = event.y - t.y
t.x0 = event.x - t.x
elseif t.isFocus then
if “moved” == phase then
– Make object move (we subtract t.x0,t.y0 so that moves are
– relative to initial grab point, rather than object “snapping”).

t.y = event.y - t.y0
t.x = event.x - t.x0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Important to return true. This tells the system that the event
– should not be propagated to listeners of any objects underneath.
return true

end

object:addEventListener(“touch”,onTouch)
local button = display.newImage(“button.png”)
local buttonpress = function (event)
if event.phase == “began” then
–do stuff
end
end
button:addEventListener(“touch”,buttonpress)

[/code] [import]uid: 38001 topic_id: 12974 reply_id: 312974[/import]

Explaining how it doesn’t work would be a good start.

The fact you’re setting a focus makes me think when you press the button the platform stops dragging, is that what’s up? [import]uid: 52491 topic_id: 12974 reply_id: 47674[/import]

Yes that is what happens. Also, the button doesn’t do anything unless I completely stop dragging the platform. [import]uid: 38001 topic_id: 12974 reply_id: 47719[/import]

It is because you are setting a focus, as I said previously.

Please read this API for information on how to do this correctly when using multitouch. [import]uid: 52491 topic_id: 12974 reply_id: 47837[/import]

Yes I got it to work! Thank you so much! [import]uid: 38001 topic_id: 12974 reply_id: 47861[/import]

No worries; it feels great when you get it how you want it, doesn’t it? Well done :smiley: [import]uid: 52491 topic_id: 12974 reply_id: 47956[/import]

Hello!

I trying to find the way to deactivate the multitouch when i am using some features of my app.
I looking in the forum and i can see you talk about an API but the link seems to be disabled.
Could you help me to find a solution?

Regards! [import]uid: 44013 topic_id: 12974 reply_id: 55539[/import]