- //argument0 = the text
- //argument1 = whether or not to draw the box at the end
- //argument3 = whether or not to draw the text box
- //` = white text
- //{ = blue text
- global.drawingtext = true //the game is drawing text
- if argument2 = true //if it is the first time through
- self.position = 1//set the position as 1
- }
- global.more = argument1
- global.font = spr_letters //set the font at the beggining of the script
- //sets the postion of the pointer, so it knows how much text should be drawn
- if keyboard_check(vk_enter) = true //if enter is pushed
- self.done = true //you are done
- self.position = string_length(global.text) //end the text
- self.curstring = global.text //set the string to the text
- keyboard_clear(vk_enter) //stop generating events
- if self.done = false //if the text line isn't done
- self.curstring = string_copy(global.text, 1, self.position) //the first line is a part of the actual first line
- if string_length(self.curstring) = string_length(global.text) //if the text is done
- self.done = true //this line is done
- }
- if self.done = false //if not all text is done
- self.position += 1 //add one to the position
- if argument3 = true //if you should draw the text box
- draw_sprite(spr_textbox, 0, view_xview[1] + 16, view_yview[1] + 160) //draw the text box
- self.pointx = 22 //a little to the right...
- for(i = 1; i < string_length(self.curstring) + 1; i += 1) //once for every character
- self.lettertemp = string_copy(self.curstring, i, 1) //get the letter
- {
- self.pointy += 16 //go down a line
- if self.lettertemp <> ' ' and self.lettertemp <> '~' //if it isn't a space or a tilde
- if self.lettertemp <> '`' and self.lettertemp <> '^' and self.lettertemp <> '{' and self.lettertemp <> '}' //if it's not changing the font
- self.todraw = scr_getletter(self.lettertemp) //get the imagesingle of the value
- draw_sprite(global.font, self.todraw, view_xview[1] + self.pointx, view_yview[1] + self.pointy)
- }
- {
- {
- }
- {
- }
- {
- }
- {
- }
- }
- {
- }
- {
- self.pointy += 16 //move down for the next letter
- self.pointx = 22 //reset to the start of the line
- }
- screen_refresh() //refreshes the screen so you can actually see it
- if self.done = true and global.more = true //if we need to draw an arrow
- draw_sprite(spr_textmore, 0, view_xview[1] + 155, view_yview[1] + 216) //draw the arrow
- {
- sleep(30)
- scr_dialogbox(argument0, argument1, false, argument3) //do it all again
- else //yer done!
- screen_refresh() //refresh the screen
- sleep(30)
- keyboard_clear(vk_shift)
- global.drawingtext = false //get on with your regular life
- ___________________________________________________________________________________________________________________
- letter = argument0
- if ord(letter) >= ord('A') and ord(letter) <= ord('Z') //if it is an uppercase letter
- return (32 + (ord(letter) - ord('A'))) //return a value for the letter
- if ord(letter) >= ord('a') and ord(letter) <= ord('z') //if it is a lowercase letter
- return (64 + (ord(letter) - ord('a'))) //return a value for the letter
- if letter = '!' //exclamation mark
- return 0
- if letter = '' //quotations
- return 1
- if letter = '#' //number sign
- return 2
- if letter = '$' //dollar sign
- return 3
- if letter = '%' //percent sign
- return 4
- if letter = '&' //ampersand
- return 5
- if letter = '' //semi-qute
- return 6
- if letter = '(' //parentheses
- return 7
- if letter = ')' //parentheses
- return 8
- if letter = '*' //asterisk
- return 9
- if letter = '+' //plus sign
- return 10
- if letter = ',' //comma
- return 11
- if letter = '-' //dash
- return 12
- if letter = '.' //period
- return 13
- if letter = '/' //slash
- return 14
- if letter = '0' //0
- return 15
- if letter = '1' //1
- return 16
- if letter = '2' //2
- return 17
- if letter = '3' //3
- return 18
- if letter = '4' //4
- return 19
- if letter = '5' //5
- return 20
- if letter = '6' //6
- return 21
- if letter = '7' //7
- return 22
- if letter = '8' //8
- return 23
- if letter = '9' //9
- return 24
- if letter = ':' //colon
- return 25
- if letter = ';' //semi colon
- return 26
- if letter = '<' //less than
- return 27
- if letter = '=' //equal to
- return 28
- if letter = '>' //greater than
- return 29
- if letter = '?' //question mark
- return 30
- if letter = '@' //at sign
- return 31
- if letter = '[' //bracket
- return 58
- if letter = ' //slash
- return 59
- if letter = ']' //bracket
- return 60
- if letter = '^' //carot
- return 61
- if letter = '_' //underscore
- return 62
- if letter = '' //quotation mark
- return 63
- Write some text and click Submit to get your own personal speech bubble. This site is inspired by, but not affiliated with, the excellent comic diesel sweeties.
- Drawtextext(100, 50, keyboardstring, 3, 300); The above code will draw whatever text the user types into the keyboard, splitting it onto new lines every time the string length for that line exceeds 300 pixels. The code will also maintain a separation of 3 pixels between lines should this occur.
A game with dialogue can be drastically improved with a 'typewriter' effect, in my opinion at least. Not only is it aesthetically pleasing, but can ease the burden of a lot of text on-screen. Though this example is written for Game Maker, it can be adapted to other languages with ease.
Use the Draw Event in GameMaker: Studio when you want to display something during the game. The Draw Event does have its own submenu, as shown in this figure.
If you use a Draw Event, GameMaker no longer defaults to the assigned Sprite, and instead you have to tell GameMaker what to draw.
Scrolling Text Box Myspace
The different options from the submenu include
Text Box Excel
Draw: The standard Draw Event should be sufficient for most of your needs. The Draw Event enables you to place code or Actions for an Object, and those Actions and code override the default draw, which would be the assigned Sprite.
This is useful, for example, if you want to replace the assigned Sprite with text to display a message. This Event is called once per View, while the other Draw Events are drawn each step of the game.
All Objects with an assigned Sprite with Visible toggled on (from the Object Properties window, as shown here) automatically trigger a default Draw Event every step of the game. GameMaker does this for you, which is nice, because you don’t have to assign a Draw Event for each Object with an assigned Sprite to have it appear in the game.
Select the Visible check box to automatically trigger a default Draw Event.Draw GUI, Draw GUI Begin, and Draw GUI End: GUI is an acronym for graphical user interface. The GUI is not affected by the View scale or rotation. Instead, the GUI is drawn on a separate layer than, say, the background.
A Draw GUI Event is great for creating a heads-up display (HUD), which can show a player’s health, ammo, weapon type, a mini map, and so on. As with the other Begin and End Events, the Draw GUI Begin and Draw GUI End Events determine the order of what’s drawn.
Draw Begin and Draw End: These two Events do exactly as they say: They make sure that something is drawn in the game either before or after the standard Draw Event. Using these Events is a great way to make sure items are drawn in the order you want them to appear.
The Draw Begin, Draw, and Draw End Events all run before the Draw GUI Events and between the PreDraw and PostDraw Events. This has significant meaning in that all these Events are drawn beneath the Draw GUI Event, no matter what the Depth is set at.
PreDraw and PostDraw: The PreDraw and PostDraw Events are drawn directly to the screen buffer, which is the combined screen space for all Views currently visible, or the window size if you don’t use Views.
The PreDraw Event is triggered before any other Draw Events, which means you can use it to set values, set draw properties, and, of course, draw things. The PostDraw Event runs after the other Draw Events but before the Draw GUI Event.
You need to deselect the Clear Background with Window Colour check box in the Room editor for PreDraw and PostDraw Events to work. This figure shows where to deselect this feature (the default setting has it selected). You also need to make sure that a background color is not drawn; you do this on the Background tab.
Do not select Clear Background with Window Colour for PreDraw and PostDraw Events.If you turn off the View Clearing and disable drawing a background color, you might experience trails (leftover traces of images) during gameplay. These trails happen because now you’re drawing directly over the previous frame without it being cleared.
You can use code to help solve this potential problem, which is draw_clear_alpha. You can place this code in an Execute Code Action within the PreDraw or PostDraw Event.
Resize: The Resize Event is used specifically for Windows 8 games and doesn’t actually draw anything in the game. Instead, the Resize Event is to help snap the game window when the player moves that window to the side of the screen.
If you’re familiar with working in a Microsoft Windows environment, you’re aware that if you’re working in a window and you drag the top of the window to the top of your screen, Windows will snap the bottom of the window to the bottom of the screen. This Event is triggered every time the player resizes or moves the game window.