alicia
alicia

Reputation: 597

Draw String in Canvas

I'm trying to draw a String inside a canvas. The text and the position of the String changes pressing differents bottoms. For doing so, I create TextFields which I added to a sprite which I added to a Canvas:

canvas.rawChildren.addChild(spriteNombres);

The first time everything works fine but when I press the bottoms,it does not refresh and appear the old textfields and the new ones.I cant remove the old ones, I try with removeAllChildren and also trying to delete one by one with removeChildrenAt. I do not know if I'm doing something wrong or maybe this is not the best way.

Any suggestions???

Thanks in advance.

I also try creating bitmapdata and drawing in the sprite inside a rectangle.

var channelName: TextField = new TextField();
channelName.text = channelNames[displaySequence[channel]];
if (channelName.text != null) {

channelName.antiAliasType = AntiAliasType.NORMAL;
var theWidth,theHeight:int;
theWidth=0;
theHeight=20;

var bitmapdata:BitmapData = new BitmapData(theWidth, theHeight, true, 0x000000);
bitmapdata.draw(channelName);               
spriteNombres.graphics.beginBitmapFill(bitmapdata);
spriteNombres.graphics.drawRect(offsetX, offsetY, theWidth, theHeight);
    spriteNombres.graphics.endFill();                            

}

Upvotes: 0

Views: 773

Answers (1)

Theo.T
Theo.T

Reputation: 9267

Not so sure but there are two things that maybe should be double-checked in your script.

First, are you using graphics.clear() before redrawing ? it can get messy otherwise. Second, I think you need to pass a matrix to the graphics.beginBitmapFill method which should have the the tx,ty translated same as offsetX, offsetY (to be tested, not 100% about it)

Upvotes: 1

Related Questions