質問

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.

役に立ちましたか?

解決

You should remove one indent in front of return Task.cont. Otherwise, the task will only continue as long as the mouse cursor is in the window; as soon as it leaves the window, hasMouse() will return False and the task will stop running.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top