Colission Listener problem

Hi,

I am developing my first application using GhostControl and implementing the PhysicsCollisionListener interface.

I have a GhostControl attached to a Node and a Sphere that collides with it.

I have implemented a collision method on my listener so that, even if multiple collision events between the sphere and the GhostControl are triggered, only the first invocation does some work:

public void collision(PhysicsCollisionEvent event) {

if (!object_in){

object_in=true;

System.out.print(“Collisionn”);

}

}



However the execution of the program displays 4 “Collision” messages (I believe this is because I have a machine with 4 CORES). Is there any way to make my collision method process only the first collision event between my GhostControl and the Sphere and discard the remaining ones no matter the number of CPU cores?



I have also tried with “synchronized(this){…}” in my collision method but the behavior is the same.



Thanks in advance for your help

Are u sure you aren’t registering such listener multiple times?

2 Likes

You’re right glaucomardano. I had accidentally registered the listener multiple times.

Thanks for your quick answer