Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the code, you created a single ball. I think what you want to do is create multiple balls, all of which have a separate b2Body in the physics simulation.</p> <p>There are several ways you can do this, but I'm going to stick with the "brute force approach" for now.</p> <p>Create a static function like this:</p> <pre><code>static b2Body* CreateBall(b2World* world, CCNode* node, CCPoint position) { // Create sprite and add it to the layer CCSprite* ballSprite = [CCSprite spriteWithFile:@"ball.png" rect:CGRectMake(0, 0, 52, 52)]; ballSprite.position = ccp(position.x, position.y); [node addChild:ballSprite]; // Create ball body and shape b2BodyDef ballBodyDef; ballBodyDef.type = b2_dynamicBody; ballBodyDef.position.Set(position.x/PTM_RATIO, position.y/PTM_RATIO); ballBodyDef.userData = ballSprite; b2Body* body = world-&gt;CreateBody(&amp;ballBodyDef); b2CircleShape circle; circle.m_radius = 26.0/PTM_RATIO; b2FixtureDef ballShapeDef; ballShapeDef.shape = &amp;circle; ballShapeDef.density = 1.0f; ballShapeDef.friction = 0.2f; ballShapeDef.restitution = 0.4f; body-&gt;CreateFixture(&amp;ballShapeDef); return body; } </code></pre> <p><strong>NOTE: I typed this in. I did not compile it. It may need a little tweaking.</strong></p> <p>Call this each time you want to create a new ball and pass in the world and position you want the ball to be at.</p> <p>Was this what you needed?</p> <p>I have larger examples (and code) using Box2D and working with graphics, etc., on my site at <a href="http://www.nonlinearideas.com" rel="nofollow">http://www.NonlinearIdeas.com</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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