dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: improving my game's text boxes

  1. #1
    Member
    Join Date
    Sep 2004
    Posts
    40

    improving my game's text boxes

    How do I figure out how long in pixels a string of text will be? I know there is a function for this in Java, there should be one in flash too.

    If it helps, I'm trying to set up text boxes that type themselves out character by character. i can easily set up a counter to keep track of the end of the substring of the total text that i want displayed. however, I want to keep it from displaying more than two lines at a time. If it would proceed past 2 lines, I want it to pause until the user presses a button, then i want it to move up a line and type out the next line of the full text character by character on the second row of the textbox.

    obviously, i could just count how many characters it takes in a monospace font, but i was hoping not to have to limit myself to that.

  2. #2
    Member
    Join Date
    Sep 2004
    Posts
    40
    here's what i was thinking: I'll have three numbers as indexes and a string representing the total text i want displayed. one number is for the beginning of the first line, one is for the beginning of the second, and one is for the end of what has been typed so far. Characters between the first and the third are displayed in my two-line text box. They all start at 0. Each frame, the third number increments by one, then checks if the character at that location is a space. If it is, i would check the length of what has been written so far, plus what the length of the next word. If that sum is longer than the text box's width, it sets the second number to the value corresponding to the start of the next word. It then repeats the process until it exceeds the length of the text box again.
    At that point, it would stop and wait for the user to press the key to continue. when they do, the first number takes the value of the second number, the second number takes the value of the third number, and the third number starts incrementing and checking again. It appears that the text has scrolled up one line and is continuing to type itself out. The only thing missing is a way to check the length in pixels of a string of characters. I don't want to have to make all my text courier or something.

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    175
    put the text into a TextField and then check the textWidth property. what you could do to type the text char by char is create the text box at whatever size you want, then append a character each frame. each time you get to a whitespace character, see if the following word will fit entirely on the same line by adding the word, checking the textHeight property to see if it spilled over, then removing it. if it doesn't fit, if you're on the first line stick a newline character in before proceeding and if you're on the second wait for the player's go ahead before continuing. bit of a hack, should work though

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center