SOLVED Looping

How do I turn off looping for my animation of my object in the game? I can stop it in the IDE but that doesn't effect the game according to the MANUAL.
 

kburkhart84

Firehammer Games
How do I turn off looping for my animation of my object in the game? I can stop it in the IDE but that doesn't effect the game according to the MANUAL.
Just make image_speed 0. If you want it to do the animation once, then make image_speed 0 in the animation end event.

If you later change the sprite or want it to animate again, just change image_speed back to 1.
 
I actually want to destroy the animation entirely once it reaches the last frame. Shouldn't this code work:

GML:
        with (DraculaStaticObject)
        {
            instance_destroy();
        }
        

        instance_create_depth(352,544,-1200, DraculaAttackObject1);
        with (DraculaAttackObject1)
        {
            if (image_number == 3)
            {
                instance_destroy();
                instance_create_depth(300, 500, -1200, DraculaAttackObject2);
                if (image_number == 8)
                {
                    with (DraculaAttackObject2)
                    {
                        instance_destroy();
                    }
                    instance_create_depth(352, 544, -1200, DraculaStaticObject);
                }
            }
        }
 

kburkhart84

Firehammer Games
image_number is not what you think I'm guessing. It simply tells you how many subimages there are in the current sprite. You may be looking for image_index instead if you are trying to check directly which frame it is on in order to destroy it. However, note that these are floating point values so may not ever end up exactly on some integer value. This is part of why I recommended instead to just use the event, it should work in all cases.

This can be even easier if you have a dedicated object that is literally just showing the animation and destroying itself, as you don't have to do any checking of anything.
 
image_number is not what you think I'm guessing. It simply tells you how many subimages there are in the current sprite. You may be looking for image_index instead if you are trying to check directly which frame it is on in order to destroy it. However, note that these are floating point values so may not ever end up exactly on some integer value. This is part of why I recommended instead to just use the event, it should work in all cases.

This can be even easier if you have a dedicated object that is literally just showing the animation and destroying itself, as you don't have to do any checking of anything.
What do you mean by:
This can be even easier if you have a dedicated object that is literally just showing the animation and destroying itself, as you don't have to do any checking of anything.
 

kburkhart84

Firehammer Games
What do you mean by:
I mean that if you are using a single object that does mutliple things, you will have to keep checking inputs or whatever the object does. But if the object is a "clone" of sorts and is only for the purpose of displaying the animation and that's it, then it is extremely easy to just use the animation end event and destroy itself as you wouldn't be needing any other events, and wouldn't need to do anything else in the animation end event either.
 
I mean that if you are using a single object that does mutliple things, you will have to keep checking inputs or whatever the object does. But if the object is a "clone" of sorts and is only for the purpose of displaying the animation and that's it, then it is extremely easy to just use the animation end event and destroy itself as you wouldn't be needing any other events, and wouldn't need to do anything else in the animation end event either.
Well the objects are sort of clones. I had to split them up because the frame sizes were drastically different for the single sprite. Anyway, it's done and working. Thanks :cool:
 

chamaeleon

Member
GML:
        instance_create_depth(352,544,-1200, DraculaAttackObject1);
        with (DraculaAttackObject1)
        {
            if (image_number == 3)
            {
                instance_destroy();
                instance_create_depth(300, 500, -1200, DraculaAttackObject2);
                if (image_number == 8)
                {
                    with (DraculaAttackObject2)
                    {
                        instance_destroy();
                    }
                    instance_create_depth(352, 544, -1200, DraculaStaticObject);
                }
            }
        }
Regardless of whether it should be image_number or image_index ...
GML:
            if (image_number == 3) // if this is true
            {
                ...
                if (image_number == 8) // this will not be true
                {
                    ... // this will never execute
                }
            }
You do realize that your code runs sequentially, right? No jumping around in code between events and instances because some comparison in an if statement happens to suddenly have a truthy comparison *if the current execution context was at the place of the if statement instead of somewhere completely different in your code base*. It is the only reason I can think of for your nesting of two incompatible if statements. That or you think there's some connection to the freshly created instance, which there is not at the point of the nested if statement comparison because there is no with() statement wrapping that if statement (if that is even the logic you're going for, I have no idea what your code is really supposed to accomplish).
 

Nidoking

Member
To be fair, if sprite_index changes, then image_number could potentially change between those checks, but that's not the case here, and it's almost certain (as has been said) that image_number isn't the variable they intended to use. There's a bigger problem here, though, in that the instance_destroy call comes before the second check, so it's checking a variable in a destroyed instance. I think that's supposed to be okay, since the event continues until the destroyed instance goes out of scope, but I would recommend avoiding that as a matter of practice.
 

chamaeleon

Member
To be fair, if sprite_index changes, then image_number could potentially change between those checks, but that's not the case here, and it's almost certain (as has been said) that image_number isn't the variable they intended to use. There's a bigger problem here, though, in that the instance_destroy call comes before the second check, so it's checking a variable in a destroyed instance. I think that's supposed to be okay, since the event continues until the destroyed instance goes out of scope, but I would recommend avoiding that as a matter of practice.
I agree with the potential for the number to change, as in theory you could make your create event code do anything you want, including modifying the sprite_index for a different instance. I also agree with the problematic logic of having destruction of the current instance in the middle of execution (not to be confused with in the middle of code, I try to ensure destruction at the end of an event, but that doesn't mean it is lexically at the end of the code). Regardless of what the semantics are, documented or not, I prefer to think of destruction as the last thing an instance should be involved with (exceptions may exist, I just haven't had much need for that myself).
 
The code has been changed to run in an animation_end event for each object. I am currently having a problem with it displaying multiple animations if I click more than once.

For example, the code for the controller is as of now:

GML:
if (global.dracula_attacking == false)
{

    if (mouse_check_button_released(mb_left))
    {
   
        //Last BOSS Attacked

        //if mouse_x < 1024 && mouse_x > 0  && mouse_y > 0 && mouse_y < 576
        //{


                global.dracula_atttacking = true;
                with (DraculaStaticObject)
                {
                    instance_destroy();
                }
       

                instance_create_depth(352,544,-1200, DraculaAttackObject1);
           
       
       
        //}
    }
}
and the code for the last animation object (run in animation end) is:

Code:
// You can write your code in this editor
image_speed = 0;
instance_create_depth(352, 544, -1200, DraculaStaticObject);
global.dracula_attacking = false;
instance_destroy();
the animation objects are chained together. With the idea that using the global variable restricts clicking to one animation at a time. But multiple animations are executing with each mouse click for some reason unknown to me. Aksi, the create event of the controller is:

global.dracula_attacking = false;
 
So I ran it through the debugger and its not setting global.dracula_atttacking = true; Any reason it might not do that?


(edit)

Too many t's in attacking. Stupid error.
 

kburkhart84

Firehammer Games
1. What is Dracula_Static_Object? Is it the name of the object or a reference to an instance of the object. If it is the name of the object and you possibly have more than one, you have a problem because you don't know which one you are accessing.

So I ran it through the debugger and its not setting global.dracula_atttacking = true; Any reason it might not do that?
2. There isn't any real reason unless either the code is never being reached, or you are setting it to false somewhere else and not even noticing because it happens so fast. You can add show_debug_message() to the code to see if it is ever being reached.
 
Top