Why is userdata installed for itself?

In a few box2d code examples, I saw this line of code:

body->SetUserData(self); 

I did not find an explanation in my search. What is the main purpose of installing userdata for myself in box2d?

+4
source share
1 answer

Typically, you assign a visual object (i.e. a sprite) to the Box2D body userdata object for contact listeners.

In the case of a contact callback, you get only box2d objects. Therefore, you get contact bodies from the body of userdata to send messages to the sprite, which represents the body visually.

For example, if you want to run a sprite animation in a collision.

+2
source

Source: https://habr.com/ru/post/1479811/


All Articles