Game Development Reference
In-Depth Information
After that, add the following lines to the init method of ERGPlayer.m :
self.engineEmitter = [NSKeyedUnarchiver
unarchiveObjectWithFile:
[[NSBundle mainBundle]
pathForResource:@"jet" ofType:@"sks"]];
self.engineEmitter.position = CGPointMake(-12, 18);
self.engineEmitter.name = @"jetEmitter";
[self addChild:self.engineEmitter];
self.engineEmitter.hidden = YES;
In the first line, we unarchive the emitter from file. Each Sprite Kit node is
archivable and serializable, so here we utilize that fact. Next, we set the position
of the emitter in our player sprite, give the emitter a name, and hide it since we
don't want it to be on always.
If you remember, we have already handled all physics of acceleration and
added the property that tells us whether the player is accelerating with the
same name. Now that we need extra behavior from that property, add a
new setter to it in ERGPlayer.m :
- (void) setAccelerating:(BOOL)accelerating
{
if (accelerating) {
if (self.engineEmitter.hidden) {
self.engineEmitter.hidden = NO;
}
} else {
self.engineEmitter.hidden = YES;
}
_accelerating = accelerating;
}
Here we hide or show jet flames based on our state. If you launch the game
now, you will see a nice effect that surely added some spice to our game. If Xcode
raises a warning, make sure that the accelerating property in ERGPlayer.h is of
non-atomic type.
 
Search WWH ::




Custom Search