Camera limitation

I made a 2D tabletop-style game. When I assign the camera to the mouse cursor, the camera moves infinitely forward, backward, left, and right. I want to limit the camera’s movement. Another problem is that I have a main layer and a UI layer. I keep the mouse cursor on the main layer because I want the main layer to move, but in this case, the mouse cursor remains under the UI layer and becomes invisible when I move it over them. How can I solve these two problems?

The reason for this is because the camera is positioned in the middle of the screen. The mouse will be positioned somewhere off centre on the screen. When you move the camera to the mouse position, the position the mouse is at becomes the centre of the screen, and the current mouse position is a new position that’s still off centre. This keep going on forever.


This is a bit confusing - the mouse cursor is independent of any layer. It’s on the screen (not scene) and its position can be obtained for each layer.

Do you mean the actual mouse cursor, or are you placing a sprite at the cursor location? Can you provide a screen snip of the cursor events?

So, is there no way to limit the camera?

There are ways to limit the camera, but the method you are using makes it extremely difficult. You’ll need to work out the camera movement mechanic - how do you expect it to work? Do you move the mouse, and then expect it to shift as the camera shifts so the cursor eventually centres on the screen? This would be a bit tricky to implement in GDevelop.

Or do you put in a buffer where the cursor can move up to n pixels from the camera before scrolling starts. Do you then speed up or slow down scrolling depending on how far the cursor is from the camera - the further the faster?