• 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!

GameMaker Random Background on Main Menu

9

9intend0

Guest
Hello! I was beginning to work on a game (my first) and I was trying to load in a random background from a set of sprites that I have. Essentially, every time a player opens the game, I want one of the various backgrounds come up (each background is ties to an element that you will gain control of in the game). I can't seem to find a reliable way to do it. The closest I got was creating an object which called on a random sprite from a list, but if I do that, I can't get it to parallax.
Is there something I'm missing? Is this even possible?
 

curato

Member
easiest would be put all the backgrounds on the title screen and mark them invisible then turn one on at random with layer_set_visible
 
9

9intend0

Guest
easiest would be put all the backgrounds on the title screen and mark them invisible then turn one on at random with layer_set_visible
Ok, I'll try it. Do I add that code to a dummy object or somewhere else?
Pardon the simple question, I'm new to EVERYTHING haha

EDIT:
I got it to work!

GML:
var random_number=irandom_range(1,3)
if (random_number=1){
    var layer_id = layer_get_id("Water");
    layer_set_visible(layer_id,visible);
}
if (random_number=2){
    var layer_id = layer_get_id("Fire");
    layer_set_visible(layer_id,visible);
}
else {
    var layer_id = layer_get_id("Ground");
    layer_set_visible(layer_id,visible);
}
 
Last edited by a moderator:
Top