GameMaker Studio 2 - Minimap Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the first thing you want to do when making a mini-map is establish your minimap's background the best approach for this and for most of the mini-map as a feature in general is going to vary a lot based on your game please bear with me a little in this video as i'm going to be bringing up a lot of what-ifs based on what type of game or mini-map you're making it really helps if you can pre-bake this in some way maybe even create a fixed sprite of your map's background though that could be difficult to maintain the most generic approach to this i think though is to dynamically grab a snapshot of your room and shrink it down depending on your game you might only have to do this once at the very start of a given level or map or you might have to refresh it from time to time so in this minimap object that i've created to handle the whole minimap i've made a function that will do just that we make a surface the size we want our minimap to be for me i'm using a modified room from my rpg series link in the description and it's a pixel art game with tiled artwork so a very convenient size is just the room size divided by the size of my tiles in this case 16 pixels it's worth pointing out if your rooms are very large or your art is much higher definition a lot of games are going to need different sizes and resolutions for even pixel art i metaphorically and literally can't give you a one size fits all solution here but you probably want the minimap to be the same aspect ratio meaning whatever division you apply to the width applied to the height as well then we temporarily make a surface the size of the whole dang room and we draw our tile map to that surface along with whatever other static or mostly static background elements or tile maps you might have the more stuff you can include here that you don't need to constantly update the better don't include moving things like units or whatever in this though we'll do that later once we're done we draw the surface stretch down to the smaller surface don't be tempted to use surface underscore resize that does not actually stretch or crop a surface it deletes everything on it and then resizes it you have to draw from one surface to another to scale it like this once we have our background function we want to call it once and generally avoid calling it again unless we have to call it when some major change happens in your background if scenery gets destroyed or whatever but generally use this for stuff that won't change in our example our room is pretty small but it could be quite easy depending on your game to make this function quite expensive quite quickly then i use the draw gui step or if you're comfortable drawing to your camera coordinates you can use the normal drawer or draw end or whatever too first of all we draw that background we made first checking if it still exists as surface data can be pretty volatile just losing focus on the window is enough to wipe surface data sometimes so we check if it exists and if it doesn't we make it again then we draw it where we want it i'm just using the x and y of the object as screen relative coordinates here i set them both to 15 and the create event next up we draw all of our moving entities enemies whatever it is you want to track on the mini-map we draw this to a different surface that is the same size as our background surface we draw black with zero alpha to clear the entire surface then with every entity in our game the with function can make this very easy if you use an entity system we check to see if they have a flag for being drawn to the minimap and if they do we draw a special minimap sprite in this case i've made that sprite a single white pixel you might ask why not to use draw and score point or whatever and yes that could work in this example but is just less flexible a pixel is a convenient size for us because in our situation one pixel equals one tile and gives a very accurate depiction of where the entity is on our map your game may vary and you might want to scale the pixel or draw a different sprite entirely there are two entity types i have in the room and i have flagged the slime to be drawn to the map as it's like an enemy or whatever and the plants i've marked to not draw to the minimap you could add tons of extra stuff to your entity object that controls what sprite they draw how big it should be what color it should be etc here i'm just drawing slimes so i've defaulted them all to be red here be an enemy pixel uh in a kind of traditional style when we're done drawing these entities we reset the surface target and draw the surface to the screen at the same position as our background so it sits cleanly on top next up you possibly want to draw the position of the camera on the map and even use the minimap as a way to jump your view around the map we'll start by drawing this and come back to the interaction part later here i grab the x and y of the top left of the camera translated to a position on our minimap again this is just by dividing by that same value the minimap is just a smaller version of our room in theory so we can always get minimap coordinates by just doing this the sprite i'm drawing is actually a tiny nine sliced white pixel rectangle again i could use draw underscore rectangle but this gives you more flexibility i have a video on nine slicing if you don't know how this feature works in game maker you could also create a sprite the exact size of your view scaled down to fit but again this feels more flexible to me remember we're drawing this directly on top of the map rather than to the surface though you could draw it to the surface if you wanted so we need to include the x and y position of the minimap on screen in the coordinates the width and height of the box are going to be again the width and height of the view in the room divided by the same value as everything else has been to convert them to minimap coordinates lastly i draw a nice border around the minimap which is just another nine sliced box do whatever you want here this is what we have so far looking good last step is to control the position of the camera on the map so for a larger game i would generally recommend controlling mouse behavior somewhere universal having a mouse object or something so you don't get conflicts between the different actions you might take with the mouse cursor but for this example i've just done a mouse check in the step event i get the mouse position on the screen adjusted for the camera we check if we press the mouse button and that position is inside the minimap then we just move the camera to the point we clicked on the map multiplied by whatever our map's scale is in this case as before it's our tile size my camera object also has x2 and y2 which are variables that tell the camera to scroll towards a particular spot so i have to update those two when i move it do whatever you want for however your camera works or just use camera underscore set underscore view underscore pause if you just use the default view system for your camera and there you go that's the basics of setting up a mini map in the most generic way i could think of hopefully that helps if you want to help decide future tutorial topics use the form in the description to submit suggestions that my patreon supporters can later vote on my videos are funded almost entirely by my patreon supporter so a huge thanks to them for helping provide this video for you thank you all for watching and i'll catch you all next time
Info
Channel: Shaun Spalding
Views: 3,358
Rating: undefined out of 5
Keywords: Game Maker (Video Game Engine), Tutorial, GameMaker Tutorial, GameMaker, Game Development, Indie Games, Tutorial Series, Game Maker Studio, Making Games, How to make games, GameMaker Studio 2, GMS, GMS2
Id: sIfJy0-NTTA
Channel Id: undefined
Length: 6min 6sec (366 seconds)
Published: Fri Dec 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.