CSS class name
samiwistler

Hello again,

I have a 3d css class :

.appName {  text-shadow: 0 1px 0 #ccc,               0 2px 0 #c9c9c9,               0 3px 0 #bbb,               0 4px 0 #b9b9b9,               0 5px 0 #aaa,               0 6px 1px rgba(0,0,0,.1),               0 0 5px rgba(0,0,0,.1),               0 1px 3px rgba(0,0,0,.3),               0 3px 5px rgba(0,0,0,.2),               0 5px 10px rgba(0,0,0,.25),               0 10px 10px rgba(0,0,0,.2),               0 20px 20px rgba(0,0,0,.15);}

How can i attach it to a textSprite?

 

Thanks

All 2 Comments
Gio

Hi

 

That's a lot of shadows! :)

 

A text sprite is not a DOM element, it's just a "virtual" element that is drawn into a canvas. As such, you cannot really attach any css to it. You can attach any css that you like to the canvas element that the text sprite is drawn into, but that wouldn't give you the effect that you're after with your multiple shadows.

 

Having said that, there is a trick that you can use to achieve the effect that you want. TextSprites support shadows via the method TextSprite.setShadow(color, blur, offsetX, offsetY). It has to be, however, just a single shadow value (it's really a limitation of the HTML5 canvas, so not much we can do about that).

 

But... you can draw the text sprite multiple times, to have multiple shadows!

 

Note that this is pretty performance intensive, and I definitely wouldn't recommend drawing that text with so many shadow values every frame. I would suggest that you draw your text sprite (multiple times with different shadow values) to an image, and then use that image to create a normal Sprite. This is much, much faster, and also much faster than using a CSS class with a DOM element. Also, multiple shadow values in CSS are not supported across all the different browsers, whereas this method will work everywhere.

 

This code should do it:

var textSprite = new TextSprite('Some Text', '32px Arial', '#ff8888');textSprite.scaleBounds(2, 2); // make its bounding box bigger so all the shadows will fit into the imagetextSprite.setShadow('rgba(0,0,0,0.15)', 20, 0, 20);textSprite.drawToImage('my cool text'); // draw it to a new image called 'my cool text'textSprite.setShadow('rgba(0,0,0,0.2)', 20, 0, 10);textSprite.drawToImage('my cool text'); // draw on top of the existing imagetextSprite.setShadow('rgba(0,0,0,0.25)', 10, 0, 5);textSprite.drawToImage('my cool text');// repeat for all the different shadow values that you want...// then create a Sprite with our 'my cool text' imagevar sprite = new Sprite('my cool text');

Also note that the order of the shadow values should be the opposite of what you have in CSS to replicate the same effect (i.e. start from the bottom of your list of values).

samiwistler

Thanks for the quick reply.

This is exactly what i was looking for.

 

And on a personal remark, i found the Wade engine easy to use and a fast learning curve, what makes it possible for infrastructure developer to know about the UI ..

Post a reply
Add Attachment
Submit Reply
Login to Reply