GML Stopping a sprite from animating then having it animate again

Artie_Kyle

Member
What up, GMC,

Made a bullet sprite, and I've been trying to make it so that the first image is the muzzle animation firing, then the second one is the projectile and it stops animating when it's fired and headed towards something.

After impact, I'm trying to get it to animate again and basically dissolve and destrot itself once the animation ends, but I can't get the sprite to animate again after stopping.

Here's the code:
Code:
// create event
image_speed = 1;

// step event
if image_index > 0 and !place_meeting(x, y, obj_wall)
or image_index > 0 and !place_meeting(x, y, obj_all_parent) {
   image_speed = 0;
   image_index = 1;
}

// collision event
image_speed = 1;

//animation end event
instance_destroy();
Whatever it is I'm missing, feel free to correct me. As always, thanks for your time, guys!
 
Code:
if image_index > 0 and !place_meeting(x, y, obj_wall)
or image_index > 0 and !place_meeting(x, y, obj_all_parent) {
   image_speed = 0;
   image_index = 1;
}
This piece of code is saying "if image index is larger than zero, and there is NO collision with obj_wall, OR no collision with obj_all_parent: image_speed = 0"

What you have to think is that, what happens when there is collision with one, but not the other? It could be colliding with obj_wall, but as long as it's not colliding with obj_all_parent, then the expression is true, and it will still run. So you constantly have this piece of code saying "image_speed = 0", while the collision event is telling it "image_speed = 1", so you never see any change.

Code:
if image_index > 0 and !place_meeting(x, y, obj_wall)
&& image_index > 0 and !place_meeting(x, y, obj_all_parent) // changed or for and
 {
   image_speed = 0;
   image_index = 1;
}
Will see it so that both have to be false (no collision with either) for image_speed to be zero. If either is not found to be false, then the code will not run. As the code is not running the animation end events can kick in.

However: you are doing a collision check in the step event, and also through GMS own collision event, so that seems to be duplicating the work. I also don't see that you need to check the image_index, as presumably image_speed has been stopped at an appropriate point earlier on. The lack of collision ensures image speed resumes, so checking anything else is perhaps moot. Here is how I'd revise your code:

Code:
// create event
image_speed = 0;
was_coll = false;

// step event
if !was_coll
{
if place_meeting(x, y, obj_wall) || place_meeting(x, y, obj_all_parent)
{image_speed = 1;
was_coll = true;
}
}

//animation end event
instance_destroy();
If that is not how you want it then just mix in the previous alteration with AND rather than OR ^^^^
 

Artie_Kyle

Member
@the_dude_abides

Sorry for the late reply, kept working on it and then crashed in bed. Currently working on an improvised version of your method and mine because for some reason when it hit the character and he's standing it doesn't kill him, I'd have to move one pixel towards it to kill me. Will see what happens!

Cheers ma dude!
 
Currently working on an improvised version of your method and mine because for some reason when it hit the character and he's standing it doesn't kill him, I'd have to move one pixel towards it to kill me.
I don't know why that would be the case. Unless you have something like the destroy command in the character when colliding with the bullet, and in the bullet collision you have its speed being stopped. Maybe the bullet does its collision event first, and is then moved out of collision, so the player doesn't respond?

But that could be a load of rubbish as a theory :) Is the issue something that you had before? Or did it not even get to that stage to begin with?

EDIT:
I will say that I tested the initial changes in a basic project, and it worked fine. The bullet hit objects, and then disappeared gradually before being destroyed. If you see a difference between a bullet hitting a wall (i.e it works as intended), and it hitting the player, then perhaps you can assume the player is the issue?
 

Artie_Kyle

Member
Did I mentino that I'm using GMS physics? I should've mentioned that probably, haha!

Anyways, from what I'm seeing, I think this is working fine for the moment.

I'm now moving to the next idea; I can't find any expanding speech bubble tutorials. You think I should just use text box examples and try to tweak them, or is there any tutorial on the site that I might've missed?

Cheers, dude!
 

Yal

šŸ§ *penguin noises*
GMC Elder
One way you could make this easier would be to have two different sprites (one for fire, one for dissolving). In the animation end event, if you use the shooting sprite, switch to the dissolving and set image speed to zero - the first image of the dissolving sprite would be the normal bullet. On impact, set image speed to non-zero. Now the animation will finally have a chance to end again (it won't when the image speed is zero), and this time, you'll have an additional check if you use the dissolve sprite: if so, you destroy the object.
 

Artie_Kyle

Member
While not exactly what I did, I did do something similar-ish.

Anyways, you're one of the experts here, YAL, any links to good tuts you could post in regards to bubble speech dialogue that expands. I saw it while playing minit and really like the vibe of it.

Thanks!
 
Top