YoYo Games Wiki

Fancy Help

From YoYoGames Wiki

It is very important to provide help during the game on how to play the game. This is even more important now that games on YoYo Games are played with InstantPlay. Adding a document to describe how to play the game is not going to work anymore as people won’t see it.

Downloading the Script

You can of course use the Game Information mechanism in Game Maker but that is rather limited and does not look very nice. It is though very easy to create your own fancy in-game help system. It requires a single script and some nice images that form the help pages. The script you need and an example can be downloaded here:

The download is a 760 kB zip file containing a GM7 example and a GM7 script. This requires the Pro (registered) version of GM7.

Using the Script

Simply import the script in the file fancy_help.gml into your game. Now create some help images (e.g. jpg or bmp files) that contain the different help pages. You can use any drawing program to make them look as nice as you want. They should all have the same size but they can be smaller than the room size (that actually makes it look extra fancy). They are placed in the same folder as the game executable, so we do not include them in the actual game. This saves a lot of memory and game loading time.

Assume you made three images help1.jpg, help2.jpg and help3.jpg. Create a controller object (without a sprite) that you place in every room. (Or make it persistent and place it only in the first room.) Add a Key Press event for the F1 key and in it add an action to call the script with as arguments: 3 (for the number of images), "help1.jpg", "help2.jpg" and "help3.jpg". (Don't forget the quotes. These are strings.) That is all that needs to be done.

The zip file contains an example of its use. Here is a typical result:

Image:GM_Fancy_Help.jpg


How It Works

All the work is done by a single script. It takes as argument the number of help screens, and the filenames (as strings; don't forget the quotes). The script consists of three parts. In the first part we grey-out the current image on the screen. Here is the code for that:

 var oldcol,oldalpha;
 oldcol = draw_get_color();
 oldalpha = draw_get_alpha();
 draw_set_color(c_white);
 draw_set_alpha(0.5);
 draw_rectangle(0,0,room_width,room_height,false);
 draw_set_color(oldcol);
 draw_set_alpha(oldalpha);

It stores the current color and alpha values, draws a partially transparent rectangle over the current room, and restores the old values. You can change the color and alpha settings of the grey-out rectangle if you want.

Next we will draw the actual help images. To this ene we create a background resource. We loop through the different argument file names, check whether the file exists, replace the background with it, draw it in the center of the room, refresh the screen to make it visible, and wait for the user to press a key. The code looks as follows:

 var helpimg,i,xxx,yyy;
 helpimg = background_create_color(640,480,c_black,true);
 for (i=1; i<=argument[0]; i+=1)
 {
   if (!file_exists(argument[i])) continue;
   background_replace(helpimg,argument[i],false,false,true);
   xxx = (room_width-background_get_width(helpimg))/2;
   yyy = (room_height-background_get_height(helpimg))/2;
   draw_background(helpimg,xxx,yyy);
   screen_refresh();
   keyboard_wait();
 }

Finally we need to clean-up the stuff and in particular redraw the room to make it visible in the normal way again.

 background_delete(helpimg);
 io_clear();
 screen_redraw();

That is all. (Note that you do not need to understand any of this to actually use the script!).