how to destroy a body

  ... discussions about development with the GLES1 branch of AndEngine.

how to destroy a body

Postby shani74 » Sat Jul 28, 2012 10:25 am

i am using physic in my game but i am stuck in removing a body. Bodies are creating problem for me.
Some times in start of game some invisible bodies are moving in the scene and some time game halt due to bodies.
i am removing bodies like in different tutorial in andengine. let me know where i am going wrong
Posts: 115
Joined: Thu Feb 23, 2012 5:34 am

Re: how to destroy a body

Postby OzLark » Sat Jul 28, 2012 12:55 pm

I had too many issues removing bodies during game play even with everything happening via runOnUpdateThread I would still get random body removal errors - I gave up on destroying bodies and set them to active/inactive as needed now.

It's a good idea to use pools to avoid wasting resources.

Edit: Also be aware that you can not destory bodies in the physical world contact handlers - you need to either perform the deletes using runOnUpdateThread() or via flags and some logic in an new/existing update handler.
Did this post help you? Feel free to return the gesture by downloading Ninja Bees, creating a level (or more) and sharing it to the Ninja Bees website!

Ninja Bees - Our latest Android game, check it out on Google Play (free) or paid with no ads
Posts: 1130
Joined: Sun Feb 05, 2012 3:19 am

Re: how to destroy a body

Postby shani74 » Thu Aug 02, 2012 6:09 am

thanks to your reply
but body.setActive(false) is not working for me
Posts: 115
Joined: Thu Feb 23, 2012 5:34 am

Re: how to destroy a body

Postby ViktorS » Thu Aug 02, 2012 7:43 am

Like OzLark says there are problems with body removal and creation even if you do it right. I had them for the longest time(I don't even want to count how many times I got the linker errors due to physics failing.) But in the end, shani you are too quick to discard OzLarks suggestion. Setting an inactive setting is much faster and safer. What I do is set bodies meant for deletion to inactive and then delete them on update thread.
'Javelin OU' presents, my latest game - Joj the alien
Posts: 580
Joined: Thu Oct 27, 2011 2:18 pm

Return to GLES1

Who is online

Users browsing this forum: rajesh_king and 13 guests