[Update 12/5/24] Hey, are you going through my whole resolution and aspect ratio tutorial series? Or maybe just thinking about it? DON'T My math in my older videos is flawed and will not work for every resolution. Sorry. But, you do not need to support ultra wide monitors in your indie 2D game! Just build your game for 1920x1080 using the advice in the video. Be okay with the black bars on different monitor aspect ratios. If you want to do further correction for non-whole number scaling on various monitors, just use a bi-linear filter shader on the app surface. That's what Sonic Mania does on the Switch and it looks fantastic. Ultimately, if you release your game and people start asking you for widescreen support: congratulations on releasing a game and having some measure of success. NOW you can think about adding in ultrawide support.
I found your series on aspect ratios extremely helpful and happily subscribed to your channel--thank you! I have quick question regarding GMS2. Which script is the most current for GMS2: the script here or the one in pastebin.com (referenced in one of your older videos)? I assume the one here, but just wanted to confirm. Thanks again!
@@realistindenial Everything I personally do with GMS2 cameras is based off of this video (and then I mix in some of the aspect ratio and pixel perfect scaling stuff from the older videos). If you have any more questions, definitely join my Discord server. I or someone else will be able to personally answer any questions you might have. discord.gg/By6u9pC
Following the tutorial I had pixel distortion but because I was working with a very small resolution,240x135 (1920/8 x 1080/8) since my characters are 16x16. When setting up for the camera to follow the player we have "var _y = obj_player.y - view_height/2" at 8:55. Since in my case the view_height==135, my camera "y" coordinate was always in a fraction position. So I just used floor() there("var _y = obj_player.y - floor(view_height/2)"), and whenever I used "view_height/2"and everything is ok :). Also my app surface was the size of the view(very small, 240x135), if I set it to be the size of the game window(6x bigger) it would hide this bug. tl:dr I had pixel distortion because I was accidentally setting up my camera to be in a fractional position, make sure you don't do that =)
Thank you for posting this! The simplified and persistent camera object really helps. I was having trouble letting the user adjust the window size and was led here. I used your simple camera setup and added a 'surface_resize(application_surface,camera_view_width,camera_view_height)' whenever the window changes size, or when the room changes, and it seems to work well so far.
At the time when I start thinking of all of this stuff this video is a best thing I could ever find. Thank you, it would have taken me unthinkable amount of time to figure all this out on my own.
All right, basic setup seems to work, camera follows at the center of my player, all fine, except the sprite of the player moves in totally different speed, not staying in the position of the player. What's up with that? Actually sprite is already drawn in a different location when I start the game, weird. Position should be absolute I think, why is it offset by that much? If I take out the camera code everything works as it should, something makes my sprite drawn in wrong place. EDIT: I found it, I had draw_self() function at draw GUI... which apparently is wrong choice. :D
Thank you so much!! I have watch several other videos on views and non of them explained it well and I was getting frustrated until I found your video, You explain it so well I will be watching more of your videos from now on
THANK YOU! The camera function in gms2 is such a mess to understand for someone like me and I didn't know how to simplify it. It's good to know what I should avoid doing to avoid bad habits. That's a very informative video, you're awesome!
Thanks so much, this was really helpful. Especially with the stuff about how the camera always follows the top left of the player. It was really confusing before, but it was understandable the way you showed it.
for those who cant seem to run the game even though the code is identical! In your End Step event of obj_Camera Do NOT put a ';' behind the line containing "#macro View view_camera[0]"
I would add, with newer version of GM2, placing macros in objects will raise an exception (at least it does in this example). Create a script file and place them all in there and it will then run error free.
was super helpfull I was able to make an infinit room in a fullscreen window (also added some camera movment code myself) much more customizable than the settings in the room editor
Hey, thanks a lot for this, this is exactly what I was looking for. I like to make traditional style games with strict resolutions / pixel grids. By using surface_resize to set the application surface size to the view size it enforces a strict limit. What I had to do before was floor any x and y values that weren't integers before drawing, but this simplifies things. The only downside I've found so far is that I usually print some debug information to screen, but now that's forced to the same resolution limits as well so it takes up a lot more screen space than before. It's also a lot easier to adjust the camera position this way than wrestling with the auto-follow in the room editor.
So, if you output debug information to the gui layer, you can resize the gui layer using display_set_gui_size(), and you can set it to the same size as your window! Then you debug text will be super small and crisp.
@@PixelatedPope hey, thanks! I'll try that. The solution I found was to create a custom font with aa turned off and make it as small as possible. It works and I like the fact that it doesn't break the pixel density, but screen real estate can still be an issue.
What would be the best way of implementing view scaling or 'fov' based off the camera's speed? (ie the faster the camera moves, the wider the fov becomes) I thought about just creating a muliplyer: var _fov = 1 + (point_distance(_x, _y, _cur_x, _cur_y) * .1 Then applying that to the: camera_set_view_size(view, view_width * _fov, view_height * _fov) But as you stated, the view size needs to be established prior to calculating it's coordinates, soooo...
Yeah, changing the size of the view at any time immediately complicates things. I usually operate on a "base" size and scale things off of that. So instead of referencing the current view size to get your view_width and height, you would have a static variable that represents your base size.
@@PixelatedPope Hi again. Thanks for taking the time. I'm getting a strange "overlapping effect" with collisions. If I remove the camera from the room, and test collisions, they appear pixel perfect. I am using subpixel movement, and using this code: // Check for collisions and move player if(place_meeting(x + move_speed, y, obj_solid)) { x = round(x); repeat(ceil(abs(move_speed))) { if(!place_meeting(x + sign(move_speed), y, obj_solid)) x += sign(move_speed); else break; } } else x += move_speed; I snagged this code from a forum, and it seemed to work, up until implementing the camera. Just to clarify. Collisions are functioning normally. It's just the appearance that is off. Side note: I raised the window_scale to 16, as it drastically improved the smoothness of the camera
For some reason my camera does not move slowly towards my player, just stays on it the same it would without the added code. Can't seem to figure out why, triple checked the code but there is always something to miss.
Often this is because something else is moving the camera, likely because you had a different solution in place in the project before implementing this solution. So you have to "undo" everything you had before. This could be a different object moving the camera, or it could be the "object following" setting in the room settings. Or, and this happens a lot, it could be that you position the camera on the player, then calculate the gradual position, and then move the camera again. Make sure you don't have camera_set_view_pos() called twice in your code.
@@PixelatedPope You were right I did the mortal sin of having the camera follow an object and didn't realize. New problem is the camera doesn't start on the player between room transitions. I might just scrap that part of the code tho because it doesn't seem like I honestly need it for my game. Thanks for the response though!
@@cjtodd6244 Hey, where you had this? That camera followed an object? I'm trying to figure out same problem that my camera doesnt move slowly towards player.
4:20 - Just a quick heads-up, from my experience, a Low Res app surface will increase the performance on Low end GPUs (I'm talking about potatoes here, like the GT 710, HD 6450 and APUs). Add an option for the player if possible (Or just scale down if the Frametime is too High).
I see that when you start the game, the view moves from where it is positioned in the room (top right) to where the player is. I haven't tested this but to make the view start right at where the player is when you run the game, adding this code in the ROOM START event should do the job. if instance_exists(o_player) { x = o_player.x; y = o_player.y; }
You would need to duplicate the entire code of the end step event without the lerp and that would do it. view_enabled=true; view_visible[0]=true; if(instance_exists(obj_player)) { var _x = clamp(obj_player.x-view_width/2,0,room_width-view_width); var _y = clamp(obj_player.y-view_height/2,0,room_height-view_height);
var _cur_x = camera_get_view_x(view); var _cur_y = camera_get_view_y(view);
What I meant to say is that I can not get the view to move with the player. The camera_set_view_pos is called and the given x and y are correct, but the camera seems to be stuck on screen
@@ingoliebig6206 That is VERY possible. A room created through code might not have the default camera defined. So you may need to create a camera and assign it as the view_camera[0]
yes in GMS 2.3 you MUST first add: camera_create_view(room_x, room_y, width, height, [angle, object, x_speed, y_speed, x_border, y_border]) then it works!
I've been playing with Level Of Detail for sprites which works nicely with responsive screen layouts. Basically if your art is rendered rather than drawn it's easy to render out at power of two scales with transparency maintaining detail and ketting really good results even with 1.5x scaling as you have something close to it available. I'm going to try this approach using MipMaps for tiles that don't need transparency - constructing the images out of RGB should be fun...
where do you enter the size of the viewport? If I don't do this in the editor under viewport properties, then I get a black screen. is that right? because it's not mentioned in the video.
How many rooms does your game have? Is it 1? Then go ahead and set up your view in the room editor. Is it 100? Using the room editor suddenly feels a bit tedious, no? But, hey you only have to do it once and then it's done. Until you decide you don't like your original resolution you chose. Now you get to go back through all 100 rooms again and fix it. There's nothing inherently "bad" about setting up your views in the room editor, but on larger projects it is impractical.
@@PixelatedPope I see, that makes sense. I thought it might be an inherent problem, similar to the problems with persistent rooms that you mentioned in another video. Thanks for the reply. Thanks for making the palette swapping thing on the marketplace too, by the way. Really useful for my project, there's no way I was figuring out that on my own.
I followed the tutorial perfectly and it works amazingly, but I have this one question, I would like it for the camera to be a bit more zoomed in and compromised, what do I have to change because I don't know what exactly to do.
So when you divide 1920x1080 by a whole number, the higher that number, the more zoomed in you are going to be. The problem comes from when you want something between like 3 and 4. 4 is too zoomed in, 3 is too zoomed out. You could try like 3.5 or something, but this could introduce distortions. There are work arounds for that, but it gets complicated.
Yup! I usually call it in the step event because a. it doesn't really "cost" anything significant. And b. if I decide to do zooming or something, I'll end up having to move it into the step event anyway.
0:35 is why I subscribed. I don't know if you intentionally subverted my expectations with that punchline, but damn, I thought he was going to say, "I'm interested in what game you're making." or something to that effect.
This is an older video, but I seem to not have the same outcome with the slower following camera. My camera still follows very fast, without any delay.
Two things to check: 1, if you were following this tutorial in an existing project, make sure you don't have "object following" still set in your room's view settings. 2. Make sure that you only have one camera_set_view_pos() in your end step. A lot of people do one after getting the target and then again after the lerp calculations... which is going to get the behavior you described.
@@PixelatedPope I had this problem in my existing project and I left it for 2 or 3 weeks because I was angry that I can't make it work. But yeah, your second solution is on point. I totally missed the fact that at 12:02 you're deleting the previous camera_set_view_pos(). Should be logical but for newbies like me it's obvious after the fact. Luckily you're still answering to the comments with solutions and thank you for that.
@@Kuzyn I'm here a year later than you and had the same issue, lol. Totally missed the deletion of the camera_set_view_pos from the End Step and had two of them which clearly wasn't going to work right. This comment chain helped me after about an hour of playing around and not making progress.
Could be any number of things, but youtube comments aren't great for debugging. I recommend joining the GM Discord server. Many of the members there are very familiar with this camera solution and can help you figure it out. If I'm available, I'll help myself!
Sure. Just 2 is pretty easy. Just find the midpoint between the two objects using the midpoint formula. Then point your camera at that the same way you would point it at one object. If you need more help beyond that, recommend joining the GM Discord Server here: discord.gg/gamemaker
That shouldn't really happen. The easiest way to smooth it out is to make sure you are resizing your app surface to be larger than your view (usually the window size). Beyond that, make sure you are "lerping" the camera position properly. A lot of people follow this tutorial and end up with two camera_set_view_pos() in their end step. You just need the last one.
Hi! Great tutorial! Thanks so much again! I could easily combine it with your display manager. The only thing that I couldn't solve is that the player is always jittering when camera "lerps" towards him at the end. Do you, by chance, have a solution for this issue? thx in advance. steve
Are you using sub pixels? If not, that would be a quick way to fix it. If not... man, you get into some sketchy territory. Much discussion has been had about how to move the camera in a locked pixel grid without jittering... it's a definitely challenge.
@@PixelatedPope No I don't think so. I use your display_manager & the simple as possible camera. So my application surface is exactly as large as my view size right? Should I change it? .... Oh acutally my the size of my view is ideal_width & ideal_height right? (So zoom-x times smaller)
@@Stefan-bn4wh Yeah, that would be the quickest way to smooth things out. Try setting your app surface to be 2 or 3 times the size of your view, depending on your base view size (but don't exceed the size of your window), and see if that helps smooth things out. If not, something else might be going on and I recommend hitting me up on Discord for further investigation.
i love it however personally i would when room load set it where the player is in the middle aslong as its not on the edge (then i would have it clamped) to prevent it moving from top right to player smoothly
Yup! Great idea to snap to the player's position in the room start event. Or it can look cool to do it a bit above or below the player once you have a fade implemented, so it looks like it's just sliding into place as the fade completes.
Excuse me @PixelatedPope but when I follow your steps exactly the camera doesn't follow my character so can you please tell me how to resolve this problem?
I've got a question I'm having problems solving how would I go about having my camera more zoomed out by default without increasing my window size(I don't have a zoom out feature I just want to have my camera zoomed out more by default)
I've fount a temporary fix where after I set the window size and such in the create event I then do view_width *= 1.8 view_hight *= 1.8 and it zooms out enough but anyone who has a better solution please still tell reply here :D Edit: yes I did find a temporary solution in 17ish minutes don't question it
ty for the content! when you say 'set zoom up here' what do you mean? I keep fiddling with this camera_set_view_size function to get the camera to zoom in on the player during certain events, but it doesn't focus the player.
Yeah, it can be a bit tricky. You need to change the size of the view to zoom in/out and THEN position the view. Because when we are positioning the view we are always moving the top left corner, if you center it on the player, then resize it to be smaller, your player will move down and to the right. So resize, then center. And you have to center based on the new size, not the original, so don't get the size, resize and then center based on the previous size.
One question I didn't see answered: For this approach, I know we don't use room for viewports but... do you have Enable Viewports ON or OFF in the Room Editor? I assume OFF, but wanted to be certain since it's default ON... :)
I am trying to get this to work, but the camera is static and will not move with the player. I have been trying to fix this for the past 4 hours and the only way I get it to work is by making the camera_obj follow the player's coordinates using move_towards_point(player.x, player.y, 1). The camera wont move unless the camera object moves. When I do this, the camera is the same as though I were using the viewports built in. It makes it all stuttery. From what it looks like, that isn't supposed to happen. I have looked through the code numerous times finding nothing wrong with it. I think it has to be a problem with the end step event. Everything looks good though and I have almost given up hope of using this method. I just wanted the camera to not stutter when moving, but it seems like that is what I am going to have to deal with. End step: #macro view view_camera[0] camera_set_view_size(view, view_width, view_height) if instance_exists(player) { var cx = clamp(player.x-view_width/2, 0, room_width - view_width) var cy = clamp(player.y-view_height/2, 0, room_height - view_height)
var cur_x = camera_get_view_x(view) var cur_y = camera_get_view_y(view) var qspd = 0.1 camera_set_view_pos(view, lerp(cur_x, cx, qspd), lerp(cur_y, cy, qspd)) } I have renamed some of the variables to make it better for me to understand. I don't know what the problem is at all. I have read through all of it in order to figure out the problem. Just incase I am infact an idiot, I will also include the other events: Create: view_width = 320 view_height = 240 window_scale = 3 window_set_size(view_width * window_scale, view_height * window_scale) alarm_set(0, 1) surface_resize(application_surface, view_width * window_scale, view_height * window_scale) Alarm 0: window_center() Room Start: view_enabled = true view_visible[0] = true I have viewports in the rooms disabled. My camera is persistent and visible. The camera IS in the room. The player is in the room. The end step just does not work. I don't know what to do from here. TL;DR: The camera shows up in my rooms, but it does not move with the player. It just sits there.
You mentioned split screen, how would you go about making a split screen using the new gms2 cameras? Im only finding old solutions pre-gms2 that don't seem to work anymore. The old way isnt working for me and no matter what port size i do, the camera goes fullscreen. Thank you
I'm honestly not sure. I haven't even attempted it in GMS2, yet. I imagine you'd need to hook up a camera to the second view, and then manipulate the port variables to position and size them to both fit on screen.
Still not working properly for me. I hate the new convoluted camera system. I get weird black bars on the side of my window and the pixel grid is broken.
Sorry you are having issues. The youtube comment section isn't the best place for helping someone with their code. You should join the GM Discord server. Tons of people there who can help you get your code working, and if I'm available I'll help you myself. Here's an invite: discord.gg/By6u9pC
Hi Pope, was wondering if you could help out if I wanted to hack a view_border into it (replicating the old view_hborder etc from earlier editions when a view following an object was enabled, which effectively meant there was a 'dead zone' in the middle of the screen where you could move around without the camera following, and then once you hit the borders it would keep with you again). Assuming I only want to move the x pos of the camera for now. I added an addition condition using the var view_hborder to the function that determines when to update _x. eg: if (instance_exists(target) && (target.x < _cur_x + view_hborder) {_x = floor(clamp(target.x - view_width/2, 0, room_width - view_width)); So far so good, the camera moves when the player (target) hits the horizontal view border. Only thing is that _x is still dead center of the screen, so it smoothly lerps back to having the target centered. I'm not sure how precisely to get the math working for determining _x in such a way that it lets the target/object still be pressed up against the horizontal border and moving smoothly. I'm sure it's elementary but I just can't visualise it. I'd be glad if you could help me out here.
Figured it out. Just had to figure out where the camera should go when approaching the borders instead of dead center, so had to adjust target.x - view_width/2 into something else (i.e. target.x - view_hborder*2 when going L and target.x - view_width + hborder*2 when going right). Leaving comment here in case anyone else is trying to work it out
UA-cam comments are a really poor platform for coding help. I recommend joining the GM Discord server and asking in the help channels. If I'm available, I'll be happy to help personally, but if not, there are lots of very friendly people there to help you work out the issue. Here's an invite: discord.gg/By6u9pC
I have a slight problem. I'm making a retro game, with window dimensions of 640x480, and a window scale of 1. Whenever I run my game, for a couple frames, the view is at half it's normal xscale, then it corrects itself. Is there any way of fixing this?
Start your game in a black room like almost every single game in existence does :D Then fade into a title screen or a developer logo. Not something you really need to worry about until you are ready to actually release your game. You'll notice this same sort of thing happen with pretty much every game when you change the resolution.
There's one checkbox in the view settings that I cannot figure out how to set programmatically, and that is Clear Viewport Background. How to do that, following your advice to never use the room editor to set up the views?
Hmm. It doesn't look like there is a specific function to enable that. But just adding a background layer to the bottom of your layer list will do the same thing.
@@PixelatedPope Yea, I discovered this when I had a background that wasn't just a standard solid colour, so it was drawing over itself. I'll look into adding a couple background layers, with the lowest level being just a black rectangle.
I have one question: I already know how to make objects "wrap" from one side of the level to the other (if x exceeds room_width, then x -= room_width, if x < 0, then x += room_width and so on), but how can I use a single view camera to have a wrapping view (move close enough to the right side, I'll actually see part of the left side, and the objects wrapping from one side to the other just appear to move normally)? Does this require multiple views?
Hmm... That might be a good use case for multiple views. What I usually do for room wrapping like that is have like... a surface or something of the room drawn to the left and the right of the room itself. Then each object draws itself in its room position, but also draws itself x-room_width and x+room_width. So there are these sort of "clones" of your object but it's not actually the object itself. Multiple views multiplies the time it takes to draw your game, since each object will be drawn multiple times. So you really should avoid it as much as possible.
Hey there it is me again. I am still using this way of scaling in my project that is almost 2 years old, but I have noticed something odd. I have trouble detecting touches (left mouse) properly. When I draw the mouse_x and mouse_y on the screen, the top left corner of the room and view is not 0,0, but something like 0,35. And when I move the mouse all the way to the bottom right corner, I get a totally different resolution than the values of viewHeight and viewWidth. This is probably why the point_in_rectangle code is giving me trouble detecting touches. Did something change in Game Maker rendering thisway of scaling obsolete, or do I have to change anything? I don't know if you still maintain this, but it seems that something in Game Maker has changed. Thanks.
Do you get the same results if you use the "device" functions instead of mouse functions? Have you messed with the "port" settings at all in your room settings? Are you trying to interact with something "in the room" or "in the gui"?
I'm not sure if I'm following this correctly but does your object camera work without putting it in a room? If not, do I have to put it in each room I make?
That is totally up to you and your art. Again, room size doesn't matter, it's just what base resolution you want your game to be. If you are using really low res pixel art, then try dividing 1920 and 1080 by 4 and see how that looks. If it seems too zoomed in, try 3. Etc.
Really loving this camera object, but I've been having a couple problems with it. Everything works great until needing to switch rooms, then the camera bugs out. Having the obj_camera be persistent doesn't fix anything, nor does creating a new obj_camera in the new room. I have no clue why this problem is occurring, but any tips would be incredibly helpful!
@@michaelhill1256 You don't know how to drag and drop an instance from your asset list to your room? You may be jumping into the deep end by watching my channel, then. You should probably start with some of the beginner tutorials.
Hey pope, i know it's a little bit later, but there's anyway to make my camera no shivering? that's because my player_speed are 1, and i've read that view x and y can't be a cracked number, liker 0.50 or 1.50, my player movements cut hspd and vspd in half in diagonals, so, when i move, my player just don't stop shivering, and if i try to floor, the player stops shivering, but the scenario, start to get a little bit unfocused, sorry for my bad english c-c
View positions actually CAN be non-whole numbers. But the easiest way to fix this is to use sub-pixels. Resize your application surface to be the same size as your window, and you'll notice things should stop jittering.
I loved this tutorial and I know its going to help me a ton. I was using another camera system before, but I find this one to be more useful. I do have a question through. For some reason , when i play my game my camera zooms in to my character a bit too much( i think it is because I have the width at 1920/6 and height at 1080/6 in the create event. Is there someway i can fix this because you said the higher the number, the better it is going to look but I do not want the camera to zoom in too much.
Yeah, just go down to 5! The higher the better but not at the cost of how you want your game to look. If it's too close, just step it back. I wouldn't go below 3... but 2 is technically okay as well if you are okay with your game looking absolutely awful on old laptops.
@@PixelatedPope Another question, how about the aspect ratio, so the pixels will look nice and clean (I'm using hand drawn sprites). I was wondering how that would be set up with this system. I saw your other tutorials about aspect ratio, but I don't know which code to put in. And one more question, this may be a dumb one but on the left where you can change the size of the screen in the room, with this code I won't have to do that anymore?
@@slickygreasegames Yup, don't mess with the camera / view settings in the room editor anymore. This code does all that for you. As for aspect ratios, I would recommend not worrying about them. You don't need to support ultra wide screen, or 16:10 or whatever. Just support 16:9 and be okay with some black bars. Nobody is going to care, and it's really not worth the effort for 99% of GM projects.
@@PixelatedPope One more question. Since my camera zooms in on the character with those settings I have, would I need to shrink the size of the sprites and the background assets to fit with the room?
@@slickygreasegames Not necessarily. You can always increase the size of the view. You also mentioned "hand drawn" sprites... if you aren't doing "pixel art" with hard edges and precise pixels... well, almost none of this matters. You can make your view almost any size you want, including 1920x1080 if your sprites are just that large.
In search of a solution to the problem of pixel distortion, I found myself here, in front of your playlist. These guides were very useful for me, but I still have a question about views and cameras. Is it possible to add a mini-map for a 2D game with camera? If not, are there any alternative methods to manage game resolution and aspect ratio with such possibility? I'm quite unskilled at GMS.
It's absolutely possible, yes. UA-cam comments aren't exactly the best way to get help with GameMaker, though. I highly recommend joinging the GameMaker Discord server and asking your question there. If I'm around, I'll help you myself. If I'm not, there are lots of friendly, helpful people there to answer questions. Here's a link: discord.gg/gamemaker
When I switch to fullscreen the fps drops from 60 down to 30, then back to 60 when exiting fullscreen. What would be causing this issue? I'm thinking the application surface is being stretched and slowing the performance
That's very possible, especially on something like a 4K monitor. Ideally, you wouldn't always size your app surface to be the same size as your window; it's not really necessary. Instead pick a nice multiple that gives you enough smoothness without being super high res. You could even make it an option for your players to choose smoothness over performance.
I followed this tutorial exactly but my viewport size is the same as the room size. Is this video independent of the earlier videos or am I missing something from them?
Totally independent. You are missing something from THIS video. You sure you got an instance of your camera object in the room? You sure you have your room start event set up correctly?
@@PixelatedPope So I did need an instance in the room. I don't think I saw you place it in the room, but I didn't expect to have seen since I was wondering how the instance will exist across the entire game. Will I have to place an instance manually in every room?
I have a couple questions: Why do you update the camera view size every step? As far as I can tell you only need to do that once unless you're changing the view size dynamically. When I start my game there's a small graphical glitch where it displays a squashed frame before filling out the window. Did I do something wrong, is there a way to fix that, or is that just the way it has to work?
That's the way it has to work. Typically you want the first frame of your game to just be black, and then fade into the next thing you want the player to see. Then nothing ugly will be on screen. As for updating the camera size... there's no reason not to. And if your game supports zooming in or out, then you wouldn't have to change much to support that with this setup. You are welcome to set the view size in the room start event when you enable the view and never touch it again if that's all you need for your project, though.
@@PixelatedPope thanks for the reply. What you suggested about starting on a black frame is what I ended up doing. It felt like I was missing something so it's good to know I wasn't.
Thank you for your videos! I have once used two views for a single-player game and I am curious if you can share why I am wrong as it seemed correct at the time. This was back before GMS by the way. I used one view to follow the character and then a second view layered on top of that but in the bottom right corner as a mini-map / radar. This seemed like a pretty good use case for 2 views on a single-player game but let me know!
Absolutely! It "seems" like a good idea, but it's actually terrible! When you have a second view, every single object in that room runs its draw event for that view. Every. Single. One. I imagine not a single thing visible in your first view was meant to be seen in your second view. Or at least, a very limited number of them. But since you used a second view, EVERY object lined up to run their draw event again. Not to mention other non-object related drawing like all of your backgrounds and tiles. Everything draws for every view. I don't think I need to explain why this can be very bad. Radars and minimaps can be easily created using a surface, and then you have full control over what is drawn to that surface. This will be much better for performance and it's way easier to manage than positioning views in a room.
Nice job explaining the new system. The one part of setting the view within the room editor that was missing is the concept of view border. I assume that if you wanted to include this aspect with your system, you would calculate it manually rather then using the built-in functions (camera_set_view_border)?
Right. Basically, you take full control over the logic of your camera, so if you only want the camera to move when the object is close to the edge, you can handle that with logic.
@PixelatedPope I have tried a lot with the camera most of them works with my game, but there is one main problem (which happens every time) whenever I add or do something with the camera the same obj moves in a weird way, like the sprite is moving , can you help?
Been trying to mesh together your first one with this one, but would really love a completely fresh from scratch video based on GMS2. Also a bit confused as to some of the magic numbers, like view_width=1920/6 - you just say that the higher the division number, the better, but don't really go further into it. Any chance you would consider making something like the old part 3, but from scratch in GMS2?
Yeah, I've helped a few people with this exact thing. I could do a future video on that, sure, but who knows when I'll get around to that. For the time being, join my Discord server and ask there, and I or someone else familiar with the topic will help walk you through it and answer any questions you might have. discord.gg/By6u9pC
Alternatively, you could check the pinned comment which is how I've personally meshed the old tutorial and this one. But feel free to reach out with any specific questions.
@@PixelatedPope Now... if only I can decode what you just said and somehow apply it to my game. lol anyway, nice video. I tried it but it did not work for me for some reason.
@@DrN0D3-MUSIC If you want some help, I recommend joining my discord server (link in the description). Lots of people, including myself, who can help you with anything GM related!
use display_set_gui_size() to set the size to whatever you want. Typically you either keep it the same size (like I have) or have it match the window size.
Hey thanks for the tut, I've got a small problem though, while the camera works and follows the player, it doesn't do that slow drag back to the center of the screen for the player character. Did you maybe change something in the other parts of the camera events and not show it? Or am I just missing something?
This is great - one question out of curiosity: why do you start your var names with underscores (eg _x, _y, _spd). is this a common naming convention or just personal habit?
Both? Sometimes I tell myself I started the trend. It was more important back in GMS1 and earlier when variables didn't have different colors, but it's a good idea to differentiate your vars from your instance variables. And the easiest way to do that consistently and make it immediately recognizable at a glance is with some sort of special character. The other advantage is being able to reuse common variable names. For example, say you are looping through the rows and columns of a ds_grid with a for loop. Many would do something like this: for(var i=0; i
Jesus man. I'm so grateful for your tutorials. I've dropped my project for months because I couldn't understand why some tiles were stretched during camera movement. I haven't yet tried your dynamic scaling solution but once I get off from work, I'll try it out. I really hope this solves the problem. I still have one question tho: Is it possible to get an invite to your discord server and ask you or the other experts for advice if any errors or problems might occur. Do I need to pay for the help or how do you provide it? free if the time suits you? I'd be also glad to show you my not so impressive platform game in the progress.
sadly im not sure what im doing wrong, this camera object seems to change nothing in the game. it simply looks the same with and without the object. changing the scale and other variables simply made no effect either as if the game just ignores this objects code and i have absolutely 0 clue why. my game is a platformer rather than top down but that shouldnt be an issue i dont think. anyone else have or had this issue?
i created a whole new test game to see if it would work and it did. ive no clue why in oneproject itseems to do nothing and in the other works perfectly. maybe there are some room camera or view settings that can affect this that i touched? id rather not just build my project back up from scratch if i can avoid it.
ok PROTIP: NEVER change the filenames of your project from file explorer. just save as new project name. I changed the project name in windows file explorer and it really messed some things up. i clicked save as template and saved it all thankfully, and now camera is working well :D
Nice! If you are ever feeling disheartened and want to commiserate with other GM users, make sure you join the Discord server! We'll help you get over whatever has ya down! discord.gg/By6u9pC
[Update 12/5/24]
Hey, are you going through my whole resolution and aspect ratio tutorial series? Or maybe just thinking about it?
DON'T
My math in my older videos is flawed and will not work for every resolution. Sorry.
But, you do not need to support ultra wide monitors in your indie 2D game! Just build your game for 1920x1080 using the advice in the video. Be okay with the black bars on different monitor aspect ratios.
If you want to do further correction for non-whole number scaling on various monitors, just use a bi-linear filter shader on the app surface. That's what Sonic Mania does on the Switch and it looks fantastic.
Ultimately, if you release your game and people start asking you for widescreen support: congratulations on releasing a game and having some measure of success. NOW you can think about adding in ultrawide support.
I found your series on aspect ratios extremely helpful and happily subscribed to your channel--thank you!
I have quick question regarding GMS2. Which script is the most current for GMS2: the script here or the one in pastebin.com (referenced in one of your older videos)? I assume the one here, but just wanted to confirm. Thanks again!
@@realistindenial Everything I personally do with GMS2 cameras is based off of this video (and then I mix in some of the aspect ratio and pixel perfect scaling stuff from the older videos). If you have any more questions, definitely join my Discord server. I or someone else will be able to personally answer any questions you might have. discord.gg/By6u9pC
@@PixelatedPope Thanks for your response. Thanks for the invite to Discord. I'll see you there! :-D
Why are you making those macros? I don't see them being used anywhere in the code.
@@ulascantepe1326 it's more likely you'll use them elsewhere in your code. It's just a nice way to get the view's current dimensions.
Finally, a GMS video that isn't 2 years old.
Nice
it is now.
Oof
HAH!
hummm now is exactely 2 years old . But I don't care, I need it
It’s so nice to see how fast you help people on discord
yup 100% recommend it
This!! He's a really cool guy
Following the tutorial I had pixel distortion but because I was working with a very small resolution,240x135 (1920/8 x 1080/8) since my characters are 16x16.
When setting up for the camera to follow the player we have "var _y = obj_player.y - view_height/2" at 8:55.
Since in my case the view_height==135, my camera "y" coordinate was always in a fraction position.
So I just used floor() there("var _y = obj_player.y - floor(view_height/2)"), and whenever I used "view_height/2"and everything is ok :).
Also my app surface was the size of the view(very small, 240x135), if I set it to be the size of the game window(6x bigger) it would hide this bug.
tl:dr
I had pixel distortion because I was accidentally setting up my camera to be in a fractional position, make sure you don't do that =)
Thank you for posting this!
The simplified and persistent camera object really helps. I was having trouble letting the user adjust the window size and was led here. I used your simple camera setup and added a 'surface_resize(application_surface,camera_view_width,camera_view_height)' whenever the window changes size, or when the room changes, and it seems to work well so far.
At the time when I start thinking of all of this stuff this video is a best thing I could ever find. Thank you, it would have taken me unthinkable amount of time to figure all this out on my own.
All right, basic setup seems to work, camera follows at the center of my player, all fine, except the sprite of the player moves in totally different speed, not staying in the position of the player. What's up with that? Actually sprite is already drawn in a different location when I start the game, weird. Position should be absolute I think, why is it offset by that much? If I take out the camera code everything works as it should, something makes my sprite drawn in wrong place. EDIT: I found it, I had draw_self() function at draw GUI... which apparently is wrong choice. :D
I'm about to binge watch everything you put out. Thank you for this stuff, it is so helpful, can't say it enough! You rock man.
Thank you!
Great video for beginners, especially with you using the whiteboard to visually show what's happening behind the scenes.
I have watched this video 15 times, every time I start a new project. You are a savior.
Just between you and me, I have to watch it every time I start a new project.
Hey, I just wanted to thank you for all your videos. It helps immensely in learning game maker :)
The scaling problem has been causing a headache for me and this video solved it. Thank you very much!
Thank you so much!! I have watch several other videos on views and non of them explained it well and I was getting frustrated until I found your video, You explain it so well I will be watching more of your videos from now on
THANK YOU! The camera function in gms2 is such a mess to understand for someone like me and I didn't know how to simplify it.
It's good to know what I should avoid doing to avoid bad habits. That's a very informative video, you're awesome!
thank you so much for this!! clear, concise, easy to understand, definitely the best tutorial on basic gamemaker cameras
Yoyo Games should be paying you for your content. Top notch as usual
Thanks so much, this was really helpful. Especially with the stuff about how the camera always follows the top left of the player. It was really confusing before, but it was understandable the way you showed it.
Thanks a lot, man! That little extra explanation there about the view compared to the "room" was very helpful knowledge! Thanks! Subbed!
for those who cant seem to run the game even though the code is identical!
In your End Step event of obj_Camera Do NOT put a ';' behind the line containing "#macro View view_camera[0]"
Yup. No semi colons on your macros!
@@PixelatedPope by the way what settings do I need in my game graphics options?
@@DeadManRising36 Default settings should be fine. Most important is the "Keep Aspect ratio" scaling option. Everything else can be changed as needed.
I would add, with newer version of GM2, placing macros in objects will raise an exception (at least it does in this example). Create a script file and place them all in there and it will then run error free.
God fucking bless you, PixelatedPope. Your tutorials are an absolute LIFESAVER. Cannot thank you enough for this!
was super helpfull I was able to make an infinit room in a fullscreen window (also added some camera movment code myself) much more customizable than the settings in the room editor
Great tutorial! Thanks for helping! Whiteboard was nice touch
Hey, thanks a lot for this, this is exactly what I was looking for. I like to make traditional style games with strict resolutions / pixel grids. By using surface_resize to set the application surface size to the view size it enforces a strict limit. What I had to do before was floor any x and y values that weren't integers before drawing, but this simplifies things. The only downside I've found so far is that I usually print some debug information to screen, but now that's forced to the same resolution limits as well so it takes up a lot more screen space than before.
It's also a lot easier to adjust the camera position this way than wrestling with the auto-follow in the room editor.
So, if you output debug information to the gui layer, you can resize the gui layer using display_set_gui_size(), and you can set it to the same size as your window! Then you debug text will be super small and crisp.
@@PixelatedPope hey, thanks! I'll try that. The solution I found was to create a custom font with aa turned off and make it as small as possible. It works and I like the fact that it doesn't break the pixel density, but screen real estate can still be an issue.
What would be the best way of implementing view scaling or 'fov' based off the camera's speed? (ie the faster the camera moves, the wider the fov becomes)
I thought about just creating a muliplyer:
var _fov = 1 + (point_distance(_x, _y, _cur_x, _cur_y) * .1
Then applying that to the:
camera_set_view_size(view, view_width * _fov, view_height * _fov)
But as you stated, the view size needs to be established prior to calculating it's coordinates, soooo...
Yeah, changing the size of the view at any time immediately complicates things. I usually operate on a "base" size and scale things off of that. So instead of referencing the current view size to get your view_width and height, you would have a static variable that represents your base size.
@@PixelatedPope Hi again. Thanks for taking the time. I'm getting a strange "overlapping effect" with collisions. If I remove the camera from the room, and test collisions, they appear pixel perfect. I am using subpixel movement, and using this code:
// Check for collisions and move player
if(place_meeting(x + move_speed, y, obj_solid))
{
x = round(x);
repeat(ceil(abs(move_speed)))
{
if(!place_meeting(x + sign(move_speed), y, obj_solid)) x += sign(move_speed);
else break;
}
}
else x += move_speed;
I snagged this code from a forum, and it seemed to work, up until implementing the camera. Just to clarify. Collisions are functioning normally. It's just the appearance that is off.
Side note: I raised the window_scale to 16, as it drastically improved the smoothness of the camera
For some reason my camera does not move slowly towards my player, just stays on it the same it would without the added code. Can't seem to figure out why, triple checked the code but there is always something to miss.
Often this is because something else is moving the camera, likely because you had a different solution in place in the project before implementing this solution. So you have to "undo" everything you had before. This could be a different object moving the camera, or it could be the "object following" setting in the room settings.
Or, and this happens a lot, it could be that you position the camera on the player, then calculate the gradual position, and then move the camera again. Make sure you don't have camera_set_view_pos() called twice in your code.
@@PixelatedPope You were right I did the mortal sin of having the camera follow an object and didn't realize. New problem is the camera doesn't start on the player between room transitions. I might just scrap that part of the code tho because it doesn't seem like I honestly need it for my game. Thanks for the response though!
@@cjtodd6244 Hey, where you had this? That camera followed an object? I'm trying to figure out same problem that my camera doesnt move slowly towards player.
Wow, this video was fantastic. It was simple and straight to the point. Helped a ton, thanks!
Oh my god, you just saved my project. Thank you very much for the info about cameras cus I couldn't find anything helpful in the documents.
4:20 - Just a quick heads-up, from my experience, a Low Res app surface will increase the performance on Low end GPUs (I'm talking about potatoes here, like the GT 710, HD 6450 and APUs).
Add an option for the player if possible (Or just scale down if the Frametime is too High).
I see that when you start the game, the view moves from where it is positioned in the room (top right) to where the player is. I haven't tested this but to make the view start right at where the player is when you run the game, adding this code in the ROOM START event should do the job.
if instance_exists(o_player) {
x = o_player.x;
y = o_player.y;
}
You would need to duplicate the entire code of the end step event without the lerp and that would do it.
view_enabled=true;
view_visible[0]=true;
if(instance_exists(obj_player))
{
var _x = clamp(obj_player.x-view_width/2,0,room_width-view_width);
var _y = clamp(obj_player.y-view_height/2,0,room_height-view_height);
var _cur_x = camera_get_view_x(view);
var _cur_y = camera_get_view_y(view);
camera_set_view_pos(view,_x,_y);
}
@@PixelatedPope Yeah, that works. Thanks for correcting. I should've tested that before commenting.
Did anything bout this change in GMS 2.3? I can't get it to work
What I meant to say is that I can not get the view to move with the player. The camera_set_view_pos is called and the given x and y are correct, but the camera seems to be stuck on screen
@@ingoliebig6206 Let me check. If so, I would expect it to be a bug that should be brought to Yoyo's attention.
PixelatedPope maybe it’s a problem cause I create that room on-the-fly using the room_add function... but still... it should work I guess
@@ingoliebig6206 That is VERY possible. A room created through code might not have the default camera defined. So you may need to create a camera and assign it as the view_camera[0]
yes in GMS 2.3 you MUST first add: camera_create_view(room_x, room_y, width, height, [angle, object, x_speed, y_speed, x_border, y_border])
then it works!
Simple but clear and concise 👍
I've been playing with Level Of Detail for sprites which works nicely with responsive screen layouts. Basically if your art is rendered rather than drawn it's easy to render out at power of two scales with transparency maintaining detail and ketting really good results even with 1.5x scaling as you have something close to it available.
I'm going to try this approach using MipMaps for tiles that don't need transparency - constructing the images out of RGB should be fun...
It's for sure way easier.
Now I can simplify my setup.
There can be uses for two cameras without split-screen. Using the built in view-ports is a valid option.
no its not, you're horrible at programming
where do you enter the size of the viewport?
If I don't do this in the editor under viewport properties, then I get a black screen. is that right? because it's not mentioned in the video.
View Port is a combination of your app surface size and your window size. Don't change any settings in the room editor. Make sure they are all DEFAULT
Thanks for showing me this video, very nice!
This was awesome! Love it. Thank you very much.
I don't doubt there's a reason, but can you explain why we shouldn't set up the view in the room editor?
How many rooms does your game have? Is it 1? Then go ahead and set up your view in the room editor. Is it 100? Using the room editor suddenly feels a bit tedious, no? But, hey you only have to do it once and then it's done. Until you decide you don't like your original resolution you chose. Now you get to go back through all 100 rooms again and fix it. There's nothing inherently "bad" about setting up your views in the room editor, but on larger projects it is impractical.
@@PixelatedPope I see, that makes sense. I thought it might be an inherent problem, similar to the problems with persistent rooms that you mentioned in another video. Thanks for the reply. Thanks for making the palette swapping thing on the marketplace too, by the way. Really useful for my project, there's no way I was figuring out that on my own.
@@alexkennedy4990 No problem! Thanks for watching and good luck with your project!
@@PixelatedPope Thanks!
I followed the tutorial perfectly and it works amazingly, but I have this one question, I would like it for the camera to be a bit more zoomed in and compromised, what do I have to change because I don't know what exactly to do.
So when you divide 1920x1080 by a whole number, the higher that number, the more zoomed in you are going to be.
The problem comes from when you want something between like 3 and 4. 4 is too zoomed in, 3 is too zoomed out. You could try like 3.5 or something, but this could introduce distortions. There are work arounds for that, but it gets complicated.
@@PixelatedPope It actually worked out incredibly well, I got exactly what I wanted with virtually no issues. Thank you for the help, have a good one.
I was wondering, why is camera_set_view_size called every step? Can it just be called if the resolution changes?
Yup! I usually call it in the step event because a. it doesn't really "cost" anything significant. And b. if I decide to do zooming or something, I'll end up having to move it into the step event anyway.
@@PixelatedPope thanks! The part about "cost" was what I was also getting at. Now I'm fiddling around with getting stuff working with isometric view.
Finally, A religion that I can get on board with.
0:35 is why I subscribed. I don't know if you intentionally subverted my expectations with that punchline, but damn, I thought he was going to say, "I'm interested in what game you're making." or something to that effect.
Best video on the subject ever!!!!!
finnaly a video that explains everything perfectly
This is an older video, but I seem to not have the same outcome with the slower following camera. My camera still follows very fast, without any delay.
Two things to check: 1, if you were following this tutorial in an existing project, make sure you don't have "object following" still set in your room's view settings.
2. Make sure that you only have one camera_set_view_pos() in your end step. A lot of people do one after getting the target and then again after the lerp calculations... which is going to get the behavior you described.
@@PixelatedPope You sir, are a genius. I did not have views enabled but still had the player object being followed. Looks great now! Thank you.
@@PixelatedPope I had this problem in my existing project and I left it for 2 or 3 weeks because I was angry that I can't make it work. But yeah, your second solution is on point. I totally missed the fact that at 12:02 you're deleting the previous camera_set_view_pos(). Should be logical but for newbies like me it's obvious after the fact.
Luckily you're still answering to the comments with solutions and thank you for that.
@@Kuzyn I'm here a year later than you and had the same issue, lol. Totally missed the deletion of the camera_set_view_pos from the End Step and had two of them which clearly wasn't going to work right. This comment chain helped me after about an hour of playing around and not making progress.
@@timtimethymetie its crucial to check comments if you have any troubles, really helps in every tutorial!
I got a black screen :/
anyone has a clue of what could have caused that?
Could be any number of things, but youtube comments aren't great for debugging. I recommend joining the GM Discord server. Many of the members there are very familiar with this camera solution and can help you figure it out. If I'm available, I'll help myself!
Is there a way to make the camera positioned in the middle of two objects? I can't seem to figure that out.
Sure. Just 2 is pretty easy. Just find the midpoint between the two objects using the midpoint formula. Then point your camera at that the same way you would point it at one object. If you need more help beyond that, recommend joining the GM Discord Server here: discord.gg/gamemaker
I really can't get it to work... The scaling seems perfect, but when the camera moves diagonally it jitters! :(
That shouldn't really happen. The easiest way to smooth it out is to make sure you are resizing your app surface to be larger than your view (usually the window size). Beyond that, make sure you are "lerping" the camera position properly. A lot of people follow this tutorial and end up with two camera_set_view_pos() in their end step. You just need the last one.
Any chance of making a split screen camera video that scales? Not too many resources on the subject.
Awesome! Fixed all the jittery pixels for me, as well as answered a couple of other questions. Thank you so much!
wow this works even in 2023 GM version. thanks
i'm a subscriber. you uploaded videos recently. i want more your many tips. by the way have a nice christmas.
Is it a requirement to put an instance this camera object in each room you use? The persistence checkbox doesn't apply it automatically, right?
Check the persistent box and drop it in the first room of your game and that's all you need to do!
@@PixelatedPope neat. I think I'm gonna customize it to configure what sprite to follow because it might be different per room.
Hi! Great tutorial! Thanks so much again! I could easily combine it with your display manager. The only thing that I couldn't solve is that the player is always jittering when camera "lerps" towards him at the end. Do you, by chance, have a solution for this issue? thx in advance. steve
Are you using sub pixels? If not, that would be a quick way to fix it. If not... man, you get into some sketchy territory. Much discussion has been had about how to move the camera in a locked pixel grid without jittering... it's a definitely challenge.
@@PixelatedPope Do you mean by "are you using sub pixels?" that I round the x,y positions? No I don''t.
@@Stefan-bn4wh Is your application surface larger than your view size?
@@PixelatedPope No I don't think so. I use your display_manager & the simple as possible camera. So my application surface is exactly as large as my view size right? Should I change it? .... Oh acutally my the size of my view is ideal_width & ideal_height right? (So zoom-x times smaller)
@@Stefan-bn4wh Yeah, that would be the quickest way to smooth things out. Try setting your app surface to be 2 or 3 times the size of your view, depending on your base view size (but don't exceed the size of your window), and see if that helps smooth things out. If not, something else might be going on and I recommend hitting me up on Discord for further investigation.
i love it however personally i would when room load set it where the player is in the middle aslong as its not on the edge (then i would have it clamped) to prevent it moving from top right to player smoothly
Yup! Great idea to snap to the player's position in the room start event. Or it can look cool to do it a bit above or below the player once you have a fade implemented, so it looks like it's just sliding into place as the fade completes.
Excuse me @PixelatedPope but when I follow your steps exactly the camera doesn't follow my character so can you please tell me how to resolve this problem?
Did you put an instance of the camera manager object in the room?
@@PixelatedPope oops... thanks for the fix!
I've got a question I'm having problems solving how would I go about having my camera more zoomed out by default without increasing my window size(I don't have a zoom out feature I just want to have my camera zoomed out more by default)
I've fount a temporary fix where after I set the window size and such in the create event I then do
view_width *= 1.8
view_hight *= 1.8
and it zooms out enough but anyone who has a better solution please still tell reply here :D
Edit:
yes I did find a temporary solution in 17ish minutes don't question it
Sure. See in the code where we divide 1920 and 1080 by 6? Make that a 5 or a 4 and you'll zoom out!
@@PixelatedPope Thank you, that was a simple fix that I wish I had tried earlier 👍
i've been dying for videos like this!
Definitely going to use this!
ty for the content! when you say 'set zoom up here' what do you mean? I keep fiddling with this camera_set_view_size function to get the camera to zoom in on the player during certain events, but it doesn't focus the player.
Yeah, it can be a bit tricky. You need to change the size of the view to zoom in/out and THEN position the view. Because when we are positioning the view we are always moving the top left corner, if you center it on the player, then resize it to be smaller, your player will move down and to the right.
So resize, then center. And you have to center based on the new size, not the original, so don't get the size, resize and then center based on the previous size.
One question I didn't see answered:
For this approach, I know we don't use room for viewports but... do you have Enable Viewports ON or OFF in the Room Editor?
I assume OFF, but wanted to be certain since it's default ON... :)
Yup! You shouldn't have to set anything view related in the room editor ever with this method. The room start event checks that box for you.
I am trying to get this to work, but the camera is static and will not move with the player. I have been trying to fix this for the past 4 hours and the only way I get it to work is by making the camera_obj follow the player's coordinates using move_towards_point(player.x, player.y, 1). The camera wont move unless the camera object moves. When I do this, the camera is the same as though I were using the viewports built in. It makes it all stuttery. From what it looks like, that isn't supposed to happen. I have looked through the code numerous times finding nothing wrong with it. I think it has to be a problem with the end step event. Everything looks good though and I have almost given up hope of using this method. I just wanted the camera to not stutter when moving, but it seems like that is what I am going to have to deal with.
End step:
#macro view view_camera[0]
camera_set_view_size(view, view_width, view_height)
if instance_exists(player)
{
var cx = clamp(player.x-view_width/2, 0, room_width - view_width)
var cy = clamp(player.y-view_height/2, 0, room_height - view_height)
var cur_x = camera_get_view_x(view)
var cur_y = camera_get_view_y(view)
var qspd = 0.1
camera_set_view_pos(view, lerp(cur_x, cx, qspd), lerp(cur_y, cy, qspd))
}
I have renamed some of the variables to make it better for me to understand.
I don't know what the problem is at all. I have read through all of it in order to figure out the problem.
Just incase I am infact an idiot, I will also include the other events:
Create:
view_width = 320
view_height = 240
window_scale = 3
window_set_size(view_width * window_scale, view_height * window_scale)
alarm_set(0, 1)
surface_resize(application_surface, view_width * window_scale, view_height * window_scale)
Alarm 0:
window_center()
Room Start:
view_enabled = true
view_visible[0] = true
I have viewports in the rooms disabled. My camera is persistent and visible.
The camera IS in the room. The player is in the room. The end step just does not work. I don't know what to do from here.
TL;DR: The camera shows up in my rooms, but it does not move with the player. It just sits there.
Finally got it working about 5 hours later.
@@gamesruleyears8993 how?
You, sir, are a scholar and a saint! Thank you!
You mentioned split screen, how would you go about making a split screen using the new gms2 cameras? Im only finding old solutions pre-gms2 that don't seem to work anymore. The old way isnt working for me and no matter what port size i do, the camera goes fullscreen. Thank you
I'm honestly not sure. I haven't even attempted it in GMS2, yet. I imagine you'd need to hook up a camera to the second view, and then manipulate the port variables to position and size them to both fit on screen.
is there ANY way to fix jittery camera caused by parallax? especially noticeable when the camera is moving slow
Still not working properly for me. I hate the new convoluted camera system. I get weird black bars on the side of my window and the pixel grid is broken.
Sorry you are having issues. The youtube comment section isn't the best place for helping someone with their code. You should join the GM Discord server. Tons of people there who can help you get your code working, and if I'm available I'll help you myself. Here's an invite: discord.gg/By6u9pC
Hi Pope, was wondering if you could help out if I wanted to hack a view_border into it (replicating the old view_hborder etc from earlier editions when a view following an object was enabled, which effectively meant there was a 'dead zone' in the middle of the screen where you could move around without the camera following, and then once you hit the borders it would keep with you again). Assuming I only want to move the x pos of the camera for now.
I added an addition condition using the var view_hborder to the function that determines when to update _x. eg:
if (instance_exists(target) && (target.x < _cur_x + view_hborder) {_x = floor(clamp(target.x - view_width/2, 0, room_width - view_width));
So far so good, the camera moves when the player (target) hits the horizontal view border. Only thing is that _x is still dead center of the screen, so it smoothly lerps back to having the target centered.
I'm not sure how precisely to get the math working for determining _x in such a way that it lets the target/object still be pressed up against the horizontal border and moving smoothly. I'm sure it's elementary but I just can't visualise it. I'd be glad if you could help me out here.
Figured it out. Just had to figure out where the camera should go when approaching the borders instead of dead center, so had to adjust target.x - view_width/2 into something else (i.e. target.x - view_hborder*2 when going L and target.x - view_width + hborder*2 when going right). Leaving comment here in case anyone else is trying to work it out
UA-cam comments are a really poor platform for coding help. I recommend joining the GM Discord server and asking in the help channels. If I'm available, I'll be happy to help personally, but if not, there are lots of very friendly people there to help you work out the issue. Here's an invite: discord.gg/By6u9pC
I have a slight problem. I'm making a retro game, with window dimensions of 640x480, and a window scale of 1. Whenever I run my game, for a couple frames, the view is at half it's normal xscale, then it corrects itself. Is there any way of fixing this?
Start your game in a black room like almost every single game in existence does :D Then fade into a title screen or a developer logo. Not something you really need to worry about until you are ready to actually release your game. You'll notice this same sort of thing happen with pretty much every game when you change the resolution.
There's one checkbox in the view settings that I cannot figure out how to set programmatically, and that is Clear Viewport Background. How to do that, following your advice to never use the room editor to set up the views?
Hmm. It doesn't look like there is a specific function to enable that. But just adding a background layer to the bottom of your layer list will do the same thing.
@@PixelatedPope Yea, I discovered this when I had a background that wasn't just a standard solid colour, so it was drawing over itself. I'll look into adding a couple background layers, with the lowest level being just a black rectangle.
@@ktisistoukuriou You can also just add a draw start event and just throw a draw_clear(c_black) in it.
@@PixelatedPope Yea, that's probably the best idea, since it circumvents having to check every room. Cheers!
I have one question: I already know how to make objects "wrap" from one side of the level to the other (if x exceeds room_width, then x -= room_width, if x < 0, then x += room_width and so on), but how can I use a single view camera to have a wrapping view (move close enough to the right side, I'll actually see part of the left side, and the objects wrapping from one side to the other just appear to move normally)? Does this require multiple views?
Hmm... That might be a good use case for multiple views. What I usually do for room wrapping like that is have like... a surface or something of the room drawn to the left and the right of the room itself. Then each object draws itself in its room position, but also draws itself x-room_width and x+room_width. So there are these sort of "clones" of your object but it's not actually the object itself. Multiple views multiplies the time it takes to draw your game, since each object will be drawn multiple times. So you really should avoid it as much as possible.
@@PixelatedPope Thanks!
Hey there it is me again. I am still using this way of scaling in my project that is almost 2 years old, but I have noticed something odd. I have trouble detecting touches (left mouse) properly. When I draw the mouse_x and mouse_y on the screen, the top left corner of the room and view is not 0,0, but something like 0,35. And when I move the mouse all the way to the bottom right corner, I get a totally different resolution than the values of viewHeight and viewWidth. This is probably why the point_in_rectangle code is giving me trouble detecting touches. Did something change in Game Maker rendering thisway of scaling obsolete, or do I have to change anything? I don't know if you still maintain this, but it seems that something in Game Maker has changed. Thanks.
Do you get the same results if you use the "device" functions instead of mouse functions? Have you messed with the "port" settings at all in your room settings? Are you trying to interact with something "in the room" or "in the gui"?
@@PixelatedPope You are a real hero! Saved me again, after almost 2 years! Can I credit you in my game?
@@yukondave8389 Not necessary, but you can if you like. Good luck with your project!
I'm not sure if I'm following this correctly but does your object camera work without putting it in a room? If not, do I have to put it in each room I make?
Create it in a single room early in your game (I do it in the first room) and set it to persistent so you don't have to keep creating it.
@@PixelatedPope Thank you appreciate it
Niceeee! Need more video tutorial!!
I use game maker 1 and it says: "Uknown function or script: surface_resize". Is there something I can do?
surface_resize() is absolutely a GMS1 function. So... try spelling it differently? I'm not sure what to tell ya.
But how do we know what size to make our room in the first place?
That is totally up to you and your art. Again, room size doesn't matter, it's just what base resolution you want your game to be. If you are using really low res pixel art, then try dividing 1920 and 1080 by 4 and see how that looks. If it seems too zoomed in, try 3. Etc.
Hey, is there a way to vertically flip the camera?
These tutorials are amazing!
Why did you stop making videos?
They take a lot of time and energy 😅
Really loving this camera object, but I've been having a couple problems with it. Everything works great until needing to switch rooms, then the camera bugs out. Having the obj_camera be persistent doesn't fix anything, nor does creating a new obj_camera in the new room.
I have no clue why this problem is occurring, but any tips would be incredibly helpful!
I would recommend joining the GM discord server and asking me there. UA-cam comments aren't great for troubleshooting. discord.gg/By6u9pC
I did all the coding that I saw in this video, and nothing's happening. Could someone please tell me what my problem could be.
Did you put an instance of the camera object in your room?
@@PixelatedPope Nope. From what I watched, I didn’t see you do that. As a matter of fact, I don’t even know how to do that.
@@michaelhill1256 You don't know how to drag and drop an instance from your asset list to your room? You may be jumping into the deep end by watching my channel, then. You should probably start with some of the beginner tutorials.
@@PixelatedPope Oh oops. Sorry. I didn’t know what instance meant. But thanks to you, I do now. Thank you for your help. I truly appreciate it. 🙂👍
Hey pope, i know it's a little bit later, but there's anyway to make my camera no shivering? that's because my player_speed are 1, and i've read that view x and y can't be a cracked number, liker 0.50 or 1.50, my player movements cut hspd and vspd in half in diagonals, so, when i move, my player just don't stop shivering, and if i try to floor, the player stops shivering, but the scenario, start to get a little bit unfocused, sorry for my bad english c-c
View positions actually CAN be non-whole numbers. But the easiest way to fix this is to use sub-pixels. Resize your application surface to be the same size as your window, and you'll notice things should stop jittering.
I loved this tutorial and I know its going to help me a ton. I was using another camera system before, but I find this one to be more useful. I do have a question through. For some reason , when i play my game my camera zooms in to my character a bit too much( i think it is because I have the width at 1920/6 and height at 1080/6 in the create event. Is there someway i can fix this because you said the higher the number, the better it is going to look but I do not want the camera to zoom in too much.
Yeah, just go down to 5! The higher the better but not at the cost of how you want your game to look. If it's too close, just step it back. I wouldn't go below 3... but 2 is technically okay as well if you are okay with your game looking absolutely awful on old laptops.
@@PixelatedPope Another question, how about the aspect ratio, so the pixels will look nice and clean (I'm using hand drawn sprites). I was wondering how that would be set up with this system. I saw your other tutorials about aspect ratio, but I don't know which code to put in. And one more question, this may be a dumb one but on the left where you can change the size of the screen in the room, with this code I won't have to do that anymore?
@@slickygreasegames Yup, don't mess with the camera / view settings in the room editor anymore. This code does all that for you.
As for aspect ratios, I would recommend not worrying about them. You don't need to support ultra wide screen, or 16:10 or whatever. Just support 16:9 and be okay with some black bars. Nobody is going to care, and it's really not worth the effort for 99% of GM projects.
@@PixelatedPope One more question. Since my camera zooms in on the character with those settings I have, would I need to shrink the size of the sprites and the background assets to fit with the room?
@@slickygreasegames Not necessarily. You can always increase the size of the view. You also mentioned "hand drawn" sprites... if you aren't doing "pixel art" with hard edges and precise pixels... well, almost none of this matters. You can make your view almost any size you want, including 1920x1080 if your sprites are just that large.
How would you get this to be fullscreen?
window_set_fullscreen(true)
@@PixelatedPope Thanks!
In search of a solution to the problem of pixel distortion, I found myself here, in front of your playlist. These guides were very useful for me, but I still have a question about views and cameras. Is it possible to add a mini-map for a 2D game with camera? If not, are there any alternative methods to manage game resolution and aspect ratio with such possibility?
I'm quite unskilled at GMS.
It's absolutely possible, yes. UA-cam comments aren't exactly the best way to get help with GameMaker, though. I highly recommend joinging the GameMaker Discord server and asking your question there. If I'm around, I'll help you myself. If I'm not, there are lots of friendly, helpful people there to answer questions. Here's a link: discord.gg/gamemaker
When I switch to fullscreen the fps drops from 60 down to 30, then back to 60 when exiting fullscreen. What would be causing this issue? I'm thinking the application surface is being stretched and slowing the performance
That's very possible, especially on something like a 4K monitor. Ideally, you wouldn't always size your app surface to be the same size as your window; it's not really necessary. Instead pick a nice multiple that gives you enough smoothness without being super high res. You could even make it an option for your players to choose smoothness over performance.
I followed this tutorial exactly but my viewport size is the same as the room size. Is this video independent of the earlier videos or am I missing something from them?
Totally independent. You are missing something from THIS video. You sure you got an instance of your camera object in the room? You sure you have your room start event set up correctly?
@@PixelatedPope So I did need an instance in the room. I don't think I saw you place it in the room, but I didn't expect to have seen since I was wondering how the instance will exist across the entire game. Will I have to place an instance manually in every room?
@@Scarabola Nope, just check the "persistent" checkbox in your camera object and you are good to go.
@@PixelatedPope Ok thanks :)
I have a couple questions:
Why do you update the camera view size every step? As far as I can tell you only need to do that once unless you're changing the view size dynamically.
When I start my game there's a small graphical glitch where it displays a squashed frame before filling out the window. Did I do something wrong, is there a way to fix that, or is that just the way it has to work?
That's the way it has to work. Typically you want the first frame of your game to just be black, and then fade into the next thing you want the player to see. Then nothing ugly will be on screen.
As for updating the camera size... there's no reason not to. And if your game supports zooming in or out, then you wouldn't have to change much to support that with this setup. You are welcome to set the view size in the room start event when you enable the view and never touch it again if that's all you need for your project, though.
@@PixelatedPope thanks for the reply. What you suggested about starting on a black frame is what I ended up doing. It felt like I was missing something so it's good to know I wasn't.
Thank you for your videos! I have once used two views for a single-player game and I am curious if you can share why I am wrong as it seemed correct at the time. This was back before GMS by the way. I used one view to follow the character and then a second view layered on top of that but in the bottom right corner as a mini-map / radar. This seemed like a pretty good use case for 2 views on a single-player game but let me know!
Absolutely! It "seems" like a good idea, but it's actually terrible! When you have a second view, every single object in that room runs its draw event for that view. Every. Single. One. I imagine not a single thing visible in your first view was meant to be seen in your second view. Or at least, a very limited number of them. But since you used a second view, EVERY object lined up to run their draw event again. Not to mention other non-object related drawing like all of your backgrounds and tiles. Everything draws for every view. I don't think I need to explain why this can be very bad.
Radars and minimaps can be easily created using a surface, and then you have full control over what is drawn to that surface. This will be much better for performance and it's way easier to manage than positioning views in a room.
@@PixelatedPope Thank you for the good insight! I am still new to utilizing surfaces but I am looking forward to explore them.
Nice job explaining the new system. The one part of setting the view within the room editor that was missing is the concept of view border. I assume that if you wanted to include this aspect with your system, you would calculate it manually rather then using the built-in functions (camera_set_view_border)?
Right. Basically, you take full control over the logic of your camera, so if you only want the camera to move when the object is close to the edge, you can handle that with logic.
@PixelatedPope I have tried a lot with the camera most of them works with my game, but there is one main problem (which happens every time) whenever I add or do something with the camera the same obj moves in a weird way, like the sprite is moving , can you help?
I can probably help with that. Join my Discord server and I or some other member of the server will try to assist. discord.gg/By6u9pC
the velocity of the camera looks like the hotline Miami's camera XD
Been trying to mesh together your first one with this one, but would really love a completely fresh from scratch video based on GMS2. Also a bit confused as to some of the magic numbers, like view_width=1920/6 - you just say that the higher the division number, the better, but don't really go further into it. Any chance you would consider making something like the old part 3, but from scratch in GMS2?
Yeah, I've helped a few people with this exact thing. I could do a future video on that, sure, but who knows when I'll get around to that. For the time being, join my Discord server and ask there, and I or someone else familiar with the topic will help walk you through it and answer any questions you might have. discord.gg/By6u9pC
Alternatively, you could check the pinned comment which is how I've personally meshed the old tutorial and this one. But feel free to reach out with any specific questions.
How do you get rid of that ugly stutter that happens when you start the room?
I usually just use a fade in.
So in another video, I watched they used a split screen to make a minimap for the game. Is there a better way?
MUCH better. Surfaces.
@@PixelatedPope Now... if only I can decode what you just said and somehow apply it to my game. lol anyway, nice video. I tried it but it did not work for me for some reason.
@@DrN0D3-MUSIC If you want some help, I recommend joining my discord server (link in the description). Lots of people, including myself, who can help you with anything GM related!
@@PixelatedPope thanks man. X'D
Nice dude, been waiting for this :)
Hey man, is it expected that Draw GUI events scale up with this setup? How can I prevent that from happening? thanks so much.
use display_set_gui_size() to set the size to whatever you want. Typically you either keep it the same size (like I have) or have it match the window size.
@@PixelatedPope I set the GUI to the window size and it fixed everything, thanks a ton dude
Hey thanks for the tut, I've got a small problem though, while the camera works and follows the player, it doesn't do that slow drag back to the center of the screen for the player character. Did you maybe change something in the other parts of the camera events and not show it? Or am I just missing something?
This is great - one question out of curiosity: why do you start your var names with underscores (eg _x, _y, _spd). is this a common naming convention or just personal habit?
Both? Sometimes I tell myself I started the trend. It was more important back in GMS1 and earlier when variables didn't have different colors, but it's a good idea to differentiate your vars from your instance variables. And the easiest way to do that consistently and make it immediately recognizable at a glance is with some sort of special character. The other advantage is being able to reuse common variable names.
For example, say you are looping through the rows and columns of a ds_grid with a for loop. Many would do something like this:
for(var i=0; i
@@PixelatedPope thanks, great explanation!
Jesus man. I'm so grateful for your tutorials. I've dropped my project for months because I couldn't understand why some tiles were stretched during camera movement. I haven't yet tried your dynamic scaling solution but once I get off from work, I'll try it out. I really hope this solves the problem. I still have one question tho: Is it possible to get an invite to your discord server and ask you or the other experts for advice if any errors or problems might occur. Do I need to pay for the help or how do you provide it? free if the time suits you? I'd be also glad to show you my not so impressive platform game in the progress.
sadly im not sure what im doing wrong, this camera object seems to change nothing in the game. it simply looks the same with and without the object. changing the scale and other variables simply made no effect either as if the game just ignores this objects code and i have absolutely 0 clue why. my game is a platformer rather than top down but that shouldnt be an issue i dont think. anyone else have or had this issue?
i created a whole new test game to see if it would work and it did. ive no clue why in oneproject itseems to do nothing and in the other works perfectly. maybe there are some room camera or view settings that can affect this that i touched? id rather not just build my project back up from scratch if i can avoid it.
ok PROTIP: NEVER change the filenames of your project from file explorer. just save as new project name. I changed the project name in windows file explorer and it really messed some things up. i clicked save as template and saved it all thankfully, and now camera is working well :D
GOODNESS GRACIOUS im going crazy thinking about aspect ratios and resolution multiples
So I've been getting really disheartend with the room editor's camera controls. Thank you soo much! I can carry on with my project now!
Nice! If you are ever feeling disheartened and want to commiserate with other GM users, make sure you join the Discord server! We'll help you get over whatever has ya down! discord.gg/By6u9pC
@@PixelatedPope I don't know why it took me so long to see this! Thank you again
how do you function with big light on?