Rayne Aven
Member
Hi, I'm having a problem making a message system in RGSS that displays a message letter by letter rather than all at once. Here's my code:
(Note: This is a very simple message system that I just made to try to teach myself Ruby/RGSS as I'm new at it. I wrote all the code myself, so if something confuses you while reading it, I can definitely make it clearer.)
The script takes input text and displays it character-by-character, unless that character is '^', in which case it deletes that character and pauses for 10 frames before continuing to display more text. It actually works pretty well. The only problem I'm having is that using Graphics.update pauses not only the text display but everything else, as well. For instance, one scene in which I tried to use it also has the "rain" weather effect occurring. Whenever the game pauses to display text, the rain and other sprite animations also pause. The conclusion I came across was that I'm not supposed to be using Graphics.update, but my attempts at deciphering other, more advanced message systems for the solution have been fruitless. So, I'm asking for help. How can I make the game display text letter-by-letter without using Graphics.update (or taking someone else's message system).
Code:
# This class will make a the window text appear letter by letter...
# ...rather than all at once
class Window_Speech3 < Window_Base
def initialize(id, awidth, line1, line2, line3, line4)
if (($game_map.events[id].x - $game_map.display_x/128) * 32 - (awidth/2.4) < 0)
x = 0
else
x = ($game_map.events[id].x - $game_map.display_x/128) * 32 - (awidth/2.4)
end
if (($game_map.events[id].y - $game_map.display_y/128) * 32 - 160 < 0)
y = 0
else
y = ($game_map.events[id].y - $game_map.display_y/128) * 32 - 160
end
if (line4.length != 0)
aheight = 128
elsif (line3.length != 0)
aheight = 104
y = y + 24
elsif (line2.length != 0)
aheight = 80
y = y + 48
else
aheight = 56
y = y + 72
end
super (x, y, awidth, aheight)
self.contents = Bitmap.new(width - 32, height - 32)
speak(line1, line2, line3, line4)
end
def speak(line1, line2, line3, line4)
$game_switches[2] = true
for i in 0...line1.length
if line1[i, 1] == "^"
line1.slice!(i, 1)
for j in 0...10
Graphics.update
end
redo
end
self.contents.clear
self.contents.draw_text(0, 0, 448, 24, line1[0, i+1])
Graphics.update
end
for i in 0...line2.length
if line2[i, 1] == "^"
line2.slice!(i, 1)
for j in 0...10
Graphics.update
end
redo
end
self.contents.clear
self.contents.draw_text(0, 0, 448, 24, line1)
self.contents.draw_text(0, 24, 448, 24, line2[0, i+1])
Graphics.update
end
for i in 0...line3.length
if line3[i, 1] == "^"
line3.slice!(i, 1)
for j in 0...10
Graphics.update
end
redo
end
self.contents.clear
self.contents.draw_text(0, 0, 448, 24, line1)
self.contents.draw_text(0, 24, 448, 24, line2)
self.contents.draw_text(0, 48, 448, 24, line3[0, i+1])
Graphics.update
end
for i in 0...line4.length
if line4[i, 1] == "^"
line4.slice!(i, 1)
for j in 0...10
Graphics.update
end
redo
end
self.contents.clear
self.contents.draw_text(0, 0, 448, 24, line1)
self.contents.draw_text(0, 24, 448, 24, line2)
self.contents.draw_text(0, 48, 448, 24, line3)
self.contents.draw_text(0, 72, 448, 24, line4[0, i+1])
Graphics.update
end
end
end
(Note: This is a very simple message system that I just made to try to teach myself Ruby/RGSS as I'm new at it. I wrote all the code myself, so if something confuses you while reading it, I can definitely make it clearer.)
The script takes input text and displays it character-by-character, unless that character is '^', in which case it deletes that character and pauses for 10 frames before continuing to display more text. It actually works pretty well. The only problem I'm having is that using Graphics.update pauses not only the text display but everything else, as well. For instance, one scene in which I tried to use it also has the "rain" weather effect occurring. Whenever the game pauses to display text, the rain and other sprite animations also pause. The conclusion I came across was that I'm not supposed to be using Graphics.update, but my attempts at deciphering other, more advanced message systems for the solution have been fruitless. So, I'm asking for help. How can I make the game display text letter-by-letter without using Graphics.update (or taking someone else's message system).