Game Development Reference
In-Depth Information
orbNode!.physicsBody = SKPhysicsBody(circleOfRadius:
orbNode!.size.width / 2)
orbNode!.physicsBody!.dynamic = false
orbNode!.physicsBody!.categoryBitMask
= CollisionCategoryPowerUpOrbs
orbNode!.physicsBody!.collisionBitMask = 0
orbNode!.name = "POWER_UP_ORB"
foregroundNode!.addChild(orbNode)
Adding More Orbs to the Scene
The game scene is ready to start adding some real game components. The first is going to
be a collection of additional orb nodes. The orbs will be laid out in two lines above the
player. The first line of orbs, a collection of 20, will be centered and will start 100 points
above the playNode with 140 points in between each node's anchorPoint . The
second set of orb nodes will also be a string of 20 nodes, but they will be 50 points to the
right of the player. The code to add the first set of orb nodes is shown in the following
snippet:
var orbNodePosition = CGPointMake(playerNode!.position.x,
playerNode!.position.y
+ 100)
for i in 0...19 {
var orbNode = SKSpriteNode(imageNamed: "PowerUp)
orbNodePosition.y += 140
orbNode.position = orbNodePosition
orbNode.physicsBody = SKPhysicsBody(circleOfRadius:
orbNode.size.width / 2)
orbNode.physicsBody!.dynamic = false
orbNode.physicsBody!.categoryBitMask
= CollisionCategoryPowerUpOrbs
orbNode.physicsBody!.collisionBitMask = 0
orbNode.name = "POWER_UP_ORB"
foregroundNode!.addChild(orbNode)
}
Search WWH ::




Custom Search