Pir Jacques
Member
So... I seriously, desperately need help with this thing. I wanted to try and figure this out on my own, to not have to bother you all about it... to no avail. It's been weeks since I tried to implement this stupid thing, and I still can't figure it out. So... nya.
What I'm trying to do: I am trying to create a camera system for my game. It's a top-down camera, and it's pretty standard in that it follows the player around the room, but it has one unique quirk: it should not, under any circumstances, scale up the display. Ever. However, I want the player to be able to resize the window as they please, so what I'm aiming for is, as you change the window's size, you simply see more or less of the room, with the camera's size exactly equaling the window size. Finally, the camera should always stay centered on the protagonist, and when the window is larger than the current room, the room should be centered on the screen.
What's the problem?: When the window is equal to or larger than the size of the room, everything works just fine: the room centers in the window with no scaling. Everything's good there. But as soon as I set the window to be smaller than the room, we get scaling: sprites and tiles stretch whichever way you moved the window. That is a no-no, and it's the issue I've been stuck on all this time.
What I've got: After studying the documentation, and the aforementioned weeks of trial and error, I have this prototype that I've been using, with all of these codes being executed from the same persistent object:
The Post-Draw event:
I have disable the normal drawing of the application surface, and am instead drawing it to my own specifications with this code. This code serves two purposes: to keep the view centered on the screen, and to prevent the display from scaling. It does both of these jobs correctly, as far as I can tell.
The Game Start event:
This code does two things. The first is it stores the camera used throughout the entire game into its respective global variable. A few notable values: the width of 448 and height of 354 match the width and height of the first room, and while these sizes get changed as soon as the player resizes the window, these initial sets ensure that the pixel-perfect scale stays intact. The second code is the aforementioned disabling of the default application surface drawing.
The Room Start event:
Fairly simple: this code assigns the previously set camera to viewport 0 at the beginning of every room.
The Step Event:
This is the flagship event for this system, with the most actions, so let me break them all down:
The first block is the camera size setting block. It checks which is smaller: the room or the window, and stores the value of the smaller into camWidth and camHeight, respectively, before using those two to set the camera size. The check is crucial to the system, as it lets the camera function two ways: if the window is smaller than the room, it shows only a portion of the room matching the window size, while if the window is larger than the room, it keeps the camera the same size as the room, so as to let the application surface drawing centre the room properly.
The second block is fairly simple: it sets the viewport to the same size as the camera. If the viewport is any other size, scaling would occur, and we do not want that.
The third block is also fairly simple: it simply sets the "view border" to half the window size all four ways. This is what lets the camera center on the protagonist.
A few more notes: Yes, I have enabled the use of Views in each and every room in the game [only two, at the moment], and yes, I have set their default sizes in each and every room to the size of the room to prevent scaling. What I have given you is indeed every single code related to this camera system, I am sure of it.
Any help you all can give is very much appreciated, more than you know... And thank you in advance for your time and patience!
-Pir
What I'm trying to do: I am trying to create a camera system for my game. It's a top-down camera, and it's pretty standard in that it follows the player around the room, but it has one unique quirk: it should not, under any circumstances, scale up the display. Ever. However, I want the player to be able to resize the window as they please, so what I'm aiming for is, as you change the window's size, you simply see more or less of the room, with the camera's size exactly equaling the window size. Finally, the camera should always stay centered on the protagonist, and when the window is larger than the current room, the room should be centered on the screen.
What's the problem?: When the window is equal to or larger than the size of the room, everything works just fine: the room centers in the window with no scaling. Everything's good there. But as soon as I set the window to be smaller than the room, we get scaling: sprites and tiles stretch whichever way you moved the window. That is a no-no, and it's the issue I've been stuck on all this time.
What I've got: After studying the documentation, and the aforementioned weeks of trial and error, I have this prototype that I've been using, with all of these codes being executed from the same persistent object:
The Post-Draw event:
Code:
draw_surface_ext (application_surface, (window_get_width() /2) - (camera_get_view_width(0) /2), (window_get_height() /2) - (camera_get_view_height(0) /2), 1, 1, 0, c_white, 1)
The Game Start event:
Code:
global.thisIsTheOnlyCamera = camera_create_view (0, 0, 448, 354, 0, obj_protag, -1, -1, ((window_get_width() /2) -16), ((window_get_height() /2) -16))
application_surface_draw_enable (false)
The Room Start event:
Code:
view_camera[0] = global.thisIsTheOnlyCamera
The Step Event:
Code:
//Set camera width/height to the room's width/height or the window's width/height, whichever is smaller
if window_get_width() < room_width {camWidth = window_get_width()}
else {camWidth = room_width}
if window_get_height() < room_height {camHeight = window_get_height()}
else {camHeight = room_height}
camera_set_view_size (view_camera[0], camWidth, camHeight)
//Set viewport width/height to the room's width/height
view_set_wport(0, camWidth)
view_set_hport(0, camHeight)
//Set camera buffer
camera_set_view_border (view_camera[0], window_get_width() /2, window_get_height() /2)
The first block is the camera size setting block. It checks which is smaller: the room or the window, and stores the value of the smaller into camWidth and camHeight, respectively, before using those two to set the camera size. The check is crucial to the system, as it lets the camera function two ways: if the window is smaller than the room, it shows only a portion of the room matching the window size, while if the window is larger than the room, it keeps the camera the same size as the room, so as to let the application surface drawing centre the room properly.
The second block is fairly simple: it sets the viewport to the same size as the camera. If the viewport is any other size, scaling would occur, and we do not want that.
The third block is also fairly simple: it simply sets the "view border" to half the window size all four ways. This is what lets the camera center on the protagonist.
A few more notes: Yes, I have enabled the use of Views in each and every room in the game [only two, at the moment], and yes, I have set their default sizes in each and every room to the size of the room to prevent scaling. What I have given you is indeed every single code related to this camera system, I am sure of it.
Any help you all can give is very much appreciated, more than you know... And thank you in advance for your time and patience!
-Pir