• 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 Spawning Enemies when entering new room

B

BannanDylan

Guest
Sorry if wrong place, incredibly new to this but have been googling for a while but can't find what I'm looking for.

Whenever I run my game I spawn enemies from the top to fall down. I have now added a menu room and when I click play it simply goes to my game room. However now the enemies don't seem to spawn and I have no idea why as it works when my first room is my game room.

Spawn Code:

Create:

alarm[0] = room_speed*0.1;

Alarm 0:
instance_create_layer(irandom_range(30,980),-50,1,o_enemy);
alarm[0] = random_range(room_speed*0.1, room_speed*0.1);

--------

Menu Code:

Create:
menu_x = x;
menu_y = y;
button_h = 32;

button[0] = "Play!";
button[1] = "Quit!";
buttons = array_length_1d(button)

menu_index = 0;
last_selected = 0;



Step:
var menu_move =0;

menu_move += (keyboard_check_pressed(vk_down) or gamepad_button_check_pressed(0,gp_padd));
menu_move -= (keyboard_check_pressed(vk_up) or gamepad_button_check_pressed(0,gp_padu));

menu_index += menu_move;
if (menu_index < 0) menu_move = buttons - 1;
if (menu_index > buttons - 1) menu_index = 0;

if (menu_index != last_selected) audio_play_sound(s_switch,1,false);

last_selected = menu_index;

if keyboard_check_pressed(vk_enter) or (gamepad_button_check_pressed(0,gp_face1))

{

switch(menu_index)
{
case 0:
room_goto(r_game);
break;

case 1:
game_end();
break;
}
}




Draw:
var i = 0;

repeat(buttons)
{
draw_set_font(f_menu);
draw_set_halign(fa_center);
draw_set_color(c_ltgray);

if (menu_index == i) draw_set_color(c_red)

draw_text(menu_x, menu_y + button_h * i, button);
i++;
}



Thanks for any possible help!
 
B

BannanDylan

Guest
In other words, room_speed*0.1.

What object is the "Spawn Code" in, and is there an instance of it in the r_game room?

Also, where are you getting layer ID 1 from?
Yeah that first line I was following a tutorial and didn't realise the redundancy lol. o_enemy is the object I'm using.

Layer ID I believe is also from a tutorial which I might not need.

All was working fine until I added a menu before going to r_game (game room), but I can't see why that would stop the spawning :/
 

Nidoking

Member
o_enemy is the object I'm using.
Are you saying that the code to spawn o_enemy is in... o_enemy? I think I see the problem.

All was working fine until I added a menu before going to r_game (game room), but I can't see why that would stop the spawning :/
I suspect that something has changed about r_game due to it not being the first room in the game anymore. I ask again, where did you come up with layer ID 1, and what makes you think it's a valid layer to spawn o_enemy in? This question is not so much meant to inform me, but to inform you. When your answer to a question about your code is "I don't know", the proper response is not "lol", but "figure out the answer".
 
Top