GameMaker Studio 2 is the latest and greatest incarnation of GameMaker! It has everything you need to take your idea from a concept to a finished game. With no barriers to entry and powerful functionality, GameMaker Studio 2 is the ultimate 2D development environment!
A game project for Gamemaker Studio 2 that goes with a tutorial that runs you through making a player map that scales your world down to a surface that you can then draw onto the GUI layer.
Create Event
/// @description Set Up UI
//Variables
show_map = false;
selection = noone;
map_divider = 5;
mouse_x_gui = 0;
mouse_y_gui = 0;
//Make Surfaces
win_width = window_get_width();
win_height = window_get_height();
surface_width = win_height; //=
surface_height = win_height; //=
surface_margin_x = (win_width/2) - (surface_width/2);
surface_margin_y = (win_height/2) - (surface_height/2);
map_x = (surface_width/2);
map_y = (surface_height/2);
map_surface = surface_create(surface_width,surface_height); //Create surface
//Dragging Variables
dragging = false;
drag_x = 0;
drag_y = 0;
drag_offset_x = 0;
drag_offset_y = 0;
////SMOOTH DRAG AND ZOOM\\\\
//Smooth Move
drag_move_x = 0;
drag_move_y = 0;
//Zoom
map_max_zoom = 20; //Max zoom level
Draw GUI Event
/// @description Draw UI
if show_map {
/// DRAW MAP SURFACE \\\
surface_set_target(map_surface);
//Clear surface//
draw_clear(c_dkgray); //Background Colour - (Black works best most of the time);
//Draw grid//
draw_sprite_tiled(grid_sprite,0, map_x, map_y);
//Draw map objects\\
draw_map_object(player, c_white, true);
draw_map_object(friendly, c_lime, true);
draw_map_object(enemy, c_red, true);
draw_map_object(item, c_aqua, false);
//Reset Surface
surface_reset_target();
///DRAW UI\\\\
//Darken
draw_set_color(c_black); //Set colour
draw_set_alpha(0.4); //Set transparency
draw_rectangle(0,0,win_width,win_height,false);
//Reset colour & transparency
draw_set_color(-1);
draw_set_alpha(1);
//Draw map surface
draw_surface(map_surface, surface_margin_x, surface_margin_y);
}
Step Event
/// @description Math
if show_map = true {
//Update mouse to GUI position//
mouse_x_gui = device_mouse_x_to_gui(0);
mouse_y_gui = device_mouse_y_to_gui(0);
//Dragging//
if dragging = false and mouse_check_button(mb_left) {
//Set drag from point
drag_x = drag_offset_x + mouse_x_gui;
drag_y = drag_offset_y + mouse_y_gui;
dragging = true; //Start dragging
}
//Drag map view
if dragging = true {
drag_offset_x = drag_x - mouse_x_gui;
drag_offset_y = drag_y - mouse_y_gui;
}
if dragging = true and mouse_check_button_released(mb_left) {
dragging = false; //Unset dragging
}
//Calculate the point on the map surface everything should be drawn relative to//
map_x = (surface_width/2) - (player.x/map_divider) - drag_offset_x;
map_y = (surface_height/2) - (player.y/map_divider) - drag_offset_y;
////SMOOTH DRAG AND ZOOM\\\\
///Smooth Move Drag\\\
var x_m = drag_offset_x;
var y_m = drag_offset_y;
var m_pd = point_distance(drag_move_x, drag_move_y, x_m ,y_m)/10;
var speed_m = m_pd;
var angle = point_direction(drag_move_x, drag_move_y, x_m ,y_m);
drag_move_x = drag_move_x + lengthdir_x(speed_m, angle);
drag_move_y = drag_move_y + lengthdir_y(speed_m, angle);
//Zoom Function//
if mouse_wheel_down() {
if map_divider < map_max_zoom { map_divider += 0.1*map_divider; // Zoom Out
}}
if mouse_wheel_up() {
if map_divider > 0.1 { map_divider -= 0.1*map_divider; // Zoom In
}}
//Calculate the point on the map surface everything should be drawn relative to//
map_x = (surface_width/2) - (player.x/map_divider) - drag_move_x;
map_y = (surface_height/2) - (player.y/map_divider) - drag_move_y;
}
Begin Step Event
/// @description Recreate Surfaces
//Recreate surfaces if they disappear//
if !surface_exists(map_surface) { map_surface = surface_create(surface_width,surface_height);}
Key Press TAB or Key Press "M" Event
show_map = !show_map;
/// @description Free map surface
if surface_exists(map_surface) { surface_free(map_surface);}
Global Mouse Right Pressed Event
/// @description Deselect
selection = noone;
Global Mouse Middle Pressed Event
/// @description Reset View
dragging = false;
drag_offset_x = 0;
drag_offset_y = 0;
Draw_Map_Object Script
/// @description draw_map_object()
///@param obj 0
///@param colour 1
///@param ind 2
with argument0 {
var m_x = (x / UI.map_divider) + UI.map_x;
var m_y = (y / UI.map_divider) + UI.map_y;
var m_gui_x = UI.mouse_x_gui - UI.surface_margin_x;
var m_gui_y = UI.mouse_y_gui - UI.surface_margin_y;
var map_sprite = map_dot; //=
var p_in_circle = point_in_circle(m_gui_x, m_gui_y, m_x, m_y, sprite_get_width(map_sprite));
var mb_left_pressed = mouse_check_button_pressed(mb_left);
//Select object
if mb_left_pressed and p_in_circle {
UI.selection = self;
}
//Draw dot
draw_sprite_ext(map_sprite,0 ,m_x, m_y, 1,1, 0, argument1, 1);
//Draw Selector//
if UI.selection = self {
//Text
draw_set_halign(fa_center);
draw_set_valign(fa_bottom);
draw_text(m_x, m_y-20, name);
//Marker
draw_sprite(marker_sprite, 0, m_x, m_y);
}
//Draw indicator
if argument2 = true {
draw_sprite_ext(direction_sprite,0, m_x, m_y, 1,1, image_angle, argument1, 1);
}
}