Gamemaker make text appear for set time

26 дек. 2013 г. в 11:08

There's a few ways to do this one, and there's pros and cons to all of them. The array method xmortus mentioned lets you do some cool things like put in color tags in the middle of strings and read them off in your code to change certain letters for things like Zelda's big red "THIS WORD IS IMPORTANT" indicators, but it makes alignments a bit more complicated and pretty much forces you into finding a fixed width font lest your text kerning look terrible. Alternatively, the method I use allows the font's own kerning to work, but the color tag thing and other such variations are significantly harder to pull off without some sort of work-around.

My method involves two string variables and one variable meant to hold your position. There is a function called string_char_at() that's pretty useful here, but essentially you'd have the first string be what you want to say and the second string start blank, adding one letter to it at a time.

//These would be declared in the Create event: FullText = "Hello World."; DisplayText = ""; Pos = 1; //string_char_at() starts at position 1, not 0, which is sort of abnormal. //Meanwhile, in the Step event: if Pos

I can't actually test run this on the computer I'm working from at the moment, so forgive me if GM has a fit about something in there. Given I didn't botch something, how that should work is that one more letter from FullText should be added to DisplayText each step. If Pos gets high enough that it would try to add a character that doesn't exist, the additional steps won't occur, which is put in place as I'm pretty sure trying to add non-existent characters gets you an out of bounds error and crashes your game.

All that's left to do, then, is actually draw the text in your Draw event, which should give you that progressive, typewriteresque effect.

Function references: string_char_at() [docs.yoyogames.com] , string_length() [docs.yoyogames.com] .