Hi. I’m clueless on how to figure out the best values for a scrolling headline thing for my game. I use it to sort-of communicate to users to let them know if the server is down or if there’s a bug. I have absolutely no clue. Can someone try and give me any ideas? Also, here’s the code for the text:
T is the time it takes to complete the interval, and X is the X co-ordinate. I need something to calculate what X should be, so that it goes off screen before restarting, and make T be a slow, yet sort-of quick speed so that people can read it. Example: If X is too big, and T is right, it will go too fast because X is far away, and it only knows it has to get there in that time. But, if X is right and T is too quick, it will zoom across the screen. And if T is too slow, it will have you on the edge of your seat with suspense and anticipation of what word will come next. Anybody have any ideas? if this is the wrong forum, please move this post to the correct one
Thank you for your help. I just need to figure out what to plus base.win.getXSize() (because that looks like it gets the x size lol) by. Different text lengths would call for a bigger value I need to add. I think I can find that value with base.win.getXSize() multiplied by 2, minus half of the text length. How do I get one half of a strings length is all I need to know now, and a google search could do that. But if the user goes fullscreen, it will break. That can be fixed by restarting the cycle with updated properties once a window size change is detected, so I need to also know how to detect window size changes. Do you know how to detect window size changes?
If you have a class that inherits from DirectObject you can do:
class MyThingObject (DirectObject):
def __init__(self):
#send an event when something happens to the window
self.accept( 'window-event', self.on_window_event)
self.window_x=base.win.getXSize()
self.window_y=base.win.getYSize()
def on_window_event(self, window=None):
if window is not None: # window is None if there is no open window
if self.window_x != base.win.getXSize() or self.window_y != base.win.getYSize():
self.window_x=base.win.getXSize()
self.window_y=base.win.getYSize()
self.on_window_resize()
def on_window_resize(self):
print "window has changed size!"
#do some other stuff
…or you can check in a task each frame if the current window size is the same as the last recorded window size - simpler, but I somehow find the solution above neat.
If I did this incorrect, can someone fix it?
P.S Thank you for that code wezu. Conveniently, the class of the GUI the news thing is meant to be in IS inherited from DirectObject.
You seem to calculate “leng” as the number of characters in the text; instead, you should either use the code wezu gave you earlier if you’re using a TextNode, or you could call get_tight_bounds on an OnscreenText if that’s what you’re using to display the text.
Also note that base.win.getXSize gives you the window width in pixels, but if you parented your TextNode or OnscreenText to aspect2d, then you need to calculate the window width differently.
The following might help: