Author Topic: how to know the target of a collision.  (Read 4658 times)

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
how to know the target of a collision.
« on: May 12, 2008, 07:34:04 pm »
Hi, I want to know the target of a collision but the CollisionEvent only has getSource () and getObject () that are the same object inmost cases, but a method getTarget () is missing. Is there any way to get the target of a collision is my CollisionListener is on the source of the collision.....?  >:(

I want to put the collisionListener on the bullets to be fired and when they collide with something do something, but on this situation theObject and getSource returns the same object that is the bullet.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to know the target of a collision.
« Reply #1 on: May 12, 2008, 07:38:07 pm »
You have to add the listener to the target, not to the source to get it. getSource() always returns you the source, while getObject() returns the object that has caused the event, i.e. the object to which the listener has been added.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: how to know the target of a collision.
« Reply #2 on: May 12, 2008, 07:45:09 pm »
Wouldnt be better to add the getTarget method????

My first idea was to add the collisionListener to the target but I am having problems trying to transfer it. I guess that adding the method would be a great idea to make it more adaptable to other situations.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to know the target of a collision.
« Reply #3 on: May 12, 2008, 08:54:49 pm »
No, because a collision has one source but can have multiple targets. But one target has only one collision source. That's why it is the way it is.
In your case, why don't you want to add the listener to the target instead? What's the problem in transfering it?
« Last Edit: May 12, 2008, 08:57:49 pm by EgonOlsen »

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Re: how to know the target of a collision.
« Reply #4 on: May 12, 2008, 09:42:01 pm »
a notSerializable exception if I add the listener before transfering it and if I try to add the listener after transfering I am receiving an optionalDataException.
Nada por ahora

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: how to know the target of a collision.
« Reply #5 on: May 12, 2008, 11:10:38 pm »
But after all, it's just an interface. If your implementation isn't serializable, it's not the interface's fault. It has to be something in your listener that can't be serialized correctly. Maybe the complete stack trace would help to find the problem.
About the other exception: I don't see how adding the listener could cause this. It's an exception that is thrown on reading in the serialized object, so i guess it happens on the server? Are you 100% sure that server and client are using the same set of classes?