• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Objects stop spawning

jujubs

Member
Hello everyone. I'm trying to make a shmup in GM1.4, for which I'm using three separate spawners: starfieldspawner (which generates stars), rockspawner (which spawns big rocks) and aerolitespawner (which spawns small rocks). My goal for now is to spawn those objects infinitely, and I haven't had a single issue with starfield and rock, but my aerolitespawner just seems to stop working after a while.


All my spawners work about the same way, which is this:
obj_control (step event, stays hidden in the room):

Code:
global.aerolitespawner_alarm = random_range(2,3);

obj_aerolitespawner create event:

Code:
timer_ = 0;
global.aerolitespawner_alarm = 30;

obj_aerolitespawner step event:
Code:
timer_ += 1;
if (timer_ > global.aerolitespawner_alarm)
{
    if(!place_meeting(x, y, obj_rock))
    {
        instance_create(x, y, obj_aerolite);
    }
    timer_ = 0
}
I've tried counting instances of obj_aerolite and spawning another spawner, but it doesn't do anything. So, any ideas on what could be happening?
 

jo-thijs

Member
Hello everyone. I'm trying to make a shmup in GM1.4, for which I'm using three separate spawners: starfieldspawner (which generates stars), rockspawner (which spawns big rocks) and aerolitespawner (which spawns small rocks). My goal for now is to spawn those objects infinitely, and I haven't had a single issue with starfield and rock, but my aerolitespawner just seems to stop working after a while.


All my spawners work about the same way, which is this:
obj_control (step event, stays hidden in the room):

Code:
global.aerolitespawner_alarm = random_range(2,3);

obj_aerolitespawner create event:

Code:
timer_ = 0;[/COLOR][/FONT][/LEFT]
[FONT=arial][COLOR=rgb(222, 222, 222)]
[LEFT]global.aerolitespawner_alarm = 30;


obj_aerolitespawner step event:
Code:
timer_ += 1;
if (timer_ > global.aerolitespawner_alarm)
{
    if(!place_meeting(x, y, obj_rock))
    {
        instance_create(x, y, obj_aerolite);
    }
    timer_ = 0
}
I've tried counting instances of obj_aerolite and spawning another spawner, but it doesn't do anything. So, any ideas on what could be happening?
Are you sure the spawners stopped spawning or is it possible they keep spawning, but the aerolites don't reach the screen anymore?
You can test this by putting this in the draw event of obj_control:
Code:
draw_set_color(c_white);
draw_set_font(-1);
draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_text(8, 8, "aerolite count: " + string(instance_number(obj_aerolite)));
Is it possible that an instance of obj_rock got stuck on top of the spawners?

Is there any other code in your project that migt interfere with this system?
 
K

kevins_office

Guest
Code:
timer_ += 1;
if (timer_ > global.aerolitespawner_alarm)
{
    if(!place_meeting(x, y, obj_rock))
    {
        instance_create(x, y, obj_aerolite);
    }
    timer_ = 0
}
The way your code is written...

Is it time to spawn?
If there is no collision spawn new.
If there is collision skip spawning new.
Regardless if there is collision or not, reset timer and wait again.

Meaning if there is a collision you do nothing to try again to spawn a new instance in a non collision location.
I assume that is why after awhile, as the room fills up and its harder to find non collisions, you don't see any new instances spawned.

Also... Not sure how x and y is decided when you spawn a new instance, but it looks like you are giving them the same x y as the controller object which looks like it never changes. So once that x y is covered by a collision then game over.
 
Last edited by a moderator:

jujubs

Member
I assume that is why after awhile, as the room fills up and its harder to find non collisions, you don't see any new instances spawned.

Also... Not sure how x and y is decided when you spawn a new instance, but it looks like you are giving them the same x y as the controller object which looks like it never changes. So once that x y is covered by a collision then game over.
This appears to be it!

nonsense.png

I changed the Y position to be onscreen and this showed up. But, why is this happening if I'm checking for collisions on creation? And why it stopped spawning if there's still that huge gap right in the middle of my newfound asteroid belt?
 

jo-thijs

Member
This appears to be it!

View attachment 17708

I changed the Y position to be onscreen and this showed up. But, why is this happening if I'm checking for collisions on creation? And why it stopped spawning if there's still that huge gap right in the middle of my newfound asteroid belt?
What is the collision mask and sprite of obj_aerolitespawner and what is the sprite of obj_aerolite?
 

jujubs

Member
What is the collision mask and sprite of obj_aerolitespawner and what is the sprite of obj_aerolite?
obj_aerolitespawner is a 16x16 square. obj_aerolite is a 8x8 square, both the size of their onscreen sprites, though the spawner is invisible.
 

jo-thijs

Member
obj_aerolitespawner is a 16x16 square. obj_aerolite is a 8x8 square, both the size of their onscreen sprites, though the spawner is invisible.
Then that can't be the issue.

Are you sure the spawners stopped spawning or is it possible they keep spawning, but the aerolites don't reach the screen anymore?
You can test this by putting this in the draw event of obj_control:
Code:
draw_set_color(c_white);
draw_set_font(-1);
draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_text(8, 8, "aerolite count: " + string(instance_number(obj_aerolite)));
Have you already tried this?

This appears to be it!

View attachment 17708

I changed the Y position to be onscreen and this showed up. But, why is this happening if I'm checking for collisions on creation? And why it stopped spawning if there's still that huge gap right in the middle of my newfound asteroid belt?
Can you explain a little bit more what's happening there?
Are the aerolites jittering?
Are they constently spawning on top of each other once one passes by?
...
 
Top