Game Development Reference
In-Depth Information
let blackHoleTextures = [frame0, frame1, frame2,
frame3, frame4]
let animateAction =
SKAction.animateWithTextures(blackHoleTextures,
timePerFrame: 0.2)
let rotateAction
= SKAction.repeatActionForever(animateAction)
let moveLeftAction = SKAction.moveToX(0.0, duration:
2.0)
let moveRightAction = SKAction.moveToX(size.width,
duration: 2.0)
let actionSequence = SKAction.sequence([moveLeftAction,
moveRightAction])
let moveAction
= SKAction.repeatActionForever(actionSequence)
for i in 1...10 {
var blackHoleNode = SKSpriteNode(imageNamed:
"BlackHole0")
blackHoleNode.position = CGPoint(x: size.width
- 80.0, y: 600.0 * CGFloat(i))
blackHoleNode.physicsBody =
SKPhysicsBody(circleOfRadius:
blackHoleNode.size.width / 2)
blackHoleNode.physicsBody!.dynamic = false
blackHoleNode.physicsBody!.categoryBitMask
= CollisionCategoryBlackHoles
blackHoleNode.physicsBody!.collisionBitMask = 0
blackHoleNode.name = "BLACK_HOLE"
blackHoleNode.runAction(moveAction)
blackHoleNode.runAction(rotateAction)
foregroundNode!.addChild(blackHoleNode)
}
}
Once you have made all of these changes, save your work and run the application again.
This time you will see that as the black holes are moving back and forth across the scene,
they are also rotating as they are animated through each of the textures in the black-
HoleTextures array.
Search WWH ::




Custom Search