AttributeError:“ Fighter”对象没有属性“ applyRightTurn”

时间:2018-06-29 04:27:51

标签: python-3.x class attributes

我是一名学生,正在尝试为游戏引擎编写按键绑定。我的上一次代码迭代是为模型添加向右转的功能,但遇到了一个我似乎无法解决的问题:

AttributeError:“ Fighter”对象没有属性“ applyRightTurn”

有人会知道我在做什么错吗?

class Fighter(ShowBase, object):
    def __init__(self, modelPath, parentNode, nodeName, posVec, scaleVec=1.0):
        self.modelNode = loader.loadModel(modelPath)
        self.modelNode.reparentTo(parentNode)
        self.modelNode.setName(nodeName)
        self.modelNode.setScale(scaleVec)
        self.modelNode.setPos(posVec)

        self.hud = Hud("./Spaceships/DroneDefender/DroneDefender.x", self.modelNode, "hud", (0, 10, 0))

        self.setKeyBindings()
        self.origin = render.attachNewNode("origin")
        #### Changed selfPos to setPos
        self.origin.setPos(0, 0, 0)

    def setKeyBindings(self):

        self.accept("arrow_right", self.rightTurn, [1])
        self.accept("arrow_right-up", self.rightTurn, [0])



    def rightTurn(self, keyDown):
        if keyDown:
            taskMgr.add(self.applyRightTurn, "right-turn")
        else:
            taskMgr.remove("right-turn")
            self.acceptOnce("arrow_right", self.rightTurn, [1])
            self.acceptOnce("arrow_right-up", self.rightTurn, [0])

    def applyRighttTurn(self, Task):
        rate = 2
        self.modelNode.setH(self.modelNode.getH() + rate)
        return Task.cont

0 个答案:

没有答案