Quick Question: How to get "width" of a text.Label?

18 views
Skip to first unread message

Blaine

unread,
Nov 7, 2012, 10:38:25 AM11/7/12
to cocos-...@googlegroups.com
Hi guys.

I've got a Label and I want to make it scroll off the screen, then repeat. With MoveTo() the scrolling isn't a problem, but I am having a heck of a time figuring out when the entire label is off screen. I imagine I can just take the x position (which will be negative), plus the width (or width/2 if we use center point) of the label, and restart it when this value is < 0.

However, I can't figure out how to tell the width of the Label. Pyglet.text.Label has content_width, but I can't find out how to access that either.

Hopefully it's something obvious. What do you say?

class ScrollingTextLayer(cocos.layer.Layer):
is_event_handler = True
def __init__(self, caption):
super(ScrollingTextLayer, self).__init__()        
x, y = director.get_window_size()
self.title = text.Label(
  caption, (x/2, y-50), font_name = 'Gill Sans',
  font_size = 64, anchor_x='center', anchor_y='center' )
self.add( self.title )

def on_enter(self):
super(ScrollingTextLayer,self).on_enter()
move = MoveBy((-800, 0), 1)
self.title.do( move )

Blaine

Blaine

unread,
Nov 7, 2012, 10:42:25 AM11/7/12
to cocos-...@googlegroups.com
Found it! Nevermind.

Future googlers:
self.title.element.content_width

(see: dir(self.title.element))
Reply all
Reply to author
Forward
0 new messages