Overlays and Cameras/Viewports

Started by Kara Jo Kalinowski, Yesterday at 08:00:44

Previous topic - Next topic

Kara Jo Kalinowski

One thing on my to do list is to create a tile system.

I have a game with resolution 680x400 with room size 640x360 (360p)

I have the following code:

Code: ags
// room script file

Overlay* myOverlay[170];

function room_Load()
{
  for (int x = 0; x < 17; x++) {
    for (int y = 0; y < 10; y++) {
      myOverlay[y*17+x] = Overlay.CreateRoomGraphical(x*40, y*40, 1);
    }
  }
  Game.Camera.Y = 20;
}

I've also tried just CreateGraphical. I haven't worked with overlays before this. I haven't worked with cameras and viewports before this. So please, if there's a better thing I should be using, feel free to tell me.

There is an extra tile offscreen horizontally and vertically, the thing I am trying to do is create an offset so that the offscreen tiles will be displayed, but doesn't seem to work with overlays. Is there a way to do what I want without manually changing the coords of every overlay?


Crimson Wizard

#1
Quote from: Kara Jo Kalinowski on Yesterday at 08:00:44There is an extra tile offscreen horizontally and vertically, the thing I am trying to do is create an offset so that the offscreen tiles will be displayed, but doesn't seem to work with overlays. Is there a way to do what I want without manually changing the coords of every overlay?

Please elaborate, maybe with screenshots, because I could not understand this part.

Overlays are no different from other objects in regards to how they are displayed in room or inside a camera. In the end engine gathers everything as a single group of sprites (room objects, characters, room overlays, walk-behinds), and camera displays them all as same.

EDIT:
One thing that I might mention is this: in AGS you cannot move camera outside of room bounds.
If you want to have a larger scrolling area inside a small room, then you cannot use camera, but have to move the room contents in opposite direction instead.
If you have a really big map, then don't create overlays for the whole map, but create only a portion, slightly bigger than the observeable area, move these around, changing their graphics dynamically. As overlay leaves an area, "teleport" it to the opposite side.
Well, there is more here, but I'd like to know more details about the system you are trying to create first.

Kara Jo Kalinowski

In retro game systems, tiles are stored in memory with an extra tile offscreen. This would be an offset of 0,0



You would move the offset of the blue box to display additional tiles. When you reach the edge of the additional tile (i.e. x = 40 or x = -1), you'd shift all the tiles to the left/right by 1, load an additional columns worth of tiles, and move the blue box offset back to x = 0, if that makes sense? Same for vertical (y = 40 or y = -1) Doing that lets you have rooms much larger than the visible screen but only storing what's immediately accessible in memory.

It's the system we used in my GBA programming class and well although the GBA has dedicated hardware for the tiles, I wanted to simulate it using software.

The problem I am having is that Game.Camera.Y = 20; doesn't seem to be affecting the offset's position on the screen as expected.



When I'd expect the visible window to be showing what's off screen



Specifically I am asking what about overlays and cameras/viewports that I'm not understanding, and how to fix. Thanks :)

Quote from: Crimson Wizard on Yesterday at 08:56:59
Quote from: Kara Jo Kalinowski on Yesterday at 08:00:44There is an extra tile offscreen horizontally and vertically, the thing I am trying to do is create an offset so that the offscreen tiles will be displayed, but doesn't seem to work with overlays. Is there a way to do what I want without manually changing the coords of every overlay?

Please elaborate, maybe with screenshots, because I could not understand this part.

Overlays are no different from other objects in regards to how they are displayed in room or inside a camera. In the end engine gathers everything as a single group of sprites (room objects, characters, room overlays, walk-behinds), and camera displays them all as same.

EDIT:
One thing that I might mention is this: in AGS you cannot move camera outside of room bounds.
If you want to have a larger scrolling area inside a small room, then you cannot use camera, but have to move the room contents in opposite direction instead.
If you have a really big map, then don't create overlays for the whole map, but create only a portion, slightly bigger than the observeable area, move these around, changing their graphics dynamically. As overlay leaves an area, "teleport" it to the opposite side.
Well, there is more here, but I'd like to know more details about the system you are trying to create first.

Khris

#3
The command fails because the camera rectangle cannot leave the room rectangle. With your approach you would have to use a room background as big as the tilemap.

However you don't really need Game.Camera offsets for this. Use a room as big as the screen, store your own offset variables and draw the visible tiles at an offset, directly to the room background (using DrawingSurface functions).

Kara Jo Kalinowski

Quote from: Khris on Yesterday at 14:09:57The command fails because the camera rectangle cannot leave the room rectangle. With your approach you would have to use a room background as big as the tilemap.

However you don't really need Game.Camera offsets for this. Use a room as big as the screen, store your own offset variables and draw the visible tiles at an offset, directly to the room background (using DrawingSurface functions).

We solved this on discord - the problem I was having was that I assumed that setting the edges of the room would affect the room size, and it was the imported background image that determines the room size. (Previously the room did not have an image other than the default blank image.) Once I added in my background image, all works good :)

Did a quick test, and it scrolls as it should.

Code: ags
// room script file

Overlay* myOverlay[170];

function room_Load()
{
  for (int x = 0; x < 17; x++) {
    for (int y = 0; y < 10; y++) {
      myOverlay[y*17+x] = Overlay.CreateRoomGraphical(x*40, y*40, 1);
    }
  }
}


function room_RepExec()
{
  Game.Camera.X += 3;
  Game.Camera.Y += 1;
  
  while (Game.Camera.X >= 40) {
    Game.Camera.X -= 40;
  }
  while (Game.Camera.Y >= 40) {
    Game.Camera.Y -= 40;
  }
}

SMF spam blocked by CleanTalk