Game Development Reference
In-Depth Information
priority:0
swallowsTouches:NO];
// schedule updates
[self scheduleUpdate];
}
return self;
}
+(id) ballWithWorld:(b2World*)world
{
return [[self alloc] initWithWorld:world];
}
-(void) cleanup
{
[super cleanup];
[[CCDirector sharedDirector].touchDispatcher removeDelegate:self];
}
Just as with the TablePart class, the initialization begins by calling the BodyS-
prite init method initWithShape , which takes care of setting up the body and
sprite. Well, it almost does—because you do have to set the body type to be a
b2_dynamicBody to let Box2D know that this body should be treated as a movable
object.
In addition, the angular damping value of the body is set to 0.9f , which makes the
ball's angular motion more resistant to change. This allows the ball to slide over a sur-
face without rolling too much, which is standard behavior for heavy pinballs made of
metal.
Tip Tweaking physics values is usually very labor-intensive and requires care-
ful consideration of each change. It's also frequently underestimated by both
designers and programmers alike. That's because all physics attributes are inter-
related or interdependent. For example, if you change the density (mass), fric-
tion, or restitution of one object, you'll inevitably alter the behavior of any col-
liding object. Notice that this example pinball game, although it does a fairly
Search Nedrilad ::




Custom Search