pv3d

Dynamic Text on Transparent Background in Papervision3D

So, for the last couple of weeks I've been playing with the very cool Papervision3D library for Flash.  More specifically, I've been mucking around in the Effects branch of version 2.0 alpha, code-named GreatWhite.  One of the things I wanted to do was create a dynamic text field on a plane.  Luckily, I found this post, which gave me all I needed to know to get what I wanted, or at least I thought it did.  

I wanted my text on a transparent plane, so that it had no background.  Simple, I thought.  I'll just create the TextField, add it to a MovieClip and create a material out of said MovieClip.  Unfortunately, doing so will result in the ugliest text human eyes have ever beheld on a screen.  After a bit of trial and error, I came to this conclusion / solution:  Draw a rect below the TextField and give it a fill opacity of 0.  Doing this made my text look beautiful and I still had a transparent background.  My code looks like so:

 

  1.  
  2. var textMC : MovieClip = new MovieClip;
  3.  
  4. var textField : TextField = new TextField();
  5.  
  6. textField.wordWrap = true;
  7. textField.width = 800;
  8. textField.height = 150;
  9. textField.multiline = true;
  10. textField.text = "Default Text";
  11. textField.autoSize = TextFieldAutoSize.LEFT;
  12.  
  13. var textFormat : TextFormat = new TextFormat( "Arial" );
  14. textFormat.size = 36;
  15. textFormat.color = 0xFFFFFF;
  16. textField.setTextFormat( textFormat );
  17.  
  18. //Create a rect the size of the MovieClip with an opacity of 0
  19. //This lets the TextField render properly
  20. textMC.graphics.beginFill( 0x000000, 0 );
  21. textMC.graphics.drawRect( 0, 0, 800, 150 );
  22. textMC.graphics.endFill();
  23. textMC.addChild( textField );
  24.  
  25. var tfMaterial : MovieMaterial = new MovieMaterial( textMC, true, false, true );
  26. tfMaterial.smooth = true;
  27. tfMaterial.tiled = true;
  28.  
  29. var tmpPlane : Plane = new Plane( tfMaterial, 800, 150 );
  30.  

Handy Actionscript Utility

My buddy Chris Rebstock just posted on a project that he released to the world today.  Read his post to learn more about it.  Of course, I've had access to it for some time and I can say that it has made my life much easier.  Plus, if you read his post I'll tell you how to use a dynamic text field on a primitive in Papervision3D.  Think of the endless possibilities.

Close
E-mail It