• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] How the hell do you do pixel perfect scaling in GMS2? :'D

Yeah, I'm a scrub, sorry. Anyway, here's what's up: back in GMS1, you could just set the window size of your game to be an integer multiple of your view size, and it'd scale up perfectly fine. I'm trying that in GMS2, and the camera seems like it's vibrating at certain movement speeds, which looks awful, and my character isn't even sticking to the pixel grid, as shown here:



Very gross! I'm just setting my camera and viewport properties in the room editor, like so:


Apparently that doesn't work anymore, because of the new camera system? Pixel interpolation is off. How do I scale my game normally, preferably without diving into GMS2's pain-in-the-ass new camera system? I just want a cheap camera to follow my character around without destroying my pixel grid, hahah! :')


EDIT: SOLUTION HERE - https://forum.yoyogames.com/index.php?threads/how-do-i-avoid-subpixel-rendering.49651/ Last post in the thread. After doing that, you can set your cameras and views in the room editor like you used to in GMS1.
 
Last edited:

Neptune

Member
This is a good go-to for the math of it -- essentially scale your game at any whole value multiplied by the native, so if 480x270 is the native you can scale to 960x540, 1440x810 and 1920x1080 ... and so on.
https://forum.yoyogames.com/index.php?threads/how-to-properly-scale-your-game.995/

And you camera code can be as simple as this in GMS2:
Code:
var xx = o_player.x-240; // where 240 is half camera width
var yy = o_player.y-135;// where 135 is half camera height
camera_set_view_pos(view_camera[0],xx,yy);
You may want to round the x,y coords to avoid jitters too.
 
@Vether: Is that code any different than what I'm doing here in the room editor? It looks like it should work out the same, no? I'm probably misunderstanding how cameras work in GMS2...how would the code above keep my character locked to the pixel grid, when the room editor settings don't? :x

Edit: Yeah, that fixed the camera jitter, but objects are still allowed to slide off the pixel grid. =(
 

HayManMarc

Member
In my experience, I've had problems trying to set room/view things with the editor. I set the room size in the editor, and that's it. I set everything else thru code in a dedicated camera object. (FWIW)
 

Neptune

Member
I think i'm not understanding what you mean by pixel grid.

[EDIT]
If you're wanting to move the player at sub-pixels speeds, then you can't without camera jitters.
Unless you post-draw them after your application surface has already been rendered scaled up... which then will probably cause a bunch more nightmares with position and depth sorting.

Thats my thought anyway... I havnt been able to move the player at sub-pixel speeds, while also having the camera locked to player's XY smoothly.
 
Last edited:
@HayManMarc: Is your camera pixel perfect? Or are you getting weird half pixels, too? If your camera is pixel perfect, mind sharing code or where you learned it? I tried using some code I found too, but it didn't fix anything, which is why I went back to trying the room editor way. GMS1 worked fine just setting it in the room editor, though! =(

The code for my camera object, which works exactly the same (wrong) way as just setting it in the room edit:

Room start:
Code:
myCamera = camera_create_view(0, 0, 246, 224, 0, -1, -1, -1, -1, -1);
view_camera[0] = myCamera;
view_visible[0] = true;
view_enabled = true;

viewWidth = camera_get_view_width(myCamera);
viewHeight = camera_get_view_height(myCamera);
Create:
Code:
globalvar myCamera;
globalvar viewWidth;
globalvar viewHeight;

hBorder = 200;
vBorder = 100;

Border = 250;
End Step:
Code:
camera_set_view_pos(myCamera, (obj_Player.x) - (viewWidth/2), obj_Player.y - viewHeight/2);
@Vether: Here's a close up of the picture above:


The blue pixels are normal, square pixels upscaled correctly. Notice how the pixel circled and highlighted in red is "cut in half," because the character is allowed to move less than a pixel on the screen, because of the weird way GMS2 is scaling the screen. It's basically using pixel interpolation or something, even though I have it turned off, and it looks awful. :x
 

Neptune

Member
The link i posted in my previous comment has everything you need to have pixel perfect scaling. Ranger's tutorial is very thorough.
 
@Vether: He made that tutorial back when GMS1 was out....it's for handling changing resolutions perfectly no matter what full screen size you're in and stuff. I never needed it during GMS1, though. Also, even if the game isn't pixel perfect, it's very strange to me that objects are falling off the pixel grid...

Whatever Ranger is doing for scaling his game makes my computer slow to a crawl, too, which is weird. I dunno. I'll look through his tutorial, but I don't know if it'll solve my problem. It doesn't seem like it explains what the hell's up with GMS2's cameras, since it was primarily a GMS1 tutorial. Thanks for the link, though!

That said, if anyone has any more advice, I'm happy to hear it!

Edit: Alright, found the solution to avoid GMS2's 💩💩💩💩ty default subpixel rendering - last post in the thread: https://forum.yoyogames.com/index.php?threads/how-do-i-avoid-subpixel-rendering.49651/

Thanks for the advice, guys! Marking this solved! =)
 
Last edited:

HayManMarc

Member
If your movement speed is a decimal amount, you'll get that off-pixel anomaly because GM can make it work when it's upscaled (if you can understand my bad explaining).

(Give me a few... I just got home from work. I'll take a closer look, unless someone else figures it out first.)
 

Pfap

Member
Hmmm, I'm not an expert on cameras or pixel perfect. But I have a cheap camera that follows a character around.
This is what I did:

//camera object create event
Code:
view_camera[0] = camera_create_view(0, 0, 512, 288, 0, player, 5, 5, 200, 200);
//0 for the start  x of the camera
//0 for the start y of the camera
//512 for the width of my camera
//288 for the height of my camera
//0 for the camera angle mine points straight down
//player for the object it follows
//5 for the x speed the camera follows the player at
//5 for the y speed the camera follows the player at
//200 for the x border padding
//200 for the y border padding


view_enabled = true;

view_visible[0] = true;

I have Enable Viewports unchecked in the room editor, but I also have viewport0 set to visible. I'm not sure it is doing anything though, as it shouldn't be enabled.

Edit:
Fixed some of my comments which were wrong.
 
Top