Articles Archive
Articles Search
Director Wiki
 

"Star Wars" Crawl: The Texture Generation

June 22, 2001
by Colin Holgate

Every now and then someone will post a question to one of the lists: "How do I do scrolling text like you see at the start of Star Wars?". The answers vary, but will usually involve moving a text member up the screen, or perhaps a bitmap to get better performance. To get a reasonable perspective effect, someone might suggest using quads on either a text member or a bitmap. One thing that all of those techniques have in common is that they're not good enough!

You can get perfect results by pre-rendering an animation using something like After Effects, but where's the fun in that? What we really want to do is animate live, and possibly even change the text (you might want to include the user's name for example). Although it's not really intended to do this kind of job, it happens that you can get a fairly good imitation of the effect by applying the text in question as a texture on a plane in one of Director 8.5's new 3D cast members. This article has a simple example of the technique, as can be seen here. You'll need Shockwave 8.5 to see it in your browser.

It's easy enough to do this that we'll look at the entire script, which will help to show some other basic tricks, as well as the ones specific to the scrolling text. The movie has only one script: a movie script. Here it is, with a bit of interspersed commentary:

global w,pm

on startmovie

  w = member ("world")
  w.resetworld ()
  planetosee
  stars
  starttimer

end

Using variables as pointers to objects really comes into its own when dealing with 3D. Instead of having to follow the syntax as shown in the Help, you can set a variable that points all the way down to the object in question, then just modify the properties that way. The startmovie handler sets up variable w, which is then used in the other handlers below. The resetworld method is used to make sure that the world is set back to its start state, and prevents a second run of the movie from creating models with the same name.

on planetosee

  pr = w.newmodelresource ("plane", #plane)
  pm = w.newmodel ("plane", pr)
  ti = member ("text").image.duplicate ()
  pr.width = ti.width
  pr.length = ti.height
  pt = w.newTexture ("plane", #fromImageObject, ti)
  pt.quality = #high
  pt.renderformat = #rgba4444
  ps = w.newshader ("plane", #standard)
  pm.shader = ps
  pm.shader.texture = pt
  pm.transform.rotation = vector (90, 180, 0)
  w.camera (1).transform.position = vector (0, 0, 0)
  w.camera (1).transform.rotation = vector (-10, 0, 0)

end

Again, a variable (pm) is set up to point directly to the plane model. It really makes the next handler pretty short! The image of the text member that holds the text to show is applied as a texture using the fromImageObject option of newTexture. The quality is set to high, to give it the best chance of being readable as it goes off into the distance, and the renderformat is set to rgba4444. This is the key to the whole effect; by using 4 bits of alpha for the texture, the text appears to have 16 levels of anti-aliasing against the star background. You could use rgba8888 to get more levels, or to see more colors, but for white text there was no need, 4 bits is enough.

on backup

  pm.transform.position = vector (0, -500, 0 - the timer)

end

This simply moves the plane backwards along the Z axis, based on the timer. The text therefore moves at a constant speed; it will take the same time to scroll on a slower machine as on a faster machine, but it will go more smoothly on a faster machine.

on stars

  t = w.newTexture ("stars", #fromCastMember, member("stars"))
  t.quality = #high
  w.camera (1).addBackdrop (t, point (0, 0), 0)

end

You can have both overlays and backdrops in a 3D scene. The backdrop is just a texture applied to the camera. It actually becomes a new model in the 3D world, but you don't have to worry about orientation, it just sits there at a right angle to the camera, behind everything else in the scene.

on exitFrame me

  backup
  go the frame

end

Nothing too exciting here, the movie stays on the frame, and tells the plane to move back each exitframe.

Try playing with the movie, and changing the text of the text member. You'll quickly see that it is doing the effect live, and you'll see your text moving off into the distance with a very fine resolution of movement. It's a lot better than moving a sprite a pixel up the screen!

The source Director 8.5 movie is available for download in Mac or Windows format.

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