Game Development Reference
In-Depth Information
Box2D doesn't need to perform certain calculations on static objects, and the other
simply that objects colliding with a static body willn't affect a static body's position or
rotation at all.
Listing 13-4 . TablePart Class Implementation
#import "TablePart.h"
#import "Helper.h"
@implementation TablePart
-(id) initWithWorld:(b2World*)world position:(CGPoint)pos name:(NSString*)name
{
if ((self = [super initWithShape:name inWorld:world]))
{
// set the body position
physicsBody- > SetTransform([Helper toMeters:pos], 0.0f);
// make the body static
physicsBody- > SetType(b2_staticBody);
}
return self;
}
+(id) tablePartInWorld:(b2World*)world position:(CGPoint)pos name:(NSString*)name
{
return [[self alloc] initWithWorld:world position:pos name:name];
}
@end
To create the three required TablePart instances (and later other pinball elements),
I've created the TableSetup class, which creates the various BodySprite in-
stances that will make up the bodies of the pinball table. TableSetup inherits from
CCSpriteBatchNode to improve the rendering performance of the pinball table's
elements.
This is the header file of the TableSetup class:
 
Search Nedrilad ::




Custom Search