Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

as3 - render text straight to Sprite.graphics?

Because I'm a terrible, bad person who likes to do things differently for no reason, I'd love to be able to do something like mySprite.graphics.drawText(...).

As I understand things, the only way to get text currently is to create a TextField and add it as a child of mySprite. In my particular situation I'd rather not do that.

Any advice appreciated!

ooo

like image 222
orion elenzil Avatar asked Dec 07 '25 10:12

orion elenzil


2 Answers

Wrong bzzzzzzzt create a new BitmapData object, create a bitmap, adding the bitmapData to it and then adding that bitmap as a child to your sprite. Example:

var myTextImage:BitmapData = new BitmapData(textField.width, textField.height, true, 0x000000ff);

myTextImage.draw(textField);

mySprite.addChild(new Bitmap(myTextImage));

stage.addChild(mySprite);

I just made that code up so you'll have to adapt it but the principle should be more than clear enough to adapt it to your project.

Create a new BitmapData object : bitmapdata = new BitmapData(txt.width, txt.height, true, 0x000000ff);

Draw your textfield on it : bitmapdata.draw(txt);

And then use graphics class and it works !

sprite.graphics.beginBitmapFill(bitmapdata);
sprite.graphics.drawRect(0,0,txt.width,txt.height);
sprite.graphics.endFill();

C ya

like image 31
Wolfdahmonk Avatar answered Dec 10 '25 10:12

Wolfdahmonk