Problem when using Box 2D in my game


Hi everybody,
I’ve developed a simple game like Wind Runner and have a problem when loading grounds
I attached each ground with the Box2D body

  • var i = grounds.length;
    while (i—) {
    var ground = grounds[i];

// Add sprite
var sprite = cc.Sprite.createWithSpriteFrameName( + “.png”);
sprite.setPosition(cc.p(pos.x + ground.x, pos.y + ground.y));
sprite.setAnchorPoint(cc.p(0, 0));
s_GameLayer.addChild(sprite, –1, TAG_GROUND);

//add body
bodyDef.position.Set(posX + ground.x / PTM_RATIO, posY + ground.y / PTM_RATIO);
bodyDef.userData = sprite;
var b2ground = s_b2World.CreateBody(bodyDef);

And when create the running man i attached with the Box 2D body, too

My problem is sometime when the running man collide with ground, it had a weird behavior. it collided with the line between two grounds and goes back unfortunately
I’ve attached the debug draw image here
Can everybody help me?Any help would be greatly appreciated
Sorry for my bad English

Screen Shot 2013-07-24 at 5.38.01 PM.png (14.0 KB)