Game Development Reference
In-Depth Information
SKPhysicsBody(circleOfRadius: self.size.width
/ 2)
physicsBody!.dynamic = false
physicsBody!.categoryBitMask
= CollisionCategoryPowerUpOrbs
physicsBody!.collisionBitMask = 0
name = "POWER_UP_ORB"
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
This new Orb class, much like the SpaceMan class, contains all the code to set up the
node's texture and its physicsBody . Once you have the new Orb class in place, you
can then change the addOrbsToForeground() method to look like the following
simplified method:
func addOrbsToForeground() {
var orbNodePosition =
CGPoint(x: playerNode!.position.x, y:
playerNode!.position.y + 100)
var orbXShift : CGFloat = -1.0
for i in 0...49 {
// new code to use an orb
var orbNode = Orb()
if orbNodePosition.x - (orbNode.size.width * 2) <=
0 {
orbXShift = 1.0
}
if orbNodePosition.x + orbNode.size.width >=
self.size.width {
orbXShift = -1.0
}
orbNodePosition.x += 40.0 * orbXShift
orbNodePosition.y += 120
orbNode.position = orbNodePosition
self.foregroundNode!.addChild(orbNode)
}
Search WWH ::




Custom Search