• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED Animation plays only first frame when pressing a button

C

CompleteNutz

Guest
I've been at this for hours and I can't seem to figure out why when I press the left mouse button my shooting animation gets stuck on the first frame.
I'm a beginner, barely got GameMaker the day before yesterday, so my code is probably very messy. I looked everywhere online and I think my issue has something to do with the image_index being reset or something, but I don't understand how to fix it.
So I'm trying to make my character animate when shooting a projectile. My code is the following:

Create Event:

image_speed = 0;
walkspeed = 3.5;
collisionSpeed = walkspeed + 2;
/// Projectile Spawn Variables
projoffsetx = 2;
projoffsety = 4;
pdir = point_direction(0, 0, projoffsetx, projoffsety);
plength = point_distance(0, 0, projoffsetx, projoffsety); (ignore the last four lines, they're for the projectiles which surprisingly work)

Step Event:

if(keyboard_check(ord("D"))){
if place_free(x + collisionSpeed, y)
{
x += walkspeed;
image_speed = walkspeed / 3;}
sprite_index = spr_player_walk_r;
}
if(keyboard_check(ord("A"))){
if place_free(x - collisionSpeed, y){
x -= walkspeed;
image_speed = walkspeed / 3;}
sprite_index = spr_player_walk_l;
}
if(keyboard_check(ord("S"))){
if place_free(x, y + collisionSpeed){
y += walkspeed;
image_speed = walkspeed / 3;}
sprite_index = spr_player_walk_d;
}
if(keyboard_check(ord("W"))){
if place_free(x, y - collisionSpeed){
y -= walkspeed;
image_speed = walkspeed / 3;}
sprite_index = spr_player_walk_u;
}
if(keyboard_check(vk_nokey)){
image_speed = 0;
}
if (mouse_check_button_pressed(mb_left)) && sprite_index != spr_player_shoot_r {
image_index = 0;
sprite_index = spr_player_shoot_r;
}

Again, sorry if it's all over the place. For now I'm trying to get a grasp on specific things I think I'll use in my future, bigger projects.

Edit:

This is the part I'm having trouble with:

if (mouse_check_button_pressed(mb_left)) && sprite_index != spr_player_shoot_r {
image_index = 0;
sprite_index = spr_player_shoot_r;
}
 
D

Deleted member 13992

Guest
try increasing image_speed in the conditional statement you're having trouble with. either image_speed=walkspeed/3; or even just =1 to see what happens.
 
C

CompleteNutz

Guest
Sorry, my bad, i posted the version without the image_speed. Doesn't work with that either.
 
C

CompleteNutz

Guest
Oooh wait, I think I got it. In the conditional statement where I check to see if there is no key being pressed, the image_speed gets set to 0. So that means that immediately after I click, the image_speed turns to 0, so that's why it freezes into place after one frame. I'll try and see how I can get around that.
 
Top