A
Aardvark
Guest
Hi!
I'm fairly new to GMS 2 and GML but I'm a quick learner.
I've set-up basic animations for my player based on the direction it's going (8 directions). What I'd like to do is start a frame by frame animation from a given tile set after the player is idle for let's say 5 seconds.
Here is what I have so far :
CREATE EVENT
STEP EVENT :
I'll skip all the key detections, diagonal speed correction and collision stuff, only the timer logic :
DRAW EVENT :
The "Light" animation is what I want to draw over after a 5 seconds idle.
x_frame is the X location on the tile set, y_frame is the Y location on the tile set.
There is clearly something I don't understand, I want to loop the sprite part on the last y_frame location, in the x_frame direction, until the player move again. but nothing appears. The x_frame seems to only increment 1 frame and stalls there.
Any ideas?
Thanks!
I'm fairly new to GMS 2 and GML but I'm a quick learner.
I've set-up basic animations for my player based on the direction it's going (8 directions). What I'd like to do is start a frame by frame animation from a given tile set after the player is idle for let's say 5 seconds.
Here is what I have so far :
CREATE EVENT
Code:
/// @description Key variables
//---------PLAYER SPEED
spd = 0; //Horizontal and vertical speed
//grv = 0.3; //Gravity speed
n_spd = 3; //Walk speed
r_mod = 1.5; //Run speed modifier
d_mod = 1/sqrt(2); //Diagonal speed modifier
r_spd = r_mod*n_spd; //Run speed
//---------CHARACTER SPRITE
x_frame = 0;
y_frame = 0;
x_offset = sprite_get_xoffset(mask_index);
y_offset = sprite_get_yoffset(mask_index);
spr_base = spr_player;
spr_idle = spr_player_idle;
//---------IDLE AMINATION TIMER
room_speed = 60;
idl_anim_timer = room_speed * 5;
I'll skip all the key detections, diagonal speed correction and collision stuff, only the timer logic :
Code:
if (moveX == 0 && moveY == 0) idl_anim_timer -= 1;
else idl_anim_timer = room_speed * 5;
Code:
/// @description Draw Player
// You can write your code in this editor
var anim_length = 8; //Number of frame per loop
var frame_size = 64;
var anim_speed = 48;
var anim_speed_idle = 20;
if (moveY < 0) && (moveX == 0) y_frame = 0; //Frames for UP direction
else if (moveX < 0) && (moveY == 0) y_frame = 1; //Frames for LEFT direction
else if (moveY > 0) && (moveX == 0) y_frame = 2; //Frames for DOWN direction
else if (moveX > 0) && (moveY == 0) y_frame = 3; //Frames for RIGHT direction
else if (moveX < 0) && (moveY < 0) y_frame = 4; //Frames for UPLEFT direction
else if (moveX < 0) && (moveY > 0) y_frame = 5; //Frames for DOWNLEFT direction
else if (moveX > 0) && (moveY > 0) y_frame = 6; //Frames for DOWNRIGHT direction
else if (moveX > 0) && (moveY < 0) y_frame = 7; //Frames for UPRIGHT direction
else x_frame = 0; //Frame while not moving
var xx = x - x_offset;
var yy = y - y_offset;
if (x_frame + (anim_speed/60) < anim_length) { x_frame += anim_speed/60; }
else if (x_frame < anim_length - 1) && (key_run) { x_frame += (r_mod*anim_speed)/60; }
else { x_frame = 0; }
//---------DRAW SPHERE BASE
//spr_base is the tile containing all the sphere frames
draw_sprite_part(spr_base, 0, floor(x_frame)*frame_size, y_frame*frame_size, frame_size, frame_size, xx, yy);
//---------DRAW SPHERE LIGHT AFTER IDLE
if (moveX == 0 && moveY == 0 && idl_anim_timer < 0) {
//Draw timer for troubleshooting
draw_set_color(c_white);
draw_text(50, 50, "Timer: " + string(idl_anim_timer));
draw_text(50, 70, "Timer in seconds: " + string(idl_anim_timer/room_speed));
draw_text(50, 90, "x_frame value: " + string(x_frame));
draw_text(50, 110, "y_frame value: " + string(y_frame));
//Draw sprite from spr_idle tile over spr_base
draw_sprite_part(spr_idle, 0, floor(x_frame)*frame_size, y_frame, frame_size, frame_size, xx, yy);
if (x_frame + (anim_speed/60) < anim_length) { x_frame += anim_speed/60; }
}
x_frame is the X location on the tile set, y_frame is the Y location on the tile set.
There is clearly something I don't understand, I want to loop the sprite part on the last y_frame location, in the x_frame direction, until the player move again. but nothing appears. The x_frame seems to only increment 1 frame and stalls there.
Any ideas?
Thanks!
Last edited by a moderator: