Hi all, in the past days i am learning with box2d.
Its been fun testing objects and stuff.
Now, i have a question, what is your golden rule in working with box2d?
What points you constantly remind yourself when working with it?
Methods to efficiently code and avoid fps loss?
I would also like to target low end phones, what should I keep in mind?
Tips you can give to a box2d noob like me?
Ps: how to represent a explosion force in box2d?
Thanks for the time reading this.
Comments
Its not LUA code but you'll get the gist of what hes on about. There is a page there where the guy uses box2d particles to simulate explosions, very cool stuff.
Likes: neverjoy
http://giderosmobile.com/guide
some tips:
1) You can't destroy or create box2D bodies within the BEGIN_CONTACT, END_CONTACT listeners, eg,
world:addEventListener(Event.BEGIN_CONTACT,collideBEGIN)
you should not try to destroy bodies within the collideBEGIN function. BUT this does not mean you need to wait till bodies are out of contact before destroying them, you just can't destroy them within the actual listener. Eg if you have 2 crates stacked on top of each other there will be a BEGIN_CONTACT when they first touch. But even if they remain in contact you can destroy either one of them later on within an ENTER_FRAME listener.
2) You must remember to actually destroy bodies when going to the next level. It's not enough to destroy the corresponding Sprites. For instance its common to have a Sprite eg ball=Bitmap.new(Texture.new("ball.png")) and then add a body reference as a field in the ball table, ball.body=world:createBody(..). Then you get rid of the ball with
You should of course do
Likes: neverjoy
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
edit: i have a question.. in my case i wanted to create a body that does destruction physics(body is broken apart into smaller pieces on impact), which way is the right approach? making small body components and attach them together by weld joint and destroy that joint on impact? or create one body with multiple fixtures and then on impact, recreate smaller bodies based on created multiple fixtures?
also i dont know how to manage their sprites(does an object with multiple fixtures can have one sprite? etc.)
i dont quite know the purpose of creating multiple fixtures and what scenarios creating them best applies.
1. Create the unbroken body and add to Box2D
2. Create the broken body pieces as a separate body and disable it from collision detection (with setActive(false) if memory serves, or exclude it from collision detection in some other way).
3. When the first body needs to beak up, exclude it from collisions, move the second body to its position and location, then activate the second body
This would be quite efficient, because adding and removing bodies and fixtures are hard work for the CPU.
http://appcodingeasy.com/Gideros-Mobile/Gideros--Creating-and-breaking-complex-shape