Is there a way to set the rooms position on the screen?

Started by Gal Shemesh, Sun 18/06/2023 14:44:03

Previous topic - Next topic

Gal Shemesh

Hi everyone,

I was trying to find this one out in the manual and online, but didn't find anything that matches my issue. If it was discussed somewhere in the forum please kindly direct me to the appropriate thread:

I'm looking for a way to be able to position smaller rooms than the gameplay resolution on the X and Y axis. For example, a gameplay in a 320x200 resolution and backgrounds in 320x190 (10 pixels short, like in Sierra's "King's Quest VI"). Currently when I import for example a 320x190 background it sticks to the top left corner of the screen, leaving me with a black bar of 320x10 pixels at the bottom of my background. I wish to have this "black space" ABOVE my background and not below it, so I'm looking for a way to position my rooms's at 0 on the X axis and at 11 on the Y axis. Is there a way to achieve this?

The above is just one example. I can think of other examples this may be useful. For example, when you want to have much smaller rooms than the game resolution, such as a room that takes only 30% of the screen, and you wish to have the freedom positioning that room around the rest 70% area within the engine if you changed your mind on the initial position that you set it up, and so the room will move with all its pre-defined properties you worked hard to set up; such as Edges, Characters, Objects, Hot Spots, Walkable Areas, Walk-behinds and Regions.

Attached below screenshots from the original "King's Quest VI" and its currently equivelant appearance in AGS.

Thanks!



Gal Shemesh,
goldeng

Crimson Wizard

#1
Hello.
Yes, since AGS 3.5.0 you may freely set room position on screen using Viewports. Screen.Viewport is a primary viewport.

For example
Code: ags
Screen.Viewport.SetPosition((Screen.Width - Room.Width) / 2, (Screen.Height - Room.Height) / 2, Room.Width, Room.Height);

Will center current room in the screen.

You probably should do this in "on_event" function, on "eEventEnterRoomBeforeFadein" event, - then this will be performed each time a next room is loaded.

IMPORTANT
AGS automatically handles coordinate conversions (such as offsets) when using functions accepting screen coordinates like Room.ProcessClick or Character.GetAtScreenXY, and so forth, so you don't have to worry about that.
But if you're using functions that accept room coordinates and want to pass screen coords there (or vice versa),  then you should take offsets into account, or use Screen.ScreenToRoomPoint and Screen.ScreenToRoomPoint functions respectively. Same is true for scrolling rooms case.

For example:
Code: ags
// will work fine, AGS converts mouse coords to room automatically
Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);

Code: ags
// Imagine you want to move character to the cursor pos
Point* room_pt = Screen.ScreenToRoomPoint(mouse.x, mouse.y);
player.x = room_pt.x;
player.y = room_pt.y;

Related articles in the manual:
https://adventuregamestudio.github.io/ags-manual/Screen.html
https://adventuregamestudio.github.io/ags-manual/Viewport.html
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event

Gal Shemesh

Quote from: Crimson Wizard on Sun 18/06/2023 14:52:36Hello.
Yes, since AGS 3.5.0 you may freely set room position on screen using Viewports. Screen.Viewport is a primary viewport.

For example
Code: ags
Screen.Viewport.SetPosition((Screen.Width - Room.Width) / 2, (Screen.Height - Room.Height) / 2, Room.Width, Room.Height);

Will center current room in the screen.

You probably should do this in "on_event" function, on "eEventEnterRoomBeforeFadein" event, - then this will be performed each time a next room is loaded.

IMPORTANT
AGS automatically handles coordinate conversions (such as offsets) when using functions accepting screen coordinates like Room.ProcessClick or Character.GetAtScreenXY, and so forth, so you don't have to worry about that.
But if you're using functions that accept room coordinates and want to pass screen coords there (or vice versa),  then you should take offsets into account, or use Screen.ScreenToRoomPoint and Screen.ScreenToRoomPoint functions respectively. Same is true for scrolling rooms case.

For example:
Code: ags
// will work fine, AGS converts mouse coords to room automatically
Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);

Code: ags
// Imagine you want to move character to the cursor pos
Point* room_pt = Screen.ScreenToRoomPoint(mouse.x, mouse.y);
player.x = room_pt.x;
player.y = room_pt.y;

Related articles in the manual:
https://adventuregamestudio.github.io/ags-manual/Screen.html
https://adventuregamestudio.github.io/ags-manual/Viewport.html
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_event

Thank you so much! :)
Gal Shemesh,
goldeng

Snarky

I think it's worth pointing out that in the example shown, the easiest solution is to pad out the background with a black bar on top so that it's 320x200.

Crimson Wizard

Quote from: Snarky on Sun 18/06/2023 20:07:04I think it's worth pointing out that in the example shown, the easiest solution is to pad out the background with a black bar on top so that it's 320x200.

How is that easiest, compared with few lines in script?
(The easiest imo would be if AGS let you configure this in the editor)

Gal Shemesh

@Snarky
The main idea is to NOT include irrelevent things in the background, just to save the "trouble" of adding a line of code. So @Crimson Wizard's solution is exactly what I was looking for.

The example with the 10 pixels black bar was just a basic example, so one may think "hey, just add that line to every background you have'. It gets much more complicated though if say you have plenty of 'portion of rooms' which are much smaller and in various sizes than your actual game resolution. If you put these 'portion of rooms' on black backgrounds that fills the entire screen and you think later "hey, I wish I'd put that 'portion of a room' a little more to the left/right/up/down on the black background, then you won't only have to re-edit your artwork but also to manipulate the entire room properties and settings that I mentioned above. So being able to move around a 'portion of a room' in code is the best way to doing it. I wish of course that positioning of a room could have been done from within the room's properties panel by X and Y settings rather than doing it in code. But until it's implemented (if at all), doing it in code works for me just fine.

I followed @Crimson Wizard advice and put the line of code "Screen.Viewport.SetPosition(0, 11, Room.Width, Room.Height)" within a "room_Load()" function in the global script and it works for all rooms. :)
Gal Shemesh,
goldeng

SMF spam blocked by CleanTalk