Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a class that returns a b2Body issue
    primarykey
    data
    text
    <p>I have to created a class that returns a b2Body, which I am trying to access in the HelloWorldLayer.mm file. See the circle class below:</p> <p>the Circle.h</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" #import "Box2D.h" #import "PhysicsSprite.h" #define PTM_RATIO 32 @interface Circle : CCLayer { } +(b2Body *)rCircle; @end </code></pre> <p>and the Circle.mm</p> <pre><code>#import "Circle.h" @implementation Circle +(b2Body *)rCircle { //body and fixture defs for circleSprite b2World *world_; b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; b2FixtureDef fixtureDef; fixtureDef.density = 0.1; b2PolygonShape polygonShape; fixtureDef.shape = &amp;polygonShape; PhysicsSprite* circleBodySprite = [PhysicsSprite spriteWithFile:@"circleB.png"]; //[self addChild:circleBodySprite z:1]; //body with circle fixture b2CircleShape circleShape; circleShape.m_radius = circleBodySprite.contentSize.width/2 / PTM_RATIO; fixtureDef.shape = &amp;circleShape; b2Body* chainBase = world_-&gt;CreateBody( &amp;bodyDef ); chainBase-&gt;CreateFixture( &amp;fixtureDef ); [circleBodySprite setPhysicsBody:chainBase]; return chainBase; } @end </code></pre> <p>I keep getting EXC_BAD_ACCESS error pointing to the line:</p> <pre><code> b2Body* chainBase = world_-&gt;CreateBody( &amp;bodyDef ); </code></pre> <p>I don't know what I've done wrong. I've also been accessing the <code>b2Body</code> in the HelloWorldLayer.mm in the following way:</p> <pre><code>[Circle rCircle]; </code></pre> <p>Which also gives a <code>EXC_BAD_ACCESS</code> error.</p> <p>I want the class to return a <code>b2Body</code> so I can create a joint in the HelloWorldLayer.mm. </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.
 

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