문제

I'm a beginner Java/LibGDX developer so I'm sorry if I got something terribly wrong here but here's my question:

How could a Box2d body have some object associated with it?

For example a Box2d ball body associated with object that describes how much energy the ball has, what's the charge of the ball, and such.

This might be terribly wrong but here's what I've been trying to do:

I tried to set userdata of the ball to my object like this:

Body.setUserData(MyObject); 

and then when I need it, I would retreat it with:

Body.getUserDate();

which returns an object and I have no idea what to do with it because I don't know how to access it's fields or methods..

I hope you understood the question, if not ill try to modify it.

Thank you.

도움이 되었습니까?

해결책

You have to cast it to your type so you can access it like you're expecting..

MyObject myObject = (MyObject) Body.getUserData();
myObject.property = value;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top