Greetings. I figured I'd share a class I made about this -- it has the
slight aesthetic advantage of not using a list when it can use a string,
and that you can use an object that you can plug elsewhere.
-------------------------Here goes:
import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('', x=window.width/2, y=window.height/2,
anchor_x='center', anchor_y='center')
message = """Hello!
This is but a simple test of RPG text."""
class TIT():#text iterator.
def __init__(self,label,message):
self.n = 1
self.label = label
self.message = message
def iterate(self,dt):
self.label.text = self.message[:self.n]
if self.n != len(self.message):
self.n = self.n+1
elif self.n==len(self.message):
self.n = 1
pyglet.clock.unschedule(self.iterate)
Iterator = TIT(label,message)
@window.event
def on_draw():
window.clear()
Iterator.label.draw()
pyglet.clock.schedule_interval(Iterator.iterate, 1.0/15)
pyglet.app.run()
-------------------------End code.
The TIT object (yeah...I know, but I literally couldn't come up with a
better name) that you create takes a pyglet label and a python string, then
iterates over the latter and draws its label until it is finished, and then
it stops. That's it.
Hope it is of use. Laters.
:)
El lunes, 1 de julio de 2013 20:19:35 UTC-8, Paul Von Zimmerman escribió:
>
> How would I get text to display character by character? I was looking
> into using labels, because of the wrapping options we get, but there
> doesn't appear to be any easy way to delay the drawing of each character
> unless I make each individual character it's own label, which sort of
> eliminates the advantages we would gain from using labels in the first
> place.
> Would we just want to use individual labels (or sprites?) for each
> character, or is there a simpler way?
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.