0
\$\begingroup\$

I'm using a loop to destroy some objects in my code.

for (var i = 0; i < instance_number(obj_item); i++)
{
    var inst = instance_find(obj_item, i);
    with (inst)
        instance_destroy();
}

I would like to make them disappear one at a time on screen (i.e., the first one disappears, one second after that the second one disappears, etc.).

However, it seems that the screen is updated only when the loop has finished: all objects disappear at once.

In Unity, I would use coroutines for such a situation. How do I do that in Gamemaker?

\$\endgroup\$
0
\$\begingroup\$

Use alarm for this, like:

if instance_exists(obj_item)
{
    with instance_find(obj_item, 0)
        instance_destroy();

    alarm[0] = room_speed; // one second
}

place this code in alarm 0 and then start it using alarm[0] = 1;

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy