I’ve encountered a weird problem about positioning bodies in cocos2d/box2d.
If I set b2BodyDef type as b2_staticBody, I can’t set bodies on any position out of multipliers of PTM_RATIO. Let me explain:
#define PTM_RATIO 32.0
...
myBodyDef_1.type = b2_staticBody;
myBodyDef_1.position.Set(320.0/PTM_RATIO, 320.0/PTM_RATIO);
...
and
...
myBodyDef_1.type = b2_staticBody;
myBodyDef_1.position.Set(333.0/PTM_RATIO, 333.0/PTM_RATIO);
...
gives the same result. No change in position. Difference of 13 pixels means nothing.
If I make the difference more than PTM_RATIO it appears 1 PTM_RATIO (32px) away.
For example:
...
myBodyDef_1.type = b2_staticBody;
myBodyDef_1.position.Set(358.0/PTM_RATIO, 358.0/PTM_RATIO);
...
Diffrence of 38px, but appears only 32px(1 PTM_RATIO) away.
I tried using direct values like 1.0 and 1.1
It didn’t work. I can’t get rid of multipliers of PTM_RATIO.
One more hint, if I use b2_kinematicBody as type, it works perfect.
Any idea?
try adding explicit conversation:
358.0/((float)PTM_RATIO).try myBodyDef_1.position = b2Vec2(333.0/PTM_RATIO, 333.0/PTM_RATIO); and explicit conversation here.
try
Let me know the result please