L
LiamCollie
Guest
Hello! I'm extremely new to GMS2 and I am learning GML2 along with a video on YT from CosmoAstronaut's series Farm RPG.
And I am at the point of room transitions and with the playerFacingAfter through the game object and what not.
My issue is, when I go to the transition object I made after doing all the code in game object, player object etc. When I transition to the next room, my player is facing downward, regardless what I ser "playerFacing = dir.up ;"
But in the code for the playerFacingBefore works just fine. I am not using the same sprites as she is mine are are different in size.
Right here is my transition object's creation code.
Player code create;
Player Step;
Player Draw;
-------------
And this here is my game object code
Create:
Draw GUI
Room Start;
---------------
This here is my object transition create code
--------------
This is my room 1 room settings, not sure if this matters or not.
And the forest room;
Maybe I should also add the camera code as well.
Camera Create;
Step;
---------------
I know absolutely nothing about GML and I just been following along with the Farm RPG tutorial, and maybe my screw up is not using the same sprites exactly? I dont know, I am new at this lol I really love GMS2 and really enjoying it, but I been trying to go back and figure out, why the playerFacingAfter part isnt doing anything.
Cuz in the end, I want to make something simular to Stardew/Harvest Moon then more RPG based stuff as in like Final Fantasy inspired (Grew up playing that on SNES <3 )
But yeah, any pointer any help is highly appreciated
Thank you for your time
And I am at the point of room transitions and with the playerFacingAfter through the game object and what not.
My issue is, when I go to the transition object I made after doing all the code in game object, player object etc. When I transition to the next room, my player is facing downward, regardless what I ser "playerFacing = dir.up ;"
But in the code for the playerFacingBefore works just fine. I am not using the same sprites as she is mine are are different in size.
Right here is my transition object's creation code.
Player code create;
Code:
w_spd = 1;
n_spd = 2;
r_spd = 3;
spd = n_spd;
x_frame = 0;
y_frame = 0;
facing = 0;
Code:
//---INPUT
input_left = keyboard_check(vk_left) ;
input_right = keyboard_check(vk_right) ;
input_up = keyboard_check(vk_up) ;
input_down = keyboard_check(vk_down) ;
input_walk = keyboard_check(vk_control) ;
input_run = keyboard_check(vk_shift) ;
//--- ALTER SPEED
if(input_walk or input_run) {
spd = abs((input_walk*w_spd) - (input_run*r_spd) ) ;
} else {
spd = n_spd;
}
//---RESET MOVE VARIABLES
moveX = 0;
moveY = 0;
//---INTENDED MOVEMENT
moveY = (input_down - input_up) * spd;
if(moveY == 0) { moveX = (input_right - input_left) * spd; }
//---COLLISON CHECKS
//Direction Facing
if(moveX != 0) {
switch(sign(moveX) ) {
case 1: facing = dir.right; break;
case -1: facing = dir.left; break;
}
} else if(moveY != 0) {
switch(sign(moveY) ) {
case 1: facing = dir.down; break;
case -1: facing = dir.up; break;
}
} else {
facing = -1;
}
//Objects
var inst = instance_place(x,y,obj_transition) ;
if(inst != noone and facing == inst.playerFacingBefore) {
with(game) {
if(!doTransition) {
spawnRoom = inst.targetRoom;
spawnX = inst.targetX;
spawnY = inst.targetY;
spawnPlayerFacing = inst.playerFacingAfter;
doTransition = true;
}
}
}
//Horizontal
if(moveX != 0) {
if(place_meeting(x+moveX, y, obj_collision) ) {
repeat(abs(moveX) ) {
if(!place_meeting(x+sign(moveX) , y, obj_collision) ) { x += sign(moveX); }
else { break; }
}
moveX = 0;
}
}
//---Vertical
if(moveY != 0) {
if(place_meeting(x, y+moveY, obj_collision) ) {
repeat(abs(moveY) ) {
if(!place_meeting(x+sign(moveX) , y, obj_collision) ) { x += sign(moveX); }
else { break; }
}
moveY = 0;
}
}
//---APPLY MOVEMENT
x += moveX;
y += moveY;
Code:
var anim_length = 3;
var anim_speed = 5;
var frame_size = 22;
switch(facing) {
case dir.left: y_frame = 6; break;
case dir.right: y_frame = 1; break;
case dir.up: y_frame = 4; break;
case dir.down: y_frame = 0; break;
case -1: x_frame = 0; break;
}
//--- Draw Sprite
draw_sprite_part(spr_player,0, floor(x_frame)*frame_size, y_frame*frame_size, frame_size, frame_size,x,y,);
//---Speed Increment
if(x_frame < anim_length -1) { x_frame += anim_speed/60; }
else { x_frame = 0; }
And this here is my game object code
Create:
Code:
///description
randomize() ;
room_goto_next()
guiWidth = display_get_gui_width() ;
guiHeight = display_get_gui_height() ;
blackAlpha = 0;
spawnRoom = -1;
spawnPlayerFacing = -1;
doTransition = false;
spawnX = 0;
spawnY = 0;
enum dir {
right = 0,
up = 90,
left = 180,
down = 270,
}
Code:
if(doTransition) {
//BlackFade/RT
if(room != spawnRoom) {
blackAlpha += 0.1;
if(blackAlpha >= 1) { room_goto(spawnRoom) }
} else {
blackAlpha -= 0.1;
if(blackAlpha <= 0) { doTransition = false; }
}
draw_set_alpha(blackAlpha) ;
draw_rectangle_colour(0,0, guiWidth, guiHeight, c_black, c_black, c_black, c_black, false)
draw_set_alpha(1) ;
}
Code:
if(spawnRoom == -1) exit;
obj_player.x = spawnX;
obj_player.y = spawnY;
obj_player.facing = spawnPlayerFacing;
with(obj_player) {
switch(facing) {
case dir.left: y_frame = 6; break;
case dir.right: y_frame = 1; break;
case dir.up: y_frame = 4; break;
case dir.down: y_frame = 0; break;
}
}
This here is my object transition create code
Code:
targetRoom = -1;
targetX = 0;
targetY = 0;
playerFacingBefore = -1;
playerFacingAfter = -1;
This is my room 1 room settings, not sure if this matters or not.
And the forest room;
Maybe I should also add the camera code as well.
Camera Create;
Code:
following = obj_player;
h_border = 60;
v_border = 30;
Code:
x = clamp(x, following.x-h_border, following.x+h_border) ;
y = clamp(y, following.y-v_border, following.y+v_border) ;
I know absolutely nothing about GML and I just been following along with the Farm RPG tutorial, and maybe my screw up is not using the same sprites exactly? I dont know, I am new at this lol I really love GMS2 and really enjoying it, but I been trying to go back and figure out, why the playerFacingAfter part isnt doing anything.
Cuz in the end, I want to make something simular to Stardew/Harvest Moon then more RPG based stuff as in like Final Fantasy inspired (Grew up playing that on SNES <3 )
But yeah, any pointer any help is highly appreciated
Thank you for your time