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

Animation Problem

Ho

This is probably a kind of rookie question but I Have this character, Dr. Frankenstein, that sits on top of a castle. He sends out enemy floating brains you have to fight. I want to make it so Dr. Frankenstein plays a short animation every time he sends out a brain. My problem is that he either plays the animation over and over and over again, or not at all.

The brains are controlled by a "Brain Master" object and this is its step method:

Code:
        if ((global.number_of_brains_on_screen <= global.max_number_of_brains))
        {
            
                //show_debug_message("Checking instance place");
                random_y = random_range(200,700);
                if (!instance_place(x, random_y, BigBrainObject))
                {
                    timer--;
                    //if (timer < 0)
                    //{
                        //show_debug_message("Creating Brain");
                        global.creating_brain = true;
                        instance_create_depth(2077, random_y, -1800,BigBrainObject);   
                        global.number_of_brains_on_screen++;
                        
                    //}
                    if (timer > 0)
                    {
                        global.creating_brain = false;
                    }
                    else
                    {
                        timer = room_speed;
                    }
                    
                }
    
        }   
    
}
This is Dr. Frankenstein's Step Event:::

Code:
if (global.creating_brain)
{
    sprite_index = FrankensteinSendOutBrains;   
    
}

else {
    sprite_index = FrankensteinStatic;
}
 

Relic

Member
Edit: scratch that, missed a part of your code.

When the timer is less than 0, you create a brain, change the global variable and then a few lines later set the timer to room_speed. Whenever timer is greater than 0, the global variable is false.

Very hard for global.creating_brain to stay true for more than a single step.
 

Rob

Member
Try something like:

Code:
if (global.creating_brain) && (sprite_index != FrankensteinSendOutBrains)
{
    sprite_index = FrankensteinSendOutBrains;  
    image_index = 0;
    //Maybe set image_speed too?
}

else {
    if (sprite_index == FrankensteinSendOutBrains) && (image_index >= (image_number - 1))
    sprite_index = FrankensteinStatic;
}
 
Ok I updated my code and he Frankenstein still spazzes out. That is, he does his "send out the brains" motion non-stop, even when he should be idle,

Code:
    if ((global.number_of_brains_on_screen <= global.max_number_of_brains))
        {
            
                //show_debug_message("Checking instance place");
                random_y = random_range(200,700);
                if (!instance_place(x, random_y, BigBrainObject))
                {
                    timer--;
                    if (timer < room_speed*10 && timer > 0)
                    {
                        //show_debug_message("Creating Brain");
                        global.creating_brain = true;
                        instance_create_depth(2077, random_y, -1800,BigBrainObject);   
                        global.number_of_brains_on_screen++;
                        timer = 100;
                        with (FrankensteinObject)
                        {
                            sprite_index = FrankensteinSendOutBrains;
                        }
                    }   
                    
                    else if (timer > room_speed*10)
                    {
                        global.creating_brain = false;
                        with (FrankensteinObject)
                        {
                            sprite_index = FrankensteinStatic;
                        }
                    }
                    
                    
                }
    
        }   
}
 

Rob

Member
Set global.creating_brains to false if he doesn't need to make any more brains.

I'm on my phone ATM so it's a pain to type but if you use an else after your first if statement, set the global to false there and I think that should work.
 

Relic

Member
Two issues:

1) unless your room speed is 10 FPS, timer will never be be greater than 10*room_speed. What do you think will (or will not!) occur because of this?

2) a prediction of another issue even if you fix issue 1. Let’s say you create the last brain the screen can have. Your code won’t run next step because it’s reached the max number, so how will the sprite be changed back to static?
 
Ok. So now he plays his sending out the brains animation but occasionally he just flickers.

This is the changes I made to the code:

Code:
        if ((global.number_of_brains_on_screen <= global.max_number_of_brains))
        {
            
                //show_debug_message("Checking instance place");
                random_y = random_range(200,700);
                if (!instance_place(x, random_y, BigBrainObject))
                {
                    timer--;
                    if (timer < room_speed && timer > 0)
                    {
                        //show_debug_message("Creating Brain");
                        global.creating_brain = true;
                        instance_create_depth(2077, random_y, -1800,BigBrainObject);   
                        global.number_of_brains_on_screen++;
                        timer = 100;
                        with (FrankensteinObject)
                        {
                            sprite_index = FrankensteinSendOutBrains;
                        }
                    }   
                    /*
                    else if (timer > room_speed)
                    {
                        global.creating_brain = false;
                        with (FrankensteinObject)
                        {
                            sprite_index = FrankensteinStatic;
                        }
                    }
                    */                   
                    
                }
    
        }   
        else
        {
            sprite_index = FrankensteinStatic;
            global.creating_brain = false;
        }
 
Last edited by a moderator:
He still twitches here and there.And now a duplicate Dr. Frankenstein Is in the upper left hand corner. I did a search for FrankensteinsObject and couldn't come up with any instance_creates
 
Last edited by a moderator:
Top