Adding the particle emitter to the game
We will attach our new emitter to the Player
node, so the emitter will create new white circles wherever the player flies. We can easily reference the emitter design we just created in the editor from our code. Open GameScene.swift
and add this code at the bottom of the didMove
function:
// Instantiate a SKEmitterNode with the PierrePath design: if let dotEmitter = SKEmitterNode(fileNamed: "PierrePath") { // Position the penguin in front of other game objects: player.zPosition = 10 // Place the particle zPosition behind the penguin: dotEmitter.particleZPosition = -1 // By adding the emitter node to the player, the emitter moves // with the penguin and emits new dots wherever the player is player.addChild(dotEmitter) // However, the particles themselves should target the scene, // so they trail behind as the player moves forward. dotEmitter.targetNode = self }
Run the project. You should see the white...