Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Body after adding View dynamically #13

Closed
OFmarting opened this issue Jun 15, 2016 · 6 comments
Closed

Get Body after adding View dynamically #13

OFmarting opened this issue Jun 15, 2016 · 6 comments

Comments

@OFmarting
Copy link

Hi,
I'm adding Views to the PhysicsLayout with addView(). I want to create a Joint between multiple dynamically added Views. How can I access the Body Instance right after adding the View so I can create a Joint?

@Jawnnypoo
Copy link
Owner

Hey there, you should be able to use getPhysics().findBodyById(R.id.yourviewid) on the PhysicsLayout. Have you given this a try?

@OFmarting
Copy link
Author

Unfortunately the Body is null when I try to access it after adding the View with addView().

@Jawnnypoo
Copy link
Owner

Hey there, this has to do with the fact that the body is not actually created until the view measures itself. This is due to the fact that we need to wait for measure before adding the bodies so that we have the proper size to set the bodies to. A OnBodyCreatedListener has been added to the 2.1.0 release so that you can hook into the body creation and do the connections as needed.

@OFmarting
Copy link
Author

Thank You!

@Jawnnypoo
Copy link
Owner

No problem! Let me know if it works out

@OFmarting
Copy link
Author

Everything worked out well 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants