GameMaker Programming By Example by Brian Christian & Steven Isaacs

GameMaker Programming By Example by Brian Christian & Steven Isaacs

Author:Brian Christian & Steven Isaacs [Christian, Brian]
Language: eng
Format: epub, pdf
Publisher: Packt Publishing
Published: 2015-12-27T23:00:00+00:00


Textboxes

Congrats! You've made it this far, and have only one thing left to program, a textbox. Unfortunately, GameMaker has no built-in functions for this, which is quite surprising, as most games use a textbox, so we will need to do this on our own. Now, you might say, "What was wrong with the show_message function?" A couple things. If you want a game with a nice UI that looks clean, you probably don't want to use that function. It's a dialog box; these are usually for errors or important prompts. Also, that function is for debug purposes, and is not intended for release. In fact, we commonly used it to see the values of variables or to see whether something had ran properly when we were making these games.

So we're going to make a textbox. Unfortunately, you will need to pay very close attention to what we are about to do, as this is actually a rather complex (yet not impossible) and somewhat difficult thing to implement. We will try to explain it as best we can for you to understand, and recommend for this section, as we did with the random spawning, that you use the values we do. So let's start. Make an object for the textbox. Set its depth to -90, so that it renders beneath the pause menu, and give it a Create event, in which the variables height and width are set to 128. These will be for the height and width of the textbox. Next, set the variable padding to equal 8. This will be how much blank space there should be from the text to the edges of the box. Now, we get into some of the more complex stuff—data structure (DS) lists. These are very similar to one-dimensional arrays; however, they are more dynamic and flexible, and allow us to do more such as shuffle values, change their sorting, or put values in anywhere. That doesn't mean you should abandon arrays, as for one, there are no 2D DS lists, and two, DS lists take up more memory and we don't always need them. Anyway, create a DS list called start by setting the variable start equal to ds_list_create(). It will hold the different places at which a new line has been printed (in a number, which is the placement of the character that begins the line). Now set the variables count, last_space, and line to 0. These represent the current spot in the string we will be printing, the place in the message where the last space printed was, and the current line we are printing on. Now set the variable message equal to global.msg + "#Hit Enter to continue.", which conjoins the two strings. The # symbol represents a newline. Then, set the variable str equal to a completely empty string, and it will be the current line of text that we are printing, whereas the message is the whole string. Now set the variable global.text_box_finished to false.

Now add a Destroy event, and destroy the DS list with ds_list_destroy(id), where id should be start for us.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.