Author Topic: Box2d Code questions  (Read 1343 times)

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Box2d Code questions
« on: November 13, 2012, 02:45:22 pm »
Dear All,

I have a few questions regarding Box2d code.

Could someone please give me a quick overview as to what the following different lines of code means:
groundBodyDef.position.Set(0.0f, -10.0f); --> would it make any difference if I didnt not have a float value i.e. would I lose accuracy or would it reduce memory
--> in DFSDK, my ground will be 480pixels by 120pixels at bottom of screen (located at (0,240)). Converting this to metres using my 1/32 scale, would I simply then add these coords to groundBodyDef.position.Set?
*******
rectangle.position.Set(0.0f, 20.0f); --> This will be my sprite. --> would it matter if i didnt have 'f'?
--> in dfsdk, it should be located at (200pixels,180pixels). Therefore, would this be (6.25m, 5.625m) in box2d???
*******
How would I set ground graphics as ground in Box2d?
***
My world height is unlimited, is this automatically done when initialising a world in Box2d?
********
Thank you for taking your time reading this!!!
I would be very grateful if you could provide some answers!
Thank you ever so uch
Michael

DeadSn0wMan

  • Guest
Re: Box2d Code questions
« Reply #1 on: November 14, 2012, 07:53:46 am »
*****
How would I set ground graphics as ground in Box2d?
***

Im not sure what you mean here but if you mean "graphics" as I think you do and want a groud for a game maybe like a floor I would recomend to draw a picture of the ground and then just create simmular static box in Box2D that would react to any incomming bodies. Depending of how your ground would look like you can change the shape of the static box to be more uneven for example. Then just align the picture and the body. Remember that the Box2D static body is not going to be as detaild in shape as the actual picture of the ground.

If you want some basic graphics for debugging I can recomend reading this topic: http://dragonfiresdk.net/forum/index.php?topic=174.msg1401#msg1401 this is crucial for any usage of Box2D in DFSDK

Regarding the world height Im not sure if it's unlimited or just very large but if you want to limit it I think there is a function in the Box2D API or just put up a static body as "roof" depending on the result you want.

Hope this answer some of your questions!

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Box2d Code questions
« Reply #2 on: November 14, 2012, 01:41:29 pm »
Thanks for the reply.
So if i initialise the ground, how do I set the coordinates of my image to be the coordinates of the static object in box2d?

Thank you


DeadSn0wMan

  • Guest
Re: Box2d Code questions
« Reply #3 on: November 14, 2012, 03:54:22 pm »
Take a look at the code example of given to you by the DFSDK team and how they did it. Look at the OnTimer function where they set the views they want to be aligned with the body with ViewSetxxy every frame


By the way try to keep eveything in one thread instead of 4 and deleate solved problems or write SOLVED int the topic title and explain how you did.
« Last Edit: November 14, 2012, 04:05:02 pm by DeadSn0wMan »