Game Development Reference
In-Depth Information
Lighting affects only moving objects in your scene.
Scene Kit uses only up to eight light sources per node, so making more than
this will be a waste. In fact, Apple recommends using no more than three
lighting effects and a single ambient light.
I'm sure you are ready to jump into some code. So, for SuperSpaceMan, you will create a
nice ambient light for the scene, and you will create a spotlight so he is never in the dark.
To make things easy for you, you will control all the lighting in the GameViewCon-
troller for now. If you don't have the GameViewController open, open it up, and
you will need to create a new class variable for the spotlight. At the top of the class, go
ahead and create your new variable: var spotLight: SCNNode! . After you have
created this variable, you can now create the setupLighting() method, as in Listing
12-1 .
Listing 12-1 . setupLighting( ) Method
func setupLighting(scene:SCNScene) {
var ambientLight = SCNNode()
ambientLight.light = SCNLight()
ambientLight.light!.type = SCNLightTypeAmbient
ambientLight.light!.color = UIColor(white: 0.3, alpha:
1.0)
scene.rootNode.addChildNode(ambientLight)
var lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeSpot
lightNode.light!.castsShadow = true
lightNode.light!.color = UIColor(white: 0.8, alpha: 1.0)
lightNode.position = SCNVector3Make(0, 80, 30)
lightNode.rotation = SCNVector4Make(1, 0, 0,
Float(-M_PI/2.8))
lightNode.light!.spotInnerAngle = 0
lightNode.light!.spotOuterAngle = 50
lightNode.light!.shadowColor = UIColor.blackColor()
lightNode.light!.zFar = 500
lightNode.light!.zNear = 50
scene.rootNode.addChildNode(lightNode)
spotLight = lightNode
Search WWH ::




Custom Search