2016-10-19 73 views
2

下面的代碼不符合我的預期。如果用戶按下「w」鍵,我希望它向北行進。演員,熊貓確實第一次顯示沒有完成動畫的動作,停止動作並且再也不會動起來。我錯誤地使用了引擎嗎?或者我應該使用別的東西來實現我的目的嗎?如何在panda3d的間隔後停止動畫?

from direct.showbase.ShowBase import ShowBase 
from direct.actor.Actor import Actor 
from panda3d.core import Point3 
from direct.interval.IntervalGlobal import* 
class Window(ShowBase): 
    def __init__(self): 
     ShowBase.__init__(self) 
    def loadModels(self): 
     self.envir = loader.loadModel("models/environment") 
     self.envir.reparentTo(self.render) 
     self.envir.setY(1183.37) 
     self.envir.setHpr(0, 8, 0) 
     self.panda = Actor("models/panda-model", {"idle": "models/panda-model", "walk": "models/panda-walk4"}) 
     self.pandaPosY = 502 
     self.pandaPosX = 0 
     self.pandaPosZ = -102.66 
     self.panda.setScale(0.05, 0.05, 0.05) 
     self.panda.setY(502) 
     self.panda.setZ(-102.66) 
     self.panda.setHpr(180, 0, 0) 
     self.accept("w", self.MoveForward) 
     self.panda.reparentTo(self.render) 
    def MoveForward(self): 
     pandaForwardWalk = self.panda.posInterval(2, Point3(self.pandaPosX, self.pandaPosY + 50, self.pandaPosZ), startPos = Point3(self.pandaPosX, self.pandaPosY, self.pandaPosZ)) 
     self.panda.play("walk") 
     self.pandaForwardWalk = Sequence(pandaForwardWalk, name="pandaForwardWalk") 
game = Window() 
game.loadModels() 
game.run() 

回答