Multitouch is not working please help

Hi.

I have two buttons.

two objects.

everything works the way I want.

but when I use “Multitouch”

I have problems.

One button is like this

function object:touch( event ) &nbsp; &nbsp; if event.phase == "began" or event.phase == "moved" then &nbsp; &nbsp; &nbsp; &nbsp; if(event.target == object) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; audio.play(nota1, {channel=1}) &nbsp; &nbsp; &nbsp; &nbsp; elseif(event.phase == "moved") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(event.x \< object.contentBounds.xMin) or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (event.x \> object.contentBounds.xMax) or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (event.y \< object.contentBounds.yMin) or &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (event.y \> object.contentBounds.yMax) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; audio.stop(1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; elseif(event.phase == "ended") then &nbsp; &nbsp; &nbsp; &nbsp; audio.stop(1) &nbsp; &nbsp; end end object:addEventListener( "touch", object) Runtime:addEventListener("touch", object)
  1.  Why are you doing this (that is going to have some weird side effects):

    – ‘object’ is implied by object:, no need to pass explicitly object:addEventListener( “touch”, object) – I would not do this. I’m not clear what it would even do… :confused: Runtime:addEventListener(“touch”, object)

  2. That is not a multi-touch ready listener.  This is:

    local function isInBounds( obj, obj2 ) if(not obj) then return false end if(not obj2) then return false end local bounds = obj2.contentBounds if( obj.x > bounds.xMax ) then return false end if( obj.x < bounds.xMin ) then return false end if( obj.y > bounds.yMax ) then return false end if( obj.y < bounds.yMin ) then return false end return true end function object:touch( event ) if( event.phase == “began” ) then self.isFocus = true display.currentStage:setFocus( self, event.id ) audio.play(nota1, {channel=1}) return true elseif( self.isFocus ) then if( event.phase == “ended” ) then self.isFocus = false display.currentStage:setFocus( self, nil ) if( isInBounds( event, self ) ) then audio.stop(1) end end return true end return false end object:addEventListener( “touch” )

Note: My use of return true or return false may be entirely wrong to your circumstance.  

Additionally, choosing what to do when in bounds, etc… you must have a clear grasp of what is happening w/ the touches before coding these up.

As Brent said here,  multi-touch usage is quite specific to your needs and goals.

Nonetheless, the above code is some kind of starting point, as is this reference: https://docs.coronalabs.com/api/type/StageObject/setFocus.html

and this (read the part about multitouch AND touch):

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html

  1.  Why are you doing this (that is going to have some weird side effects):

    – ‘object’ is implied by object:, no need to pass explicitly object:addEventListener( “touch”, object) – I would not do this. I’m not clear what it would even do… :confused: Runtime:addEventListener(“touch”, object)

  2. That is not a multi-touch ready listener.  This is:

    local function isInBounds( obj, obj2 ) if(not obj) then return false end if(not obj2) then return false end local bounds = obj2.contentBounds if( obj.x > bounds.xMax ) then return false end if( obj.x < bounds.xMin ) then return false end if( obj.y > bounds.yMax ) then return false end if( obj.y < bounds.yMin ) then return false end return true end function object:touch( event ) if( event.phase == “began” ) then self.isFocus = true display.currentStage:setFocus( self, event.id ) audio.play(nota1, {channel=1}) return true elseif( self.isFocus ) then if( event.phase == “ended” ) then self.isFocus = false display.currentStage:setFocus( self, nil ) if( isInBounds( event, self ) ) then audio.stop(1) end end return true end return false end object:addEventListener( “touch” )

Note: My use of return true or return false may be entirely wrong to your circumstance.  

Additionally, choosing what to do when in bounds, etc… you must have a clear grasp of what is happening w/ the touches before coding these up.

As Brent said here,  multi-touch usage is quite specific to your needs and goals.

Nonetheless, the above code is some kind of starting point, as is this reference: https://docs.coronalabs.com/api/type/StageObject/setFocus.html

and this (read the part about multitouch AND touch):

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html