Game Development Reference
In-Depth Information
How to do it
Continuing with the same Xcode project, now we will create our solution kit for this
chapter that is, Chapter 4.
The following are the steps to add the spaceship's thrust in our game:
1. Open the FSMyScene class and add a method called addSpaceShipThrust .
To get a particle file, first we need the file's path to pick it from the bundle. The
method to find the path will require the name of the particle file and its type.
NSString *emitterPath = [[NSBundle mainBundle]
pathForResource:@"FireParticle" ofType:@"sks"];
2. After this, we can instantiate a new object of SKEmitterNode with the file path
that is, emitterPath used in preceding code. This is accomplished by using
NSKeyedUnarchiver , which will return an object of SKEMitterNode for a
path that is provided.
SKEmitterNode *emitterNode = [NSKeyedUnarchiver
unarchiveObjectWithFile:emitterPath];
3. Once the object of emitter is created, specify its position which has to be given ac-
cording to the center of the spaceship as it's its thrust.
emitterNode.particlePosition =
CGPointMake(-self.spaceShipSprite.frame.size.width/
2,0);
4. Lastly, after all the configuration is done, just add the emitterNode object to
SpaceShipSprite .
[self.spaceShipSprite addChild:emitterNode];
5. Call the addSpaceShipThrust method in the init method just after the ad-
dSpaceShip method.
6. The preceding SKEmitterNode was fully created using the SpriteKit Particle
file. But we can tweak the properties of SKEmitterNode in the code itself.
7. As we want to increase the speed of the thrust after adding the emitter node, simil-
arly, for this, we can edit the speed property of the emitter node object.
Search WWH ::




Custom Search