Game Development Reference
In-Depth Information
in the TexturePacker Output pane. The pinball.tps file used in this chapter
has this check box already set; it removes the .png extension from the sprite
frame names. That way, both the TexturePacker sprite frames and PhysicsEditor
shape names will be identical.
For the texture atlas, you use TexturePacker and add the pinball folder as a smart
folder reference, meaning that TexturePacker will keep the texture atlas contents up to
date with all changes to the images in the pinball folder. Refer to Chapter 6 for in-
structions on how to set up a smart folder reference.
You also need to set an additional option you haven't used yet: trim sprite names. This
feature removes the .png suffix from the sprite names. The advantage is that you can
use the same names for the physics shapes and the sprites. The only caveat is that
you'll have to refer to sprite frame names without the .png extension, which admit-
tedly out of habit is sometimes easy to forget.
Listing 13-2 shows the BodySprite class implementation file.
Listing 13-2 . The BodySprite Class Implementation
#import "BodySprite.h"
@implementation BodySprite
@synthesize body;
-(id) initWithShape:(NSString*)shapeName inWorld:(b2World*)world
// init the sprite itself with the given shape name
self = [super initWithSpriteFrameName:shapeName];
if (self)
// create the body
b2BodyDef bodyDef;
physicsBody = world- > CreateBody(&bodyDef);
physicsBody- > SetUserData((__bridge void*)self);
Search Nedrilad ::

Custom Search