Is There Any Way To Register A Physic Object For Events?

Hi,

As the title says, if I create physic for a display object with “addBody”, is there any way to get an handle and register that physic body to events like “touch” event?

Thanks.

Hi Aidin,

You could potentially solve this by placing a temporary physics “dot” at the touch location (say, just a circle of 10 pixels diameter) and then sensing collision on it. This dot would only need a brief time on the screen… 1 game cycle would suffice… and then you can clear it (or just re-use the same dot and toggle it to active then inactive, so you’re not always creating and removing this object for every touch). If the object senses collision during its brief time on screen, you know you’ve got a touch on that object.

Does that help somewhat?

Brent

yes, it is possible. if ball is a physics object
 

ball:addEventListener( "touch", ballTouch )

will make it listen to touch events

Hi Aidin,

You could potentially solve this by placing a temporary physics “dot” at the touch location (say, just a circle of 10 pixels diameter) and then sensing collision on it. This dot would only need a brief time on the screen… 1 game cycle would suffice… and then you can clear it (or just re-use the same dot and toggle it to active then inactive, so you’re not always creating and removing this object for every touch). If the object senses collision during its brief time on screen, you know you’ve got a touch on that object.

Does that help somewhat?

Brent

yes, it is possible. if ball is a physics object
 

ball:addEventListener( "touch", ballTouch )

will make it listen to touch events

Thanks Brent for your reply.

How can I apply your approach to gameUI’s drag code?

Thanks Brent for your reply.

How can I apply your approach to gameUI’s drag code?