Tap's not registering when using physics engine

What I’m missing?

Here is a code that randomly spawns balls and if tapped, they are removed from the screen. Everything works fine, but I have feeling that sometimes tap isn’t registered:

[lua]local function piirraball()

local ball = display.newCircle( 100, 100, 30 )
ball:setFillColor(128,128,128)
ball.x = math.random(10,300)
ball.y = 0
ball.y = math.random(10,480)

function ball:tap(event)
ball.x=-1000
end

ball:addEventListener( “tap”, ball )

end

timer.performWithDelay(500,piirraball,10)[/lua]

Now - if I add some physics to balls, I’m certain that simulator misses clicks. Sometimes I have to click a ball about 10 times, before “tap” is registered. Here is the code:

[lua]local physics = require “physics”
physics.start()
physics.setGravity(0,1)
physics.setScale( 30 )
physics.setDrawMode( “hybrid” )

local function drawBall()

local ball = display.newCircle( 100, 100, 30 )
ball:setFillColor(128,128,128)
physics.addBody(ball, “dynamic”,{density = 1, friction = 0.1, bounce = 0.1, radius = 30})
ball.x = math.random(10,300)
ball.y = 0
function ball:tap(event)
ball.x=-1000
end

ball:addEventListener( “tap”, ball )

end

timer.performWithDelay(500,drawBall,10)[/lua]

What I’m doing wrong?

Hi @Aatos Media,

Can you try applying a touch listener instead of tap, and check if you get a “began” phase on these?

Brent

Thanks Brent!

Everything works fine using touch event. I even didn’t try that, 'cause I just wanted to test some basic logic. So maybe the advice is, that don’t use tap events :slight_smile:

Hi @Aatos Media,

Tap events are fine, and should be registering on physics bodies. What may be happening is that, because your physics bodies are relatively small (radius of 30), you’re not getting both the began and ended phase on the moving object in the limited region/timespan (dictated by the device) which constitutes as a tap. You could check this by increasing the size of your physics bodies to, say, 100 and testing again… that would determine if it’s an internal issue or not.

Take care,

Brent

Hi @Aatos Media,

Can you try applying a touch listener instead of tap, and check if you get a “began” phase on these?

Brent

Thanks Brent!

Everything works fine using touch event. I even didn’t try that, 'cause I just wanted to test some basic logic. So maybe the advice is, that don’t use tap events :slight_smile:

Hi @Aatos Media,

Tap events are fine, and should be registering on physics bodies. What may be happening is that, because your physics bodies are relatively small (radius of 30), you’re not getting both the began and ended phase on the moving object in the limited region/timespan (dictated by the device) which constitutes as a tap. You could check this by increasing the size of your physics bodies to, say, 100 and testing again… that would determine if it’s an internal issue or not.

Take care,

Brent