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

I

iTypewriter

Guest
Whats up Gamers, i need help with something. I need a way to randomize the backgrounds. For context, I've set the backgrounds as instances just so it'll be easier to manipulate. Each of the backgrounds are objects. I need a way to make multiple rooms, and a random cycle through the different backgrounds. I can work with either DnD or GML, feel free to explain it like I'm a middle schooler, lol

iTypewriter
 

tagwolf

Member
The background image needs to be loaded from a sprite and set to the background layer.

You could either make your images a set of frames in one sprite and use something like:
Code:
layer_background_index(background_element_id, irandom(12));
or do something like this for different sprites:
Code:
layer_background_sprite(background_element_id, choose(spr_bg1, spr_bg2, etc etc...));
To get the element ID I reference this example form the manual:
https://docs2.yoyogames.com/source/...ooms/backgrounds/layer_background_sprite.html
Code:
var lay_id = layer_get_id("Background_sky");
var back_id = layer_background_get_id(lay_id);
if layer_background_get_sprite(back_id) != spr_Clouds
    {
    layer_background_sprite(back_id, spr_Clouds);
    }
Put any code like this into your game controller object (if you have one or make a controller object just for this) in the appropriate step or alarm or room begin or whatever event for your game.
 
Top