"Dear friends! If you enjoyed the video, please give it a like and subscribe to the channel. We strive to share with you the lost knowledge of the great prophet and teacher of GameDev, Sempiternal Rain. With these lessons, you'll learn the GameMaker Studio game engine. Learn programming in Game Maker Language (GML). And in the future, you'll be able to easily create virtually any 2D game for video consoles, computers, and phones."
Description and tips below. Enjoy!
VK Community:
sempiternalrainnotes - Sempiternal Rain: Notes
(Chat, news, and community available - Subscribe!)
Games created by the great prophet of the gaming industry, Sempiternal Rain. You can purchase them on Steam:
1. "Socialism Simulator"
2. "ReLinked"
You can purchase them on Steam)
-------------------------------------------------------------------
Lesson Title:
GameMaker Studio - Lesson #14: Working with the Mouse
Lesson Description:
In this video, you'll learn how to work with the mouse, including how to make objects follow the mouse.
Timecodes:
00:01 - Mouse Coordinates
00:44 - Click Types
04:45 - Event Handling via Code
08:04 - Following the Mouse
-------------------------------------------------------------------
*******
Mouse Coordinates
mouse_x
mouse_y
Mouse Click Types
1. Object Click
2. Global Click
Action Types
Pressed - Press, Single Click
Down - Hold
Released - Release
Mouse Enter - Hover over an object
Mouse Leave - Move away from an object
Mouse Wheel Up - Rotate the mouse wheel up
Mouse Wheel Down - Rotate the mouse wheel down
Global - Click anywhere on the screen (not on an object)
Event Handling
mb_any - Press any mouse button
mb_left - Press the left mouse button
mb_right - Press the right mouse button
mb_middle - Press the middle mouse button
mb_none - Do not press any mouse buttons
Checking if a mouse is pressed
mouse_check_button(key name) -
mouse_check_button_pressed(key name)
mouse_check_button_released(key name)
mouse_wheel_down()
mouse_wheel_up()
instance_position(mouse_x, mouse_y) // whether the mouse is hovering over the object if instance_position(mouse_x, mouse_y, self)
display_mouse_set(x,y)
window_mouse_set(x,y)
*******
*******
Ob_main
*Draw
draw_text(x,y, string(mouse_x) + ", " string(mouse_y)) //display mouse coordinates on the screen
display_mouse_set(100,100); // move the mouse cursor 100,100 relative to the screen
window_mouse_set(100,100); // move the mouse cursor 100,100 relative to the game screen
*Global Left Down //when holding down the left mouse button
instance_create_depth(mouse_x, mouse_y, 0, Ob_enemyKnight); //create the object
*Global Left Presed //when pressing the left mouse button once
instance_create_depth(mouse_x, mouse_y, 0, Ob_enemyKnight); //create an object
Ob_enemyParent
*Mouse Enter //when the mouse moves toward the object
image_blend = c_red; //recolor the object red
*Mouse Leave //when the mouse moves away from the object
image_blend = c_white; //remove the object's recolor
*Steps
if (hp<=0)
{
instance_destroy();
}
if (mouse_check_button(mb_left)) //if the left mouse button is pressed
{
instance_destroy();
}
*******
Ob_enemy
Ob_player
*Global Left Down //click anywhere on the screen
dir = point_direction(x,y,mouse_x, mouse_y); From x,y to mouse_x, mouse_y
if distance_to_point(mouse_x, mouse_y)>5 //fix the twitching bug
{
move_toward_point(mouse_x, mouse_y,5); //move to x,y with a speed of 5
motion_set(dir,5); //another way to move, dir is the direction, 5 is the speed
image_angle=dir; //rotation angle
}
else
{
speed=0;
}
*Global Left Released //release the mouse anywhere on the screen
speed=0; //object speed
///////////////////////////////////////////////////////////////////////////
Tags:
#gamemaker, #programming, #training, #mousemovement, #mouse