Mouse Coordinates in a scrolling room - AGS 3.6.1

Started by Cmdr, Mon 11/11/2024 21:35:00

Previous topic - Next topic

Cmdr

I have the exact same problem as this guy:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/problem-with-mouse-coordinates-in-a-scrolling-room/

I need to get my mouse coordinates, but not of the current viewport, but the global coordinates of the scrolling room. The given solution is simple and can be found on many threads in this forum.

But the funny thing is...
It doesn't work with AGS 3.6.1 anymore  :grin:

So what is the current equivalent of GetViewportX()?
I tried Screen.Viewport.X, but this seems to be always 0, no matter how much the screen scrolled over the room.


Cmdr

Thank you for your reply.
I found a solution with Viewport.ScreenToRoomPoint:
QuotePoint* pt = Screen.Viewport.ScreenToRoomPoint(mouse.x, mouse.y, true);
    if (pt != null) {
       DoThings(pt.x, pt.y);
    }

eri0o

https://adventuregamestudio.github.io/ags-manual/Screen.html#screenscreentoroompoint

Screen directly has a ScreenToRoomPoint which you should use. Note AGS supports multiple cameras and multiple viewports - for something like split screen and similar.

I think your approach only works if the viewport is only one and it covers the entire screen.

Crimson Wizard

#4
Quote from: Cmdr on Mon 11/11/2024 21:51:12I found a solution with Viewport.ScreenToRoomPoint:

Oh right, that's a more generic way of doing this.

You can also keep the old way by adding Game.Camera.X (instead of GetViewportX).
ScreenToRoomPoint has a benefit that it also handles scaling (if you zoom camera in or out).

Please note that if you do not pass "true" to the last argument (restrictToViewport or clipViewport, depending on a function), then you dont have to test the return value for null, as if the coordinates are never "clipped by viewport", and returned Point is always valid.

SMF spam blocked by CleanTalk