GameMaker Destroying sprites form layer

A

Aleksi Laine

Guest
Hi,
I need to destroy sprites called sTree from my asset layer. All 10 of them. Can this be done, if so how?
Thanks.
 
A

Aleksi Laine

Guest
Thanks, but the sprite_delete literally removes the sprite from the game. I only need to destroy it.
 

Sabnock

Member
instance_destroy(); if it is a sprite in an instance.

if you are using draw_sprite() just stop drawing it

if it is a layer you want to destroy use layer_destroy();

if it is something you have drawn to a surface then that is something different

??
 
A

Aleksi Laine

Guest
Yeah that works, but it destroys them one at a time. I would have to repeat the function too many times to be effective. (There might be more than just 10 of them. It's a survival game. )
 

Sabnock

Member
Yeah that works, but it destroys them one at a time. I would have to repeat the function too many times to be effective. (There might be more than just 10 of them. It's a survival game. )
if you destroy the layer and recreate it does it affect anything else?
 
A

Aleksi Laine

Guest
I have tried destroying the whole layer, but for some reason, it doesn't destroy the sprites on it.
 
A

Aleksi Laine

Guest
I "solved" the problem by abandoning the layer_sprite_create() and using draw event. The performance takes a huge hit but at least it works. If anyone still has a solution on how to get rid of the sprites created with layer_sprite_create(), I'm all ears here. Thanks all, for the help so far.
 

yodak

Member
there is a code to get all elements on the yo-yos manual. It seesms to do what you want.

GML:
var a = layer_get_all_elements(layer);
for (var i = 0; i < array_length(a); i++;)
{
    if layer_get_element_type(a[i]) == layerelementtype_sprite
    {
        layer_sprite_destroy(a[i])
    }
}
 

Keys

Member
I "solved" the problem by abandoning the layer_sprite_create() and using draw event. The performance takes a huge hit but at least it works. If anyone still has a solution on how to get rid of the sprites created with layer_sprite_create(), I'm all ears here. Thanks all, for the help so far.
I'm having the same issue, did anyone find a solution to this. Gamemaker claims you can use the ID returned from layer_sprite_create and throw it into layer_sprite_destroy to destroy it but this doesn't yield any results. How can I delete a sprite i've created on a layer??

EDIT: Never mind the function works fine, I just forgot to set a bool somewhere in my code šŸ˜…
 
Last edited:
Top