To get a feel for lights, let's go ahead and throw some into our game!
Open up the
TrackClass_00.py
file in theChapter07
folder.We'll start with a new method that will create two lights for us and assign them to illuminate the entire scene. Add this method to the bottom of the
Track
class:def setupLight(self): primeL = DirectionalLight("prime") primeL.setColor(VBase4(.6,.6,.6,1)) self.light = render.attachNewNode(primeL) self.light.setHpr(45,-60,0) render.setLight(self.light) ambL = AmbientLight("amb") ambL.setColor(VBase4(.2,.2,.2,1)) self.ambLight = render.attachNewNode(ambL) render.setLight(self.ambLight) return
Of course, we need to call that new method in order for it to do anything. Add this line of code to the bottom of the
__init__
method:self.setupLight()
Resave the file as
TrackClass_01.py
.Since our cycles have components that glow on the bottom, it makes more sense for them to cast...