• 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 Animation Replaying Issue

U

Uber-Dan

Guest
Hello GameMaker Community, I have been having a problem with a certain animation (named 'spr_enemy_rockhider_going_into_hiding) playing twice right after each other even though I programmed it to play once. It only usually happens when you go into his 100 pixel square range (where you have to be for him to come out of hiding) and out (he hides again after you go out of that radius) again in a short space of time (about 2-3 seconds, usualy how long he takes to come out of hiding, coincidence?). Here is the code for the character:
Create Event
Code:
///making variables
globalvar var_q var_e var_t
{
var_q=0
var_w=0
var_z=0
var_h=0
var_p=0
var_l=0
var_f=0
var_o=0
}
Alarm 0 Event
Code:
///unhiding animation
if (var_100pixel == 1) {
    sprite_index = spr_enemy_rockhider_unhiding image_speed = 0.2;
    alarm[1] = 25;
}
Alarm 1 Event
Code:
///animation for legs
if (var_100pixel == 1) {
    sprite_index = spr_enemy_rockhider_legs image_speed = 0.2;
    alarm[3] = 15;
}
Alarm 2 Event
Code:
///setting hiding sprite
sprite_index = spr_enemy_rockhider_hiding image_speed = 1;
Alarm 3 Event
Code:
///set var_l
if (var_100pixel == 1) {
    var_l = 1;
}
Step Event:
Code:
///100 pixel check returns var_100pixel
if (instance_exists(obj_hero)) {
    var_100pixel = 0;
    var_x = self.x;
    var_y = self.y;
    var_herox = obj_hero.x;
    var_heroy = obj_hero.y;
    var_x -= 100;
    if var_herox > var_x{
        var_x += 200;
        if var_herox < var_x{
            var_x += 100;
            var_y -= 100;
            if var_heroy > var_y{
                var_y += 200;
                if var_heroy < var_y {
                    var_y -= 100;
                    var_100pixel=1;
                }
            }
        }
    }
}
Code:
///when hero is within range do this
if (instance_exists(obj_hero)) {
    if (var_100pixel == 1) {
        //anamation for unhiding
        if (var_p == 0) {
            sprite_index = spr_enemy_rockhider_shaking image_speed = 0.2;
            alarm[0] = 30;
            var_p = 1;
        }
        //check if rockhider unhiding anamation is done
        if (var_l == 1) {
            //anamation for walking
            if (var_f == 0) {
                sprite_index = spr_enemy_rockhider_moving image_speed = 0.5;
                var_f = 1;
            }
            //move towards hero
            dir = point_direction(x,y,obj_hero.x,obj_hero.y);
            phy_speed_x = lengthdir_x(1,dir);
            phy_speed_y = lengthdir_y(1,dir);
        }
    }
}
Code:
///if hero is not within range do this
if (instance_exists(obj_hero)) {
    if (var_100pixel == 0) {
        //stop moving
        phy_speed_x = 0;
        phy_speed_y = 0;
        //reset checkmarkers
        var_f = 0;
        var_l = 0;
        //if hero was in range a step ago
        if (var_p == 1) {
            //starting anamation for hiding
            var_p = 0;
            sprite_index = spr_enemy_rockhider_going_into_hiding image_speed = 0.5;
            alarm[2] = 18
        }
    }
}
Code:
///if hero is dead
if (instance_exists(obj_hero)) {
}
else{
    phy_speed_x = 0;
    phy_speed_y = 0;
    sprite_index = spr_enemy_rockhider;
}
Sorry for all the code to sift through, I have no idea where the problem was so I thought it would be better to put it all in.
Any help will be appreciated. Uber-Dan.
 

jazzzar

Member
Sorry i cannot read all that, but maybe trying this :
Code:
If image_index==image_number-1
{
    image_speed=0;
}
Will fix it ?
 
Top