开发者

How to draw an Bitmap in Graphics-Object at any position?

开发者 https://www.devze.com 2023-02-20 15:17 出处:网络
Is it possible to draw a Bitmap to a Graphics-Object like this.graphics.beginBitmapFill(bitmapData, matrix, false);

Is it possible to draw a Bitmap to a Graphics-Object like

this.graphics.beginBitmapFill(bitmapData, matrix, false);
this.graphics.drawRect(0, 0, w, h);
this.graphics.endFill();

with an offset? A simple moveTo(x, y) call before beginBitmapFill does not work :/ Neither does changing the x and y value of drawRect... (That just开发者_C百科 seems to have the same effect as an translation with the matrix...) Additionally I don't want do draw that thing in a separate Graphics-Object and add that one into the other...

Any clue?


A bit late answer here, but since I found this question when googling on the subject, I figured I'd add an answer anyway.

You can use a combination of matrix translation and position for the drawRect call to draw a bitmap at any position in the graphics object:

var positionX:int = 100;
var positionY:int = 200;
var matrix:Matrix = new Matrix();

matrix.tx = positionX;
matrix.ty = positionY;

graphics.beginBitmapFill(bitmapData, matrix);
graphics.drawRect(positionX, positionY, bitmapData.width, bitmapData.height);
graphics.endFill();

To be honest, I have never really fully understood what the matrix is ;) and don't have any intuitive feeling for how to use it, so there may very well be other, and perhaps better, ways to do it, but the above worked for me.


you can use the BitmapData (of your bitmap) draw() or copyPixels() methods.

see the docs:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#draw%28%29

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#copyPixels%28%29

0

精彩评论

暂无评论...
验证码 换一张
取 消