Game Development Reference
In-Depth Information
emitterNode.speed = 500.0f;
8. As output of all above creation of
FireParticle
file using particle editor and
adding it in the code using
SKEmitterNode
class on the spaceship, the thrust
appears at the back side of our character of game that is, spaceship.
The following are the steps to add the smoke effect on collision of the coin and the space-
ship in our game:
1. Open the
FSMyScene
class and add a method called
addCoinColli-
sionEffectWithSpaceShip
.
2. Repeat the steps we performed while creating the thrust of the spaceship. Specify
the filename and its type to get the path.
NSString *emitterPath = [[NSBundle mainBundle]
pathForResource:@"SmokeParticle" ofType:@"sks"];
3. After this, we can instantiate a new object of
SKEmitterNode
using
NSKeyedUnarchiver
, which will return an object of
SKEMitterNode
for a
path that is provided.
SKEmitterNode *emitterNode = [NSKeyedUnarchiver
unarchiveObjectWithFile:emitterPath];
4. Once the object of the emitter is created, specify its position, which will be the
center of spaceship.
emitterNode.particlePosition = CGPointMake(0,0);
5. Lastly, after all the configuration is done, just add the
emitterNode
object
(that is,
SmokeEffect
object) to
SpaceShipSprite
.
[self.spaceShipSprite addChild:emitterNode];
6. Add all these lines to the
addCoinCollisionEffectWithSpaceShip
method and it looks like this.
7. Now call this method when the coin collides with the spaceship that is, in method
named
spaceShipCollidedWithCoin
.
[self addCoinCollisionEffectWithSpaceShip];