Here is the situation. I have a class for simulating sun that moves on the sky starting from (0, 0, 0) and ending on (0, -180, 0) (going upward and then down). Sun is the directional light. When I press space bar, it pauses, and if I press again, resumes. This is done by an interval that is included into sequence (I will need to add more intervals later).
The problem is that always after I pause the sequence and then resume it, the interval starts from (0, 0, 0), not from previous position.
class Lights():
def __init__(self):
self.setDirectionalL()
self.updateLights()
def setDirectionalL(self):
self.sun = DirectionalL()
def updateLights(self):
taskMgr.add(self.sun.updateDirectionalL,
"updateSunTask")
class DirectionalL():
def __init__(self):
self.sunLight = DirectionalLight("sun")
self.sunLight.setColor(Vec4(0.8, 0.8, 0.8, 1))
self.sunNP = render.attachNewNode(self.sunLight)
render.setLight(self.sunNP)
self.sunNP.setHpr(0, 0, 0)
self.sunIsMoving = False
self.sunI1 = self.sunNP.hprInterval(2.0,
Vec3(0, -180, 0))
self.sequence1 = Sequence(self.sunI1)
def updateDirectionalL(self, task):
if controls.keyMap["toggleSun"]:
if self.sunIsMoving:
self.sunIsMoving = False
self.sequence1.pause()
else:
self.sunIsMoving = True
self.sequence1.loop()
print "Is Interval playing according to game logic?", self.sunIsMoving
print "Current Directional Light Hpr:", self.sunNP.getHpr()
print "Is Interval actually playing accoring to Panda?", self.sequence1.isPlaying()
print
return Task.cont
I tried to change “loop()” to “resume()” (and later to “start()”) but then it plays only once, without looping. I also tried many versions of code “finish()” instead of “pause()”.
I also tried to save the Hpr values before “pause()” or “finish()”, and then calling “self.sunNP.setHpr()” before “loop()” but without success.
If I use “startT” parameter with “loop()” then it only loops from startT, and skips the beginning. For this day I have also tried numerous combinations of the above.
Gentlemen, please, what to do?
If you are interested what the print statements print, here is one example:
Is Interval playing according to game logic? False
Current Directional Light Hpr: VBase3(0, -87.48, 0)
Is Interval actually playing accoring to Panda? 0
Is Interval playing according to game logic? False
Current Directional Light Hpr: VBase3(0, -87.48, 0)
Is Interval actually playing accoring to Panda? 0
Is Interval playing according to game logic? True
Current Directional Light Hpr: VBase3(0, -87.48, 0)
Is Interval actually playing accoring to Panda? 1
Is Interval playing according to game logic? True
Current Directional Light Hpr: VBase3(0, 0, 0)
Is Interval actually playing accoring to Panda? 1
Is Interval playing according to game logic? True
Current Directional Light Hpr: VBase3(0, -0.36, 0)
Is Interval actually playing accoring to Panda? 1
Is Interval playing according to game logic? True
Current Directional Light Hpr: VBase3(0, -0.9, 0)
Is Interval actually playing accoring to Panda? 1