RPG Basics Flashcards
Adjusting Camera and Viewport
Within room properties:
- enable viewports
- set viewport[#] to visible
- set camera properties:
- 288 x 216 is 4:3 ratio (ex. Undertale), 1920 x 1080 is 16:9 (modern; ex. Hollow Knight)
- set viewport properties:
- multiply camera ratio by some whole number
- -input object for Object Following
- –set horizontal and vertical borders to half the camera ratio to have the camera stay centered on the followed object when it moves
Setting Player Speed
(create event)
xspd = 0; yspd = 0;
mv_spd = #;
What is a create event
Used for initializing variables
Runs once when an object is loaded
What is a step event
Runs every single frame of the game
Binding Arrow Keys
(step event)
//set movement keys right_key = keyboard_check(vk_right); left_key = keyboard_check(vk_left); up_key = keyboard_check(vk_up); down_key = keyboard_check(vk_down);
Binding WASD Keys
(step event)
//set movement keys d_key = keyboard_check(ord("D")); w_key = keyboard_check(ord("W")); a_key = keyboard_check(ord("A")); s_key = keyboard_check(ord("S"));
Get X & Y Speed
(step event)
//get xspd and yspd xspd = (right_key - left_key) * mv_spd; yspd = (down_key - up_key) * mv_spd;
OR
//get xspd and yspd
xspd = (a_key - d_key) * mv_spd;
yspd = (s_key - w_key) * mv_spd;
Moving the Player
(step event)
BELOW COLLISIONS
//move the player
x += xspd;
y += yspd;
Setting Collisions
(step event)
BELOW SETTING SPRITE
//collisions if place_meeting( x + xspd, y, obj_wall ) == true { xspd = 0; } if place_meeting( x, y + yspd, obj_wall ) == true { yspd = 0; }
Setting Sprite
(step event)
ABOVE COLLISIONS (else xspd & yspd gets set to 0 and it interferes with changing directional faces properly)
//set sprite mask_index = sprite[DOWN];
if yspd == 0 { if xspd > 0 {face = RIGHT}; if xspd < 0 {face = LEFT}; } if xspd > 0 && face == LEFT {face = RIGHT}; if xspd < 0 && face == RIGHT {face = LEFT}; if xspd == 0 { if yspd > 0 {face = DOWN}; if yspd < 0 {face = UP}; } if yspd > 0 && face == UP {face = DOWN}; if yspd < 0 && face == DOWN {face = UP};
sprite_index = sprite[face];
- Lines such as “if xspd > 0 && face == LEFT {face = RIGHT};” fix the issue of sprite faces not adjusting properly if the object goes from not moving to moving at a diagonal
- “mask_index = sprite[DOWN];” sets all sprite collision masks to the same as the indicated sprite
Setting Animations
(step event)
BELOW COLLISIONS
//animate if xspd == 0 && yspd == 0 { image_index = 0; }
(SET ALL FACE SPRITES TO THE SAME ORIGIN POINT)
Makes an unmoving object stay at indicated image index frame instead of animating
Setting up Macros (constants)
(script)
#macro RIGHT 0 #macro UP 1 #macro LEFT 2 #macro DOWN 3
Assigning Directional Sprites
(create event)
REQUIRES MACRO (else use 0-3)
sprite[RIGHT] = spr_player_right; sprite[UP] = spr_player_up; sprite[LEFT] = spr_player_left; sprite[DOWN] = spr_player_down;
face = DOWN;
Wall Layer
- Place obj_wall in a separate layer from Instances
- When finished placing walls, turn layer visibility off
- Adjust obj_wall opacity to not visually obscure parts of rooms
Parent and Child Objects (& Expanding Collision)
- When setting a parent object for any object, this means anytime the game references/checks the parent object, the game will also reference/check any object that is a child of it
- Making obj_wall a parent object will then reference the collision coding, allowing collision with child objects without writing them all into the code