""

Tag Archive: physics

world.CreateBody() creating NULL ??

I was doing some test stuff for a game that uses Box 2D flash. I found and learned a thing that i didn’t knew and it was very important. I had created a world with some bodies(polygons and circles) added to it. I was destroying and creating bodies just to play around. So when i was creating a body dynamically at runtime, i found out that body wasn’t getting created because world.CreateBody(bodyDef) was returning NULL. I was really surprised when i found this. I traced everything like if bodyDef and world was not null and all that. So i was looking through my code again and again to find why world.CreateBody was returning null. Then i was suspicious about something. So what i did something to confirm my suspicion that before creating a body i waited all body to sleep i.e when they are not moving or interacting. After all bodies were sleep i created a body and viola bingo bang boom my body was created. So my suspicion was true that when world is stepping then world.CreateBody always returned null (I tested it again and again). Hmnnnnnn so this was pretty interesting. I am still working around to find a solution for this as i haven’t find any very graceful good solution to create a body during world step. if you have any suggestion/tips or solution please do share.

Gracias

I have been doing game development on android very recently (2 weeks) :D. And i bought samsung galaxy having android 2.1 to test my games and demos. I am pretty happy with the results and enjoying very much. Before this i had made games for j2me mobile devices and still making. Well anyway i am not discussing android game development here so i am coming to the primary focus of this post.

Physics. Yeah physics is phun and if decent physics is added to your game then it makes game more enjoyable, of course if gameplay design is good and fun. I have been playing with my own very very basic physics code(collision detection, collision response) that i have written for j2me. It is working fine in android after tweaking my code here and there. But i wanted more features so i thought to look for any decent free opensource physics engine for android. Unfortunately i didn’t get much success. There were some forums and tutorials where using Box2d with android was discussed. This site has shown the tutorial using JBox2d on android and is been discussed by the people there.

I am a big fan of Box2d. I have been using JBox2d and Box2d flash for my respective platform based game. Library had fulfilled my satisfaction and need. I have not tested JBox2d on android yet. I wanted to do few research on it before doing that. In few forums people complained that if using more than 5 bodies, it brings the FPS rate down and makes simulation very slow. I haven’t checked that but is going to write code to see if its true. I think it may depend on hardware device specification and capability because i have played Angry Birds on my samsung galaxy s and physics of game works just fine and smooth. I came across one site where they showed the graph on how much number of bodies/elements effect the FPS(frame rate) using Box2d and Chipmunk. Here it is.

So now i am going to write a simple code of falling polygons using Box2d on android and see the FPS and performance. I will post the results and my experience on next post ASAP.

Merry Christmas & Happy New Year
Gracias.