Game Development Reference
In-Depth Information
}
The
addOrbsToForeground()
method is now much simpler. It performs only three
steps. It creates each of the orb nodes, sets their respective positions, and then adds them
to the scene.
The last node class you are going to create is the
BlackHole
class. As you can probably
guess, this class will contain all the code related to a black hole. Create another new file
Listing 9-4
.
BlackHole.swift: The New BlackHole Class
import Foundation
import SpriteKit
class BlackHole: SKSpriteNode {
override init() {
let textureAtlas = SKTextureAtlas(named:
"sprites.atlas")
var frame0 = textureAtlas.textureNamed("BlackHole0")
var frame1 = textureAtlas.textureNamed("BlackHole1")
var frame2 = textureAtlas.textureNamed("BlackHole2")
var frame3 = textureAtlas.textureNamed("BlackHole3")
var frame4 = textureAtlas.textureNamed("BlackHole4")
var blackHoleTextures = [frame0, frame1, frame2,
frame3, frame4]
var animateAction =
SKAction.animateWithTextures(blackHoleTextures,
timePerFrame: 0.2)
var rotateAction
= SKAction.repeatActionForever(animateAction)
super.init(texture: frame0,
color: UIColor.clearColor(),
size: frame0.size())
physicsBody = SKPhysicsBody(circleOfRadius:
size.width / 2)
physicsBody!.dynamic = false
physicsBody!.categoryBitMask
= CollisionCategoryBlackHoles
physicsBody!.collisionBitMask = 0