Jump to content

- - - - -

Color-changing background tutorial

  • Please log in to reply
1 reply to this topic

#1 jetp250


    GMC Member

  • New Member
  • 3 posts
  • Version:GM:Studio

Posted 17 February 2016 - 08:26 PM

  • Title:  How to make a color-changing background
  • Description:  An easy way to make a color-changing background for your game.
  • GM Version: GM:Studio
  • Registered: No
  • File Type: .zip
  • File Size:  60.78kB etc.
  • File Link: http://www.mediafire...kground.gmx.zip
  • Required Extension: None
  • Required DLL: None
  • Tags: tutorial, make, submission, submit, help, guide, template

I've been trying to make a color-changing background, which sure sounds easy. I couldn't to find any tutorials, since the background_create_color didn't work as expected. After struggling with it without finding any tutorials, I solved it myself, and decided to share. It's pretty simple. Here's all you need for it to work:


1: Create new object, call it something like 'obj_drawer'.

2: Click 'Add event' - 'Create event'.

3: Click 'Control' and drag the 'Execute code' thingy into Actions.

4: Paste this code there, or type it yourself:

obj_drawer create event:

///Setting variables to 0
Loop = 0
GG2 = 0;
BB2 = 0;
RR2 = 0;

col2 = 0;
col = 0;

5: Click 'Add event' - 'Draw GUI'.

6: Click 'Control' and drag the 'Execute code' again into Actions.

7: Copy & paste or type the following text there:

obj_drawer Draw GUI event:

// Names come from $RRBBGG :)

//Creating the loop
if Loop = 0 {
Loop = 200;

//Refreshing the colors
RR = random_range(1,99);
BB = random_range(1,99);
GG = random_range(1,99);
//resetting the loop
if Loop >= 1 {Loop -= 1;}

//Dividing the numbers with 1
GG2 = GG2 div 1;
BB2 = BB2 div 1;
RR2 = RR2 div 1;

//Smoothly changing the current values to target values 
//(e.g. RR2(current) = RR(target))

if RR2 < RR { RR2 += 1; }
if RR2 > RR { RR2 -= 1; }

if GG2 < GG { GG2 += 1; }
if GG2 > GG { GG2 -= 1; }

if BB2 < BB { BB2 += 1; }
if BB2 > BB { BB2 -= 1; }

//Resetting the loop is current colors match the target colors
if col2 == col { Loop = 0; }

//Turning the numbers into one RGB

//Target RGB
col = make_color_rgb(RR,GG,BB);

//Current RGB
col2 = make_color_rgb(RR2, GG2, BB2);

//Updating the background color
if Loop > 1 {
background_color = col2;
background_showcolor = true;

After that, click 'Create a room' and put the obj_drawer there. NOTE: MAKE SURE you have "Draw Background Color" Checked at Room 'Backgrounds'! Otherwise it won't work. Now, click Run and look at the background. I hope the comments in the code are enough self-explaining that everyone knows what's going on there. By the way, I just created a 'Loop' variable instead of using Alarms, it's whatever which one you use. with Alarms you would have to change some things that I can't explain here. Have a nice day! :)

  • 0

#2 chance


    GMC Member

  • Global Moderators
  • 8762 posts
  • Version:GM:Studio

Posted 17 February 2016 - 09:09 PM

This is OK for the Tutorials forum.  The effect is nice.  And it's a good example of how to use make_color_rgb() and background_colour.


However, it's unnecessarily complicated, in my opinion.  For example, you don't need the "color div 1" statements.  Studio can handle non-integer colors.  And if you really want integers, just replace the random_range() statements with irandom_range() to generate integer rgb values.


Also, part of your loop structure isn't really necessary.   You can remove the loop reset to -1 section, as well as the final loop, and get the same results.  So you might want to re-think what those loops are actually doing.


That said, it runs fine and it illustrates some nice features of the background color.  So beginners can learn from it.

  • 1