Game Development Reference
In-Depth Information
In addition, you can change the sprite's body shape by calling setBodyShape . This
removes any existing fixtures from the body and then adds the fixtures associated with
the given shapeName from the GB2ShapeCache . This will change only the colli-
sion shape of the body and preserve the body's current state of motion, like its velocity,
position, and rotation. Keep in mind that calling this method is time-consuming and
should be done only as needed. It's certainly not a good idea to change a body's shape
every frame.
All classes inheriting from BodySprite now have to concern themselves only with
setting the correct shape name and any code that's unique to the class.
Creating the Pinball Table
The pinball's table is made up of three individual images and associated shapes, named
table-top , table-left , and table-bottom . You'll create the table using the
TablePart class, which inherits from BodySprite . The TablePart header only
adds the static initializer method tablePartInWorld , as seen in Listing 13-3 .
Listing 13-3 . TablePart Class Interface
#import "BodySprite.h"
@interface TablePart : BodySprite
{
}
+(id) tablePartInWorld:(b2World*)world position:(CGPoint)pos name:(NSString*)name;
@end
The TablePart implementation in Listing 13-4 is also rather unimpressive because
its only purpose is to initialize the BodySprite and then set body's position to the
desired location. This will also update the sprite's position automatically the next time
the update method of the PinballTableLayer class is executed (refer to Listing
13-3 ) .
The TablePart class also sets the body type to b2_staticBody , which makes
each TablePart a nonmoving object. This has two advantages, one being that
 
 
 
Search Nedrilad ::




Custom Search