Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2D+Box2D: Stack bodies that doesn´t fall?
    text
    copied!<p><strong>EDIT 2: Problem solved! I can´t promise it will work with different settings, but by putting my block´s body density to 0, the stack of blocks did not fall when new blocks are added.</strong> </p> <p>I´m sorry about the poor title of the question, I´ll explain my problem closer here:</p> <p>So, I´ve used Box2D and cocos2D to setup a simple project where two boxes stacks on top of each other (I´m planning to expand to 8-10 boxes). Right now, using a friction of 10.0f on each box, the box at the top still moves around a little. If I would add more boxes, the "tower" would fall and I don´t want that. </p> <p>I want the boxes to use the gravity to move down, but I never ever want them to change there start x-value. So, how could I prevent my tower of boxes to fall over or prevent my boxes from moving in x-direction?</p> <p>EDIT: Posting some code This code creates on of the boxes, the other one just have a different sprite file.</p> <pre><code>CCSprite *block = [CCSprite spriteWithFile:@"red.png"]; block.position = ccp(200,380); [self addChild:block]; //Body definition b2BodyDef blockDef; blockDef.type = b2_dynamicBody; blockDef.position.Set(200/PTM_RATIO, 200/PTM_RATIO); blockDef.userData = block; b2Body *blockBody = _world-&gt;CreateBody(&amp;blockDef); //Create the shape b2PolygonShape blockShape; blockShape.SetAsBox(block.contentSize.width/PTM_RATIO/2, block.contentSize.height/PTM_RATIO/2); //Fixture defintion b2FixtureDef blockFixtureDef; blockFixtureDef.shape = &amp;blockShape; blockFixtureDef.restitution = 0.0f; blockFixtureDef.density = 10.0f; blockFixtureDef.friction = 10.0f; _redBlockFixture = blockBody-&gt;CreateFixture(&amp;blockFixtureDef); </code></pre> <p>Nothing fancy.</p> <p>Regards.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload