Silverlight vs Flash: Simple XML Parser Flash vs Silverlight Gallery
Sep 12

This is the first application request by reader (submitted by Slyi). He saw a very interesting text effect implemented by JavaScript and he would like to migrate this to the Silverlight. I think this sample can be easily adopted by Silverlight.net since I greatly promoted their Product. ^_^

There will be no post tomorrow. It’s because I will spend my time too arrange all of my samples and make a show case gallery.

Comparison

Flash implementation: 30 minutes  
Silverlight implementation: 1 hour (Implemented First)
What’s the difference?

  • flash.text.TextField [AS3] vs System.Windows.Controls.TextBlock [C#]

Source codes

Flash

Silverlight

flash.text.TextField [AS3] vs System.Windows.Controls.TextBlock[C#]

Creating a text field in AS3 looks similar to that of C#. However, the TextFormat class makes styling of AS3 text easily. Besides, the text field in Flash supports HTML Text as well. (If I am not wrong, Silverlight doesn’t have any support for HTML Text.)

// AS3
// create text format
var format : TextFormat = new TextFormat();
format.size = FONT_SIZE;
format.font = FONT_FAMILY;
format.color = 0x0000FF;

// create the text block
var textField : TextField = new TextField();
textField.text =  "text";
textField.setTextFormat(format);
textField.selectable = false;
addChild(textField);

// get the actual width and height
var actualWidth:Number = textField.textWidth;
var actualHeight:Number = textField.textHeight;

The source file size of Flash is larger than Silverlight. It’s because I have embed the font in the FLA. You can see that even no font is embed in Silverlight, it still handles the text quite well. Hence, my vote is for Silverlight this time.

Moreover, Slyi found that animating the text will consume a lot of resources. What do you think ?

Note:
Performance Tip: Animating the size of text can potentially use a lot of system resources. This is because when Silverlight renders text, it uses hinting to smooth each text glyph. If you animate the text size (by using a Transform or FontSize), Silverlight will hint the glyphs for each frame, which is costly and could cause frame dropping. If your application requires dynamic scale changes of large text, it may be better to use vector graphics to represent the text.
http://msdn.microsoft.com/en-us/library/cc189010(VS.95).aspx

// C#
// create the text block
TextBlock textBlock = new TextBlock();
textBlock.Text = "text";
textBlock.FontSize = FONT_SIZE;
textBlock.FontFamily = new FontFamily(FONT_FAMILY);
textBlock.Foreground = new SolidColorBrush(Colors.Blue);
textBlock.TextAlignment = TextAlignment.Center;
LayoutRoot.Children.Add(textBlock);

// get the actual width and height
double actualWidth = textBlock.ActualWidth;
double actualHeight = textBlock.ActualHeight;

Shares and Enjoy~

Did you like this post?

Subscribe here:  

11 Responses to “Silverlight vs Flash: Waving Text”

  1. unruledboy Says:

    it seems that the fl is faster then sl, am I wrong?

  2. slyi Says:

    This is wonderful and great perfermance even better perf than the orginal JS http://www.dhteumeuleu.com/run/txtSIN/

  3. Paul Sanderson Says:

    in feb this year i started this http://www.wscoop.com and it was posted about…

    But I need your help….

    I need links to web design and development, site , articles links…… anything you think of….

    Please are you able to help me make this into a great resource for developers and designers.

  4. admin Says:

    unruledboy, yes, Flash one is faster. The one in Flash is using EnterFrame Event while the one in Silverlight is DispatcherTimer. Althgout I don’t understand why now, I think it’s related to the implementation method.

    I think I will try to use Timer to compare with DispacherTimer later.

    Paul, no problem, I will try to submit that.

  5. Fallon Massey Says:

    You should probably always set the frame rate in SL animation apps.

  6. Shane Ng Says:

    Slyi, I think the original JS version is a bit different from the AS version. I translated the AS version back to the equivalent JS. The performance is about the same.
    http://killustar.blogspot.com/2008/09/shinedraw-in-javascript-waving-text.html

  7. admin Says:

    Shane, thanks for the sample.

    May be can make some stress tests and test over their performance.

  8. Silverlight Cream for September 12, 2008 -- #367 Says:

    [...] Silverlight vs Flash: Waving Text [...]

  9. Elroy Says:

    Hello admin, nice site you have!,

  10. SLrules Says:

    Silverlight is rendering the actual TTF/OTF fonts in real-time, rather than simply some arbitrary vector shapes that happen to resemble fonts as Flash does.

  11. Mark Rideout Says:

    There are two Silverlight items here that should be fixed: 1 - The Silverlight version should use Glyphs element vs TextBlock and 2 - The Silverlight version on Silverlight 3 should use TextHintingMode=”Animated” to correctly account for the fact that you are not trying to render this text for UI rendering.

    SLrules is correct that Silverlight always renders the font in real-time. Using TextHintingMode=”Animated” helps in that Silverlight will not always attempt to get the best font render at that size but use an overall “design” size. It also will not attempt to baseline-snap the text.

    Hope this helps,
    -mark
    Silverlight Program Manager
    Microsoft

Leave a Reply