SHOW:
|
|
- or go back to the newest paste.
1 | //######################################################### | |
2 | /// this is not my work , i just saved to use in the future | |
3 | /// this is the author profile link | |
4 | /// https://pastebin.com/SFk03CcJ | |
5 | /// and his youtube channel | |
6 | /// https://www.youtube.com/watch?v=3QUwo4_g3uw&ab_channel=MusicalKittehs | |
7 | /// Description: Draws text scrolling from the first to last character in a string. | |
8 | /// Usage: draw_text_scrolling(0, 0, "Hello World", 0.5, 20, undefined) | |
9 | ||
10 | /// @param text x | |
11 | /// The x position of the text being drawn. | |
12 | ||
13 | /// @param text y | |
14 | /// The x position of the text being drawn. | |
15 | ||
16 | /// @param text string | |
17 | /// The text string to be scrolled across the screen. | |
18 | ||
19 | /// @param text speed | |
20 | /// The speed of the text scrolling. (Range: [0.0] to [1.0]) | |
21 | ||
22 | /// @param text sleep | |
23 | /// The time in frames to sleep on pausing characters. (Ex. [.] [,] [!] [?]) | |
24 | ||
25 | /// @param text sound | |
26 | /// The sound to play after each character scroll. (Ex. [undefined] [sound_talk]) | |
27 | ||
28 | //######################################################## | |
29 | function draw_text_scrolling(text_x, text_y, text_str, text_spd, text_slp, text_snd){ | |
30 | ||
31 | #region SOURCE CODE | |
32 | ||
33 | //Checks if the index counter has been defined. | |
34 | if !variable_instance_exists(self.id, "_text_char"){ | |
35 | ||
36 | //Defines the counter variables. | |
37 | _text_char = 0; | |
38 | _text_prev = 0; | |
39 | _text_sleep = 0; | |
40 | ||
41 | } | |
42 | ||
43 | //Gets the current character index. | |
44 | var text_ind = floor(_text_char); | |
45 | var text_chr = string_char_at(text_str, text_ind); | |
46 | ||
47 | //Checks if the text index isn't the final char. | |
48 | if (text_ind != string_length(text_str)){ | |
49 | ||
50 | //Checks if the text is not sleeping. | |
51 | if (_text_sleep == 0){ | |
52 | ||
53 | //Checks if the following character is a sleep identifier. | |
54 | if !((text_chr == ".") || (text_chr == ",") || (text_chr == "?") || (text_chr == "!")){ | |
55 | ||
56 | //Increments the character counter. | |
57 | _text_char += text_spd; | |
58 | ||
59 | //Maxes out the character counter at the string length. | |
60 | _text_char = min(_text_char, string_length(text_str)); | |
61 | ||
62 | //Checks if the character has been fully incremented. | |
63 | if (text_ind > _text_prev) && (text_snd != undefined) && audio_exists(text_snd){ | |
64 | ||
65 | //Plays the text sound. | |
66 | audio_stop_sound(text_snd); | |
67 | audio_play_sound(text_snd, 0, false); | |
68 | ||
69 | } | |
70 | ||
71 | //Sets the previous value to the char index. | |
72 | _text_prev = text_ind; | |
73 | ||
74 | }else{ | |
75 | ||
76 | //Starts the sleeping process. | |
77 | _text_sleep = text_slp; | |
78 | ||
79 | } | |
80 | ||
81 | }else{ | |
82 | ||
83 | //Checks if the final frame of waiting. | |
84 | if (_text_sleep == 1){ | |
85 | ||
86 | //Increments the character past the sleep identifier. | |
87 | _text_char = text_ind + 1; | |
88 | ||
89 | } | |
90 | ||
91 | //Decrements the text sleep. | |
92 | _text_sleep--; | |
93 | ||
94 | } | |
95 | ||
96 | } | |
97 | ||
98 | //Draws the scrolling text. | |
99 | draw_text(text_x, text_y, string_copy(text_str, 1, text_ind)); | |
100 | ||
101 | #endregion | |
102 | ||
103 | } | |
104 | //######################################################## | |
105 | /// | |
106 | /// Created by Kupoapo | |
107 | /// | |
108 | //######################################################## |