problem detecting individual touches in physics objects

hi in my game i have bubbles on screen that i want to explode when i touch them

the problem is that corona recognizes as if i’m touching multiple bubbles, instead of each indivijual bubble

And makes a couple of them disappear Although i’m asking from it to make only my current bubble i’m touching disappear.

please help what am i doing wrong ?

this is how i create the bubbles :

--this will actualy create a bubble and put it on the screen sides function createBubble (whatBubble, force, side, subLevel, skipCheck) --calculates the presentage of wrong answers and adds them as bubbles local wrongBubble = isWrongBubble (subLevel) if (wrongBubble == 1) then whatBubble = srn.wrong\_answers\_pool.item[1]:value() elseif (wrongBubble == 2) then whatBubble = srn.wrong\_answers\_pool.item[2]:value() end --calculates the chance of more then one bubble if (skipCheck == false) then addMoreBubbles (whatBubble, force, side, subLevel) ; end bubble = display.newImage ("pics/mainStage/bubbles/bubble\_".. whatBubble.. "/bubble\_".. whatBubble.. ".png") bubble.tag = whatBubble -------------left side ----------------------- if (side == "left") then bubble.x = 55 local yRandom = math.random (250, 350) bubble.y = yRandom physics.addBody( bubble, { density = 0.01, friction = 0.3, bounce = 0.2, radius = 75 } ) local forceY = math.random (-90, 5) bubble:applyForce( force\*10, forceY, bubble.x, bubble.y ) -------------right side ----------------------- elseif (side == "right") then bubble.x = 960-55 local yRandom = math.random (300, 450) bubble.y = yRandom physics.addBody( bubble, { density = 0.01, friction = 0.3, bounce = 0.2, radius = 75 } ) local forceY = math.random (-130, 5) bubble:applyForce( -force\*11, forceY, bubble.x, bubble.y ) -------------down side ----------------------- elseif (side == "down") then local xRandom = math.random (150, 750) bubble.x = xRandom bubble.y = 550 physics.addBody( bubble, { density = 0.01, friction = 0.3, bounce = 0.2, radius = 75 } ) local forceX = math.random (-50, 50) bubble:applyForce( forceX, -force\*10, bubble.x, bubble.y ) end local rotationRandom = math.random (1, 5) bubble:applyAngularImpulse( rotationRandom ) bubble:addEventListener ("touch", onTouch) bubblesContainer:insert (bubble) end

and this is the onTouch function that recognizes my touch and suppose to make only the one bubble disappear

--onTouch functino handles all tuch events function onTouch (event) if event.phase == "ended" then if (event.target.tag == "pause") then elseif (event.target.tag == "audio") then else print ("event.target.tag is: ".. event.target.tag) showExplotion (event.target.x, event.target.y) physics.removeBody( event.target ) display.remove (event.target) end end end

thanks a million ! shay

You have to return true at the end of your touch function if you want the event only be handled by this specific object.

Also would I recommend to create a touch function for each object and not a global one for all touches.

[LUA]

function onTouch (event)

    if event.phase == “ended” then

        if (event.target.tag == “pause”) then

        elseif (event.target.tag == “audio”) then

        else

            print ("event.target.tag is: "… event.target.tag)

            showExplotion (event.target.x, event.target.y)

            physics.removeBody( event.target )

            display.remove (event.target)

            return true

        end

    end

end

[/LUA]

wicked ! thanks a million !

can’t really create an event listener for each bubble there allot of them …

thank s !!!

You have to return true at the end of your touch function if you want the event only be handled by this specific object.

Also would I recommend to create a touch function for each object and not a global one for all touches.

[LUA]

function onTouch (event)

    if event.phase == “ended” then

        if (event.target.tag == “pause”) then

        elseif (event.target.tag == “audio”) then

        else

            print ("event.target.tag is: "… event.target.tag)

            showExplotion (event.target.x, event.target.y)

            physics.removeBody( event.target )

            display.remove (event.target)

            return true

        end

    end

end

[/LUA]

wicked ! thanks a million !

can’t really create an event listener for each bubble there allot of them …

thank s !!!