How to Change BGs in Basic Game Maker

Save

Game Maker is a program that allows you to create your own games without having to learn a single line of code. Though most things can be done entirely with its drag-and-drop interface, some operations require the use of GML, the included programming language. Changing the game's background image (or "BG" for short) happens to be one of those---but fortunately it is still a simple process and can be done even with the advanced features turned off.

  • Start Game Maker and click the button on the toolbar that looks like a painting of a landscape. Click the "Load Background" button in the window that comes up, and choose an image from the file-browser dialog. Click "OK" to preserve your changes. This creates a background image resource (automatically named "background0"), that can be displayed on the screen ingame. Game Maker has no limit to the number of background resources you can have in a project---for this tutorial, we'll need two. Make the second background resource ("background1") by repeating the same steps.

  • Create a programmable object by clicking the button on the toolbar that looks like a blue ball. Click the "Add Event" button and choose "Key Press" > "Any Key" from the Event Selector. Switch to the Control tab of the Action Block palette, and drag an Execute Code block into the Actions panel. Type "background_index[0] = background1;" (minus the quotation marks) into the window that opens, and click the green checkmark button to keep the changes. This line of code will change the background to the second image that you created: the image named "background1."

  • Now make it so that the background image changes back again, when the key is released. Add a "Key Release" > "Any Key" event and give it an Execute Code block as well, this time with the code "background_index[0] = background0;". This will do the opposite of the first line of code, changing the background back to the first image: the image named "background0." Press "OK" to keep your changes to the object.

  • Create a room for your game to take place in by clicking the blue-bordered white box on the toolbar. Click on the "Backgrounds" tab and set the starting background for the room to "background0." Click anywhere inside the room to create an instance of your object. Now any key presses will be detected by it and acted on accordingly.

  • Click the green "Play" button to test your game. Once it loads, hold down any key to see the background change from "background0" to "background1." Release the key to change it back again.

Tips & Warnings

  • This line of background-changing code can be placed in any event for any object. You can make the background of your room change when an object collides with another, when a timer runs out or at any other event that you desire.

References

Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!