Game Development Reference
In-Depth Information
+(id) setupTableWithWorld:(b2World*)world
return [[self alloc] initTableWithWorld:world];
As of now, the job of the TableSetup class is to create the three TablePart
classes that make up the static background elements of the pinball table. It also sets the
correct position of each TablePart instance, which is influenced by their shape's
anchorPoint . For example, the table-top image has its shape anchorPoint
set to the upper left-hand corner of the image so that positioning it at (0, 480) aligns the
image and shape correctly at the top border of the screen. Because TablePart inher-
its from BodySprite , which inherits from CCSprite , it's legal and quite conveni-
ent to add these classes directly to the TableSetup class, which inherits from CCS-
priteBatchNode .
You'll later extend the TableSetup class to add the other pinball table ele-
ments—plunger, ball, bumpers, and flippers.
Tip Did you notice the use of the ccp method? It's exactly the same as the
CGPointMake method, but some cocos2d developers prefer to use ccp over
CGPointMake simply because it's shorter to type. You'll find the entire ccp
line of helpful math functions defined in CGPointExtension.h . They tend
to come in handy particularly when you're developing physics games. Box2D
also brings its own math functions that are defined in b2Math.h . The reason
is that Box2D's vector classes like b2Vec2 are C++ classes, and not C structs
like CGPoint , meaning the Box2D data structures generally can't be used with
the ccp methods.
The TableSetup class itself is initialized by the PinballTableLayer class,
which is based on the HelloWorldLayer class of the Box2D project from Chapter
12 . Listing 13-6 shows the interface of the PinballTableLayer class.
Listing 13-6 . PinballTableLayer Class Header File
Search Nedrilad ::

Custom Search