GameMaker: Studio

GameMaker: Studio

İstatistiklere Bak:
Triggering a Draw Event
Hello again forum! I've got a little question here:

I'm trying to move along dialogue by the player pressing the spacebar.

However, text only draws in the occasion of a draw event.

Is there a possible way to trigger a draw event from keyboard input so I may delete and draw new text on the game?
< >
9 yorumdan 1 ile 9 arası gösteriliyor
Yep, there are multiple ways to accomplish this kind of effect. But what you need to realize first is that the draw event works just like the step event, in that it happens once per frame.

Therefore, you can feed the draw event a dialogue string like so:

draw_text(x, y, dialogue_string_variable);

If you change the value of that variable, the text will update in the next frame. So make the spacebar press trigger an update to that dialogue variable.

If you have a lot of dialogue, it might be a good idea to store the text in an array (in the create event, or as a global variable).

current_dialogue = 0; dialogue[0] = "Hello!"; dialogue[1] = "My name is Steve."; dialogue[2] = "Would you like to buy something from me?";

And when you hit the spacebar, increment that current dialogue as the array index:

if (keyboard_check_pressed(vk_space)) { current_dialogue += 1; dialogue_string_variable = dialogue[current_dialogue]; }

Hope this helps you!

EDIT: And make sure you're only having the spacebar increment dialogue while the dialogue is actually being displayed. Also make sure you stop the dialogue from incrementing passed the arrays total length (in this case "2") or the game will crash.
En son Thew tarafından düzenlendi; 25 Tem 2014 @ 7:25
İlk olarak Thew tarafından gönderildi:
Yep, there are multiple ways to accomplish this kind of effect. But what you need to realize first is that the draw event works just like the step event, in that it happens once per frame.

Therefore, you can feed the draw event a dialogue string like so:

draw_text(x, y, dialogue_string_variable);

If you change the value of that variable, the text will update in the next frame. So make the spacebar press trigger an update to that dialogue variable.

If you have a lot of dialogue, it might be a good idea to store the text in an array (in the create event, or as a global variable).

current_dialogue = 0; dialogue[0] = "Hello!"; dialogue[1] = "My name is Steve."; dialogue[2] = "Would you like to buy something from me?";

And when you hit the spacebar, increment that current dialogue as the array index:

if (keyboard_check_pressed(vk_space)) { current_dialogue += 1; dialogue_string_variable = dialogue[current_dialogue]; }

Hope this helps you!

EDIT: And make sure you're only having the spacebar increment dialogue while the dialogue is actually being displayed. Also make sure you stop the dialogue from incrementing passed the arrays total length (in this case "2") or the game will crash.

Thanks for the reply, I'll edit to showya if this worked for me :)
I made the variables global.Tutorial_Dialogue and global.Tutorial_Dialogue_Progression

Whenever space is pressed, it increases global.Tutorial_Dialogue_Progression.

Then there's a whole mess of if statements that change the string in global.Tutorial_Dialogue.

Works great :)

One lil' thing that's bugging me though. Is it possible to indent or paragraph the text that you draw? At most I want to have 2 lines showing at a time, but this makes it look like we can only use 1.
Are you saying you want the text to wrap down to the next line? Use draw_text_ext():

// draw_text_ext(x position, y position, string, separation between lines (-1 for default), width of text before automatic line break) // example draw_text_ext(x, y, dialogue_string_variable, -1, 100);

You can also use the hash "#" character inside a string to force a line break.
my_string = "Hello! #This is on a new line!";
En son Thew tarafından düzenlendi; 25 Tem 2014 @ 21:22
Thanks for all the help.
No problem. Hope you got it figured out!
I did exactly the same thing you typed, but for some reasons, i got a error message. So I changed just a few things :

In the Draw event , i type

draw_text(x,y,dialogue[current_dialogue])

And all is working perfectly !! It seems that the command "dialogue_string_variable" wasn't recognized by Game Maker.
En son Chopper25 tarafından düzenlendi; 12 Haz 2015 @ 6:38
Just thought I'd add that GM:S has a built in variable to deal with turning on/off an objects draw events. If the only thing the object is drawing is text related and your simply checking an if statement before drawing it may be simply to simply say
visible = falseGame
and turn off the draw event for the specific instance. You can set it to true to turn the draw event back on.
İlk olarak Chopper25 tarafından gönderildi:
I did exactly the same thing you typed, but for some reasons, i got a error message. So I changed just a few things :

In the Draw event , i type

draw_text(x,y,dialogue[current_dialogue])

And all is working perfectly !! It seems that the command "dialogue_string_variable" wasn't recognized by Game Maker.

"dialogue_string_variable" was just an example of a variable I created to demonstrate how to display simple dialogue. It's not a built-in constant or function. You can name variables whatever you want.

In retrospect, I'm not sure I would use an array in this case. Arrays in Gamemaker are pretty slow and buggy. It's probably better to store your dialogue strings in a data structure or an external file.
< >
9 yorumdan 1 ile 9 arası gösteriliyor
Sayfa başına: 1530 50

Gönderilme Tarihi: 25 Tem 2014 @ 5:54
İleti: 9