0

I a pretty new to panda3d, and I came across a problem that I have no idea how to fix. I am trying to control the camera using the cursor's location, but every time it the cursor leaves the application window, and reenters it the program stops recording the cursor's position. Is this a task problem? I put the function's that receive the cursor position and control the camera into taskmgr. That section of my code is below.

    taskMgr.add(self.get_mousepos, 'getmouse')
    taskMgr.add(self.move_camera, 'movecam')


    def get_mousepos(self,task):
        if base.mouseWatcherNode.hasMouse():
            self.camerax=base.mouseWatcherNode.getMouseX()
            self.cameray=base.mouseWatcherNode.getMouseY()
            return Task.cont

    def move_camera(self,task):
        if self.camerax>=.6:
            self.camh-=.8
            camera.setHpr(self.camh,self.camh1 ,0)
        elif self.camerax<=-.6:
            self.camh+=.8
            camera.setHpr(self.camh,self.camh1 ,0)
        elif self.cameray>=.6:
            self.camh1+=.8
            camera.setHpr(self.camh,self.camh1 ,0)
        elif self.cameray<=-.6:
            self.camh1-=.8
            camera.setHpr(self.camh,self.camh1 ,0)
        return Task.cont

Thanks in advance.

4

1 回答 1

0

您应该删除 . 前面的一个缩进return Task.cont。否则,只要鼠标光标在窗口中,任务就会继续;一旦它离开窗口,hasMouse()就会返回False并且任务将停止运行。

于 2013-04-28T08:43:28.747 回答