Game Development Reference
In-Depth Information
The one item you now need to add is the enemy node, which is created just like the space-
men node. Open the GameViewController class and create a variable for the en-
emyNode right after spacemanNode : var enemyNode: SCNNode .
You will follow the same pattern as the spacemanNode , so now you need to create an
SCNNode to assign to this class-level variable. In the createMainScene() method,
you will call the setupEnemy() method, enemyNode
= setupEnemy(mainScene) . You will create this method next, so don't worry
about the error at this time.
It is now time to get rid of that error about a missing method. Right after your
setupSpaceMan() , you will create the new setupEnemy() , as Listing 14-5 shows.
Listing 14-5 . setupEnemy( )
func setupEnemy(scene:SCNScene) -> SCNNode {
var enemyScene = SCNScene(named: "art.scnassets/
Enemy.dae")
var enemyNode
= enemyScene!.rootNode.childNodeWithName("enemy",
recursively: false)
enemyNode!.name = "enemy"
enemyNode!.position = SCNVector3(x: 40, y: 10, z: 30)
enemyNode!.rotation = SCNVector4(x: 0, y: 1, z: 0, w:
Float(M_PI))
scene.rootNode.addChildNode(enemyNode!)
return enemyNode!
}
Now you have the enemy out in the playing floor, so you can dive into the collision detec-
tion of the various items.
Collision Detection
Now that you have the hero moving around an assortment of moving objects, you need to
determine when your hero runs into something.
Search WWH ::




Custom Search