Game Development Reference
In-Depth Information
// set the shape
[self setBodyShape:shapeName];
return self;
-(void) setBodyShape:(NSString*)shapeName
// remove any existing fixtures from the body
b2Fixture* fixture;
while ((fixture = physicsBody- > GetFixtureList()))
physicsBody- > DestroyFixture(fixture);
// attach a new shape from the shape cache
if (shapeName)
GB2ShapeCache* shapeCache = [GB2ShapeCache sharedShapeCache];
[shapeCache addFixturesToBody:physicsBody forShapeName:shapeName];
// Assign the shape's anchorPoint (the blue + in a circle in PhysicsEditor)
// as the BodySprite's anchorPoint. Otherwise image and shape would be offset.
self.anchorPoint = [shapeCache anchorPointForShape:shapeName];
-(void) dealloc
// remove the body from the world
physicsBody- > GetWorld()- > DestroyBody(physicsBody);
The BodySprite implementation initializes the sprite with the initWithS-
priteFrameName method. Then it calls the world's CreateBody method and sets
self as the user data pointer of the body, allowing you to later access the BodyS-
Search Nedrilad ::

Custom Search