Articles Archive
Articles Search
Director Wiki
 

Comparing Text Display Methods

June 7, 2000
by Gary Rosenzweig

Sometimes, when you are building a game or other time-dependent application, you have to squeeze every bit of speed out of Director. This means finding creative ways to do things that can usually be done simply. One example is text display. In Director, all you need to do is plop down a text member and update its text property. However, this can be slow. Let's compare four different ways of displaying text.

The first way is to use a plain text member. As an example, we will loop and place 100 different random numbers into the member. Each number will be exactly 6 digits long. We'll time how long it takes to do this and come up with a frame rate based on this one simple example. Here is the script that does this:

property pStartTime, pFrame

on beginSprite me

  -- record starting time
  pStartTime = the milliseconds
  pFrame = 0

end

on exitFrame me

  -- get random six-digit number
  n = string(random(1000000)+1000000).char[2..7]

  -- set text or field member
  sprite(1).member.text = n

  -- count frames
  pFrame = pFrame + 1

  -- see if 100 frames have been counted
  if pFrame = 100 then
    -- put frame rate
    alert string(pFrame/((the milliseconds - pStartTime)/1000.0))&&"fps"
    go to frame 1
  else
    go to the frame
  end if

end

You can use the Shockwave application below to test out each of these methods. The "Nice Text" button uses an embedded font, anti-aliased.

On my Powerbook, I get about 80 fps for the "Nice Text" example. Next, let's take the anti-aliasing away and do it again. The "Plain Text" button does this. It improves the speed a bit, to about 120 fps. That's as fast as I was able to get text members to go. The score itself is set to 999 fps. This means that just this simple use of a text member is enough to slow it down from 999 fps to about 100 fps. Our next option is to use a field member. This old member type is far simpler than the newer text members. Instead of using an embedded font, I just used a system font. The results is a nice 250 fps.

In all three of these cases, I use the same behavior to generate the random numbers, fill the members, and track the frame rate. The last option is to not use text at all. Instead, we will use six bitmap members. Each will be set to a bitmap of a digit from 0 to 9. To be fair, they will each be 32-bit bitmaps. The result? 480 fps! This is surely the way to go when making score and time displays for fast-action arcade games. Lets look at the handler that sets the bitmaps. It assumes the bitmaps are sprites 1 through 6. It also assumes that there are members each named "0" through "9".

-- set six bitmaps to show number

on drawNumber me, n

  repeat with i = 1 to 6
    sprite(i).member = member(n.char[i])
  end repeat

end

A Director 8 sample movie is available for download in Mac or PC format.

This handler is called instead of the text property set in the earlier script. Other than that, the two behaviors used in the example are the same. Tests like these, called benchmark tests, are often used to determine the best way to perform a task. In Director, they are especially useful because there are so many ways to perform one single task.

Gary Rosenzweig's latest book is "Advanced Lingo for Games." In it, you can find the source code for more than 20 complete games. More information about the book can be found at http://clevermedia.com/resources/bookstore/book4.html. It can be purchased there, or in your local bookstore.

Gary Rosenzweig is the Chief Engineer, founder, and owner of CleverMedia, a game and multimedia development company in Denver, Colorado. He is the author of ten books on Macromedia Director and Flash, including his latest, Special Edition Using Director MX.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.