Hello, i’m having some problems with box2d + cocos2dx
It’s nothing specific, its basically everything.
For example, I’m having trouble to set the body’s size with the sprite size. The sprite is very big and the body is very small. And im not making the sprite’s size more bigger, it has the default scale. Even setting the body to like 30 width and 30 height…
Another problem is with the step time, I’ve tested A LOT of techniques of MANY topics of many forums, but i haven’t find anything , but the body is pushing down very slow, and when I apply any force to it, it takes a lot of time to change the velocity.
So, my question is, there is any SIMPLE way to use box2d in cocos2dx?? Please give me just a simple example…
BTW: I’ve tried to test the testbed in cpp-tests, but the box2d is with some error that I couldn’t fix.
I’m not sure how you are using it - but generally there is no direct link between the size of the sprite and the size of the box2d body - except what you program.
e.g. I have a Box2d body that is a circle with a diameter of 1m
I create a sprite with a circle with a diameter of 64 pixels to represent the Box2d body.
So - in this case my ratio of pixels to meters is 64
Now, I check the location of the Body, multiply the X and Y by 64 and position my sprite there.
If I turn on Box2d debug, I need to tell it what that ratio is (i.e. 64 in this case) then the debug circle will be the same size as my sprite
So the question is, how big is your sprite, how big is your body?
if you set the body to 30 wide and 30 high you can still use the same sprite - but your ratio is now 64/30 (i.e. about 2)
the reason it may be slow is, if you have ‘normal’ gravity with a large body like you have, the mass fo the body is large and so the inertia is large - so it takes a large effort to move it!
Bx2d works best with small values - so to start, try setting up what I have suggested with a simple circle body, and a simple sprite, and experiment.
I’m sorry I don’t have a simple Box2d example to show you
Thank you for the answer! I tried to set some things and its better now , its not slow anymore, and im using 32 for my ratio. But im having problems to draw the debug now… But it’s ok, at least its working now, Thank you again