Unwanted scene movement

I just found out that when I press mouse left button and move the cursor all scenes move along.
Only the background remains in place.
I don’t know what is wrong here. It is not in my code, I removed all mouse references so maybe it is in the editor settings? In the behaviour of mouse cursor of ImageBackground?

Now I removed Mouse(TCastleScene) from the Scene list in the editor but it does not make any difference.

I don’t think I can say much without seeing the code, but my guess would be that for some reason the mouse input affects Viewport instead of Mouse. Check which component is “found by name” (e.g. using DesignedComponent in Start). Maybe something overwrites the variable later?

Yes, left clicking the mouse button, holding it down and then moving it causes the viewport to move over the background image, even when there is no visible cursor.

This is my Start code:

procedure TStatePlay.Start;
 I: integer;
    TransformOwner := TComponent.Create(nil);
    DesignUrl := 'castle-data:/gamestateplay.castle-user-interface';
    ImageBackground := DesignedComponent ('ImageBackground') as TCastleImageControl;
    BackPlane1 := DesignedComponent ('Plane1') as TCastlePlane;
    FrontPlane := DesignedComponent ('Plane2') as TCastlePlane;
    LeftPlane := DesignedComponent ('Plane3') as TCastlePlane;
    RightPlane := DesignedComponent ('Plane4') as TCastlePlane;
    Plane5 := DesignedComponent ('Plane5') as TCastlePlane;
    BackPlane2 := DesignedComponent ('Plane6') as TCastlePlane;

    Viewport := DesignedComponent ('Viewport') as TCastleViewport;
    LocationOwner := TComponent.Create(FreeAtStop);
    ImageBackground.Cursor:= mcNone;

I have removed almost every code but the dragging is still there. I am pretty sure it is not in the code but in the editor settings.

You have Navigation2D1:TCastle2DNavigation in the scene. The very purpose of this component is that it allows the user to move the camera (so, everything within the Viewport moves) by dragging with left mouse button. There’s also zoom with mouse wheel :slight_smile:

Just remove the Navigation2D1:TCastle2DNavigation component. You can select viewport and click on the “hamburger menu button” at the top bar and choose “Change Navigation → None (Viewport.Navigation := nil)”.

Note that right now the same navigation method is both used in editor (at design-time) and it is exposed to users at runtime. I know this can get confusing. I’m working now on a rework of cameras to separate these two, so this will get less confusing, you will have separate navigation methods as runtime and design-time.

1 Like

Ah! Thanks.
I never found out the zoom with mouse wheel by accident either, but indeed it does.
I removed the Castle2DNavigation and everything is okay now. Another problem solved.

1 Like