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
Alarm 0 Event
Alarm 1 Event
Alarm 2 Event
Alarm 3 Event
Step Event:
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.
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
}
Code:
///unhiding animation
if (var_100pixel == 1) {
sprite_index = spr_enemy_rockhider_unhiding image_speed = 0.2;
alarm[1] = 25;
}
Code:
///animation for legs
if (var_100pixel == 1) {
sprite_index = spr_enemy_rockhider_legs image_speed = 0.2;
alarm[3] = 15;
}
Code:
///setting hiding sprite
sprite_index = spr_enemy_rockhider_hiding image_speed = 1;
Code:
///set var_l
if (var_100pixel == 1) {
var_l = 1;
}
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;
}
Any help will be appreciated. Uber-Dan.