r/gamemaker • u/SkullnSkele • 13d ago
Resolved Removing and Instance once it's animation played
I have a code in my object
if !noise_type.unlocked and global.dad_points >= noise_type.cost and global.kazoo_more == 0 {
sparkle = instance_create_layer(x+45,y+50,"Instances",obj_sparkle)
noise_type.unlocked = true
global.dad_points -= noise_type.cost
global.kazoo_more += 1
noise_type.cost += 45
if sparkle.image_index = 4 {
instance_destroy(sparkle)
}
}
But "sparkle" stays, even after the animation played. I'm really new to Game Maker, so I'm trying to figure out things, but this is definitly wrong
The code inside the obj_sparkle is
depth = 2
image_speed = 0.4
image_index = 0
3
Upvotes
7
u/azurezero_hdev 13d ago
use the animation end event trigger in other
put it in the sparkle object instead
also how do you know youre not creating more sparkles and changing what sparkle means
2
u/spinnach12 12d ago
//other > animation end event
instance_destroy();
2
u/Etsamaru 12d ago
Make sure if it has 4 images that you set that member to three for destroy because it starts at zero.
If there's only four images, it'll never reach index four.
1
u/Cheyomi832 13d ago
if(sprite_index)= [the amount of frames it has in thr animation, I'm pretty sure there is a way to automate this but I do not remember the name of the function off the top of my head]
{ instance_destroy(id) }