ShowBase window tends to reset its position when trying to grab it

Hey,
I tried implementing a 3rd person camera for my application but it seems to produce some issues with the window properties. In the inherited class of ShowBase I add a task via self.taskMgr.add(self.OrbitCameraTask, 'thirdPersonCameraTask')

where OrbitCameraTask is:

def OrbitCameraTask(self,task):
        md = self.win.getPointer(0)
        if base.mouseWatcherNode.isButtonDown(MouseButton.one()):
            self.props.setCursorHidden(True)
            self.win.requestProperties(self.props)
            x = md.getX()
            y = md.getY()
            if self.win.movePointer(0, int(self.x_mouse_position), int(self.y_mouse_position)):
                self.heading = self.heading - (x - self.x_mouse_position) * 0.5
                self.pitch = self.pitch - (y - self.y_mouse_position) * 0.5
            if self.pitch > 90:
                self.pitch = 90
            elif self.pitch <-90:
                self.pitch = -90
            self.parentnode.setHpr(self.heading, self.pitch,0)
        else:
            self.props.setCursorHidden(False)
            self.win.requestProperties(self.props)
            self.x_mouse_position = md.getX()
            self.y_mouse_position = md.getY()
        return task.cont

When i dont bind the task, I can move the window without any problem, but adding the task resets the window to the original position, when i try to move it.

‘self.props’ is :

self.props = WindowProperties()
self.props.setOrigin(100, 100)
self.props.setSize(int(self.canvas_width), int(self.canvas_height))
self.setBackgroundColor(0,0,0)

Edit:
I think this behaiviour comes from setting the window properties from self.props, right? What would be the right way to hide and show the cursor in this case?

Yeah. You are reseting windows location and size every time.
You need to request a single cursor visibility option only:

properties = WindowProperties()
properties.set_cursor_hidden(True)
#properties.set_cursor_hidden(False)
self.win.request_properties(properties)  # request cursor option changes
1 Like