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
Depth Sorting
(step event for PLAYER)
(create event for OTHER OBJECTS)
//depth depth=-bbox_bottom;
bbox is the collision box. this makes the bottom of the collision box a negative number. THE LOWER THE NUMBER, THE HIGHER THE OBJECT DEPTH PRIORITY
Ex. an object at -10 will have their sprite show up on top of an object at -5
Objects with the Same Collision Masks (Reducing Clutter)
- If you know multiple objects will have the same collision mask, you can make multiple sprites in the frames of a single sprite and set the fps to 0
- you can then place the object and change the frame to achieve the sprite you want
Room Order
Room at the top of the list is where the game will start
obj_warp_block (general)
(create event)
target_x = 0; target_y = 0; target_rm = 0; target_face = 0;
(step event)
//warp blocks if place_meeting( x, y, obj_player) && !instance_exists(obj_warp) { var inst = instance_create_depth( 0, 0, -9999, obj_warp ); inst.target_x = target_x; inst.target_y = target_y; inst.target_rm = target_rm; inst.target_face = target_face; }
Ensure the warp block object is actually touchable by the player when placing it
“var inst” is a local variable (a variable only needed in the one event it’s put into; it won’t be referenced by code outside this event)
“&& !instance_exists(obj_warp)” is to ensure an obj_warp is not created every frame the player is touching the warp block [ “!” means “not” ]. it will only run the code if the warp object does not currently exist.
obj_warp_block (placed)
Set obj_player to “persistent” by checking box in object options
After placing obj_warp_block, click on it and select “Creation Code”
Add and change the 0s in the following code to desired coordinates, room, and face after warping:
target_x = 0; target_y = 0; target_rm = 0; target_face = 0;
remember to uncheck “visible” when done editing the warp block
Creation Code
Adds code to every individual instance of the selected object and will run immediately after the create event
Warping Between Rooms (obj_warp)
Create obj_warp using your room transition animation as the sprite and set it as “persistent”
(create event)
target_x = 0; target_y = 0; target_rm = 0;
(step_event)
if room == target_rm && image_index < 1
{
instance_destroy();
}
(draw event)
var _camx = camera_get_view_x(view_camera[0]); var _camy = camera_get_view_y(view_camera[0]);
draw_sprite_tiled(sprite_index, image_index, _camx, _camy);
(animation end event)
room_goto(target_rm);
obj_player.x = target_x;
obj_player.y = target_y;
obj_player.face = target_face;
image_speed = -1;
setting image_speed to -1 will make the animation play in reverse once the animation has ended
draw_sprite_tiled (rather than draw_sprite) will tile the sprite across the entire room
don’t use if image_index = 0 in the step event because the image index usually has a decimal point to ensure the animation is running at the correct speed
obj_pauser (pausing the player during room transitions)
in obj_player
(step event)
(between “//get xspd and yspd” and “//set sprite”)
//pause if instance_exists(obj_pauser) { xspd = 0; yspd = 0; }
make obj_pauser the parent object of obj_warp
forces the player’s speed to 0 while obj_pauser exists
Parallax Backgrounds
Visually disable the “Background” layer
Make a background that is the same size as the camera
Make obj_parallax_background
(create event)
depth = 10000;
(draw event)
var _camx = camera_get_view_x(view_camera[0]); var _camy = camera_get_view_y(view_camera[0]);
var _p = 1;
draw_sprite_tiled(bg_name, 0, _camx_p, _camy_p);
IF YOU WANT A SUB-IMAGE: draw_sprite_tiled(bg_name, 1, _camx.25, _camy.25);
the lower the number value of var _p, the closer the background will appear
.25 is an example number for the sub image code, it just needs to be >_p
the second variable in draw_sprite_tiled is the sprite frame