• 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!

Legacy GM Issue with playing an animation

N

Nahual

Guest
I'm so glad and beyond happy that the GMC is back! :)

Now if you guys could help me a bit here with this issue that is killing me :confused:

I'm trying to make the player (main character) to do a full animation and when it reaches "frame number 5" then releases a missile, all of this is part of a power-up.

Everything works, the missile is created and it travels how it supposed to, what it doesn't work is the animation, for some reason the animation doesn't play all the way through and is breaking my skull not being able to fix it.

The code is in the STEP event of the player.
Here's what I have coded:
Code:
CREATE EVENT
///initialize variables
image_speed = .2;
grav = 1;
spd = 4;
jspd = 12;
hspd = 0;
vspd = 0;
b = -1; //bullet
c = -1; //bullet
d = -1; //gun spark
e = -1; //gun spark
f = -1; //fua powerup
canshoot = true;
hurt = 0;
Code:
STEP EVENT
//powerup
if (fkey) && (obj_controller.tequila = 3){
    sprite_index = spr_player_power;
    image_speed = 1;
    alarm[2] = 40;
  
    if (image_index > 5){
    audio_play_sound(snd_fua,9,false);
    f=instance_create(x+sign(image_xscale) * 8,y-2,obj_fua);
    f.speed = 15;
    obj_controller.tequila = 0;
  
  
// powerup facing
    if (image_xscale = 1){
        f.direction = 0;
        }else{
        f.image_xscale = -1;
        f.direction = 180;
        }
}
}
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
Do you change the sprite to something else BEFORE the powerup code, aka further up the step event? If you change sprites to a sprite with less subimages, image_index will be clamped to the new range.
 
N

Nahual

Guest
No the only animation before the power animation is the IDLE animation
 

Yal

🐧 *penguin noises*
GMC Elder
And you ALWAYS set the sprite to that? Because that might be the problem depending on the number of idle subimages.
 
A

Aleksandar Gavrilovic

Guest
wait a minute... but you set image_index to zero in the condition! it's not going to go on, it's going to start at 0 again. is that the intention? i think not
 

Yal

🐧 *penguin noises*
GMC Elder
Ah, nice catch there. I assumed the missile was supposed to be released at the end of the animation, not partway through, so I didn't notice that.
 
N

Nahual

Guest
I was told that after changing sprites with sprite_index =
Then i had to set the image_index = 0 back to zero

Before I had that line of code, it wouldnt work anyways.
Any other ideas?
 

RangerX

Member
If the animation doesn't play its whole, its because the image_index variable is back to zero somewhere. There isn't much other things that could end up being the reason.
What's in alarm 2 ?
 
N

Nahual

Guest
I've changed a few things on the code, removing the image_index back to zero and the alarm[2] as well which was another try on ending the power animation and changing it back to the idle animation.

I will post the entire STEP event code because maybe I'm missing something that I am not seeing, perhaps, and hopefully you guys can see it and help me with this because like RangerX pointed out, my powerup code should work but is not.

So here it is the entire code, maybe something I have coded is not making the player play the full entire power animation.

The "fkey = keyboard_check(ord('C'));" is what I'm using to play the powerup animation and shoot the missile
Thank you all again for your time.
Code:
STEP EVENT
///game input
rkey = keyboard_check(vk_right);
lkey = keyboard_check(vk_left);
jkey = keyboard_check_pressed(ord('Z'));
skey = keyboard_check_pressed(ord('X'));
ekey = keyboard_check_pressed(vk_enter);
ukey = keyboard_check_pressed(vk_up);
eskey = keyboard_check_pressed(vk_escape);
fkey = keyboard_check(ord('C'));

//override the controls for a gamepad
var gp_id = 0;
var thresh = .5;

//checking if gamepad is supported and connected
if (gamepad_is_connected(0))
{
    rkey = gamepad_button_check(0,gp_padr) or gamepad_axis_value(0,gp_axislh) > thresh;
    lkey = gamepad_button_check(0,gp_padl) or gamepad_axis_value(0,gp_axislh) < -thresh;
    jkey = gamepad_button_check_pressed(0,gp_face1);
    skey = gamepad_button_check_pressed(0,gp_face3);
    down = gamepad_axis_value(1,gp_axislv) > thresh;
    ckey = gamepad_button_check_pressed(0,gp_shoulderl);
    ekey = gamepad_button_check_pressed(0,gp_start) and gamepad_button_check_pressed(0,gp_start)
    ukey = gamepad_button_check(0,gp_padu) or gamepad_axis_value(0,gp_axislh) < -thresh;
    eskey = gamepad_button_check(0,gp_select)
    fkey = gamepad_button_check_pressed(0,gp_shoulderr);
}


//check for ground
if (place_meeting(x,y+1,obj_solid))
{
    vspd = 0;
  
    //jumping
    if (jkey)
    {
        audio_play_sound(snd_jump, 5, false);
        vspd = -jspd;
    }
} else
{
    //gravity
    if(vspd < 10)
    {
       vspd += grav;
    }
}

//moving to the right
if (rkey)
{
    //facing right
    hspd = spd;
}

//moving to the left
if (lkey)
{
    //facing left
    hspd = -spd
}

//check for not moving
if ((!rkey && !lkey) or (rkey && lkey))
{
    hspd = 0;
}

//check for horizontal collisions
if (place_meeting(x+hspd,y,obj_solid))
{
    while(!place_meeting(x+sign(hspd),y,obj_solid))
    {
    x += sign(hspd);
    }
    hspd = 0;
}

// play landing sound
    if (place_meeting(x,y+vspd, obj_solid) && vspd >0)
    {
        instance_create(x, y+10,obj_dust);
        audio_play_sound(snd_landing,4,false)
    }  

//move vertically
x += hspd;

//check for vertical collisions
if (place_meeting(x,y+vspd,obj_solid))
{
    while(!place_meeting(x,y+sign(vspd),obj_solid))
    {
    y += sign(vspd);
    }
    vspd = 0;
}

//move horisontally
y += vspd;

//controlling sprites
if (yprevious != y)
{
    sprite_index = spr_player_jump;
    image_speed = 0;
    image_index = y > yprevious;
}else {
    if (xprevious != x)
    {
    sprite_index = spr_player_walk;
    image_speed = .6;
    }else
    {
     sprite_index = spr_player_idle
     image_speed = 0.2;
}      
}  
//control player's direction (facing)
if (xprevious < x)
{
    image_xscale = 1;
}else if (xprevious> x)
{
    image_xscale = -1;
}

//powerup
if (fkey) && (obj_controller.tequila = 3){
    sprite_index = spr_player_power;
    image_speed = 0.5;
  
    if (image_index > 5){
    audio_play_sound(snd_fua,9,false);
    f=instance_create(x+sign(image_xscale) * 8,y-2,obj_fua);
    f.speed = 15;
    obj_controller.tequila = 0;
  
  
// powerup facing
    if (image_xscale = 1){
        f.direction = 0;
        }else{
        f.image_xscale = -1;
        f.direction = 180;
        }
}
}


//shooting
if (skey) && (canshoot = true)
{
    //gamepad_set_vibration(0, 1, 1);
    d=instance_create(x+sign(image_xscale) * 18,y-2,obj_gun_spark);
    e=instance_create(x+sign(image_xscale) * 8,y+10,obj_gun_spark2);
    b=instance_create(x+5,y-2,obj_player_bullet);
    c=instance_create(x-7,y+3,obj_player_bullet);
    b.speed = 17;
    c.speed = 17;
    canshoot = false;
    alarm[0] = 7;

//check bullet direction
if (image_xscale = 1)
{
    d.direction = 0;
    e.direction = 0;
    b.direction = 0;
    c.direction = 0;
}else{
    d.image_xscale = -1;
    e.image_xscale = -1;
    b.direction = 180;
    c.direction = 180;
}
}

  
if (keyboard_check_pressed(ord('V'))){
    obj_controller.tequila += 3;
}

//if the lives are full and collect more
if global.hp > 3
{
    global.hp = 3;
}

//if tequilas are full and collect more
if obj_controller.tequila > 3
{
    obj_controller.tequila = 3;
}

//transparent after hit
if hurt = 1
{
    //image_alpha = 0.5;
    image_blend = c_red;
}
    else
{
    //image_alpha = 1;
    image_blend = c_white;
}

//if health 0
if global.hp <1
{
//show him dead
image_speed = 0.1;
sprite_index = spr_player_dead;
script_execute(dead_state);
//turn of the vibration
gamepad_set_vibration(0, 0 ,0);
instance_create(x,y,obj_death_timer);
}
//restart game
if keyboard_check(ord('R'))
{
    game_restart();
}

//go back to menu
if (eskey){
    room_goto(Menu);
    }
 
Top