GML Minimap Tutorial

  • Thread starter Deleted member 16767
  • Start date
D

Deleted member 16767

Guest
GM Version: Made with GMS2
Target Platform: ANY
Download: No download required

Note: I don't use semi-colon in the video, but it's recommended to be used.


This is how you make a mini map easy and without any hassle!

Your solid wall sprite must have it's collision mask middle centered in the sprite editor for this to work accurately. My player sprite has it's collision mask bottom centered.

Children objects will adapt with the mini map. If you made your collision mask the wrong way, you can always make a duplicate object and make it a child to the
previous solid object. Don't forget to put the duplicated sprite with the new collision mask centered on the object!

Now, lets start with the coding.

Add this to a script called scr_minimap (edit the object names to be your object names):

Code:
var _x, _y, _s;
_x = argument0;
_y = argument1;
_s = argument2;

draw_rectangle_color(_x,_y,_x+room_width/_s,_y+room_height/_s,c_white,c_white,c_white,c_white,1);  //Draws the minimap

with (solid_wall)
{
draw_set_color(c_white); //Color of the object on the minimap
draw_rectangle(_x+x/_s-sprite_width/(2*_s),_y+y/_s-sprite_height/(2*_s),_x+x/_s+sprite_width/(2*_s),_y+y/_s+sprite_height/(2*_s),0); //_s means size. Do not edit out sprite_width and sprite_height!

sprite_collision_mask(-1,true,0,-1,-1,-1,-1,0,0);  //This will make your objects dragable so you won't need to alt + click the objects one by one

//This gives the minimap a fog
if distance_to_object(obj_Player_Wizard) < 1200
    {
        draw_set_alpha(1);
    }
 else
    {
        draw_set_alpha(0);
    }
 
}

//This could be an item on the minimap
with (herbs_harvestable)
{
draw_set_color(c_yellow);
draw_rectangle(_x+x/_s-sprite_width/(2*_s),_y+y/_s-sprite_width/(2*_s),_x+x/_s+sprite_width/(2*_s),_y+y/_s+sprite_width/(2*_s),0);
}


//This is the player
with (obj_Player_Wizard)
{
draw_set_alpha(1);
draw_set_color(c_aqua);
draw_circle(_x+x/_s-sprite_width/(2*_s),_y+y/_s-sprite_width/(2*_s),4,0);
}
Then make an object called obj_minimap.

In the create event, write this.

Code:
wview = view_wport[0];
hview = view_hport[0];
In the draw GUI event, write this:

Code:
if keyboard_check(vk_tab)
{
scr_minimap(wview/6,hview/6,25);
}
else
{scr_minimap(wview/1.4,hview/1.5,50);} //This means the position of it and lastly the size of it. Configure it to your needs!
 
Last edited by a moderator:
Top