Skip to main content
Known Participant
January 14, 2014
Answered

Drawing small sprite to large bitmap

  • January 14, 2014
  • 2 replies
  • 772 views

Hi

I have a spirte circSprite that I draw on a large bitmap drawingBitmap.

drawingBitmapData = new BitmapData(800, 600, true,0);

drawingBitmap = new Bitmap(drawingBitmapData);

stage.addChild(drawingBitmap);

var circSprite:Sprite = new Sprite();

circSprite.graphics.beginFill(0xFF0000,0);

circSprite.graphics.drawRect(0,0,160,160);

circSprite.graphics.endFill();

circSprite.graphics.beginFill(0xFF00FF,1);

circSprite.graphics.drawCircle(40,40,40);

circSprite.graphics.endFill();

var mat:Matrix = new Matrix();

drawingBitmapData.drawWithQuality(circSprite,mat,null,null, null,true,StageQuality.MEDIUM);

I would like to move the circSpirte to a different position ( 100,100 ) - how can I do that?

Thanks!

Rolf

This topic has been closed for replies.
Correct answer kglad

update the matrix:

var rect:Rectangle=new Rectangle(0,0,800,600);

var bgColor:uint = 0xffffff;  //<- use your stage color

mat.tx+=3;

drawingBitmapData.fillRect(rect,bgColor);  //<- to make it look like the previously drawn object(s) were erased

drawingBitmapData.drawWithQuality(circSprite,mat,null,null, null,true,StageQuality.MEDIUM);

2 replies

robdillon
Participating Frequently
January 14, 2014

The drawCircle function takes 3 arguments, the x position, the y position and the radius, so if you want the circle at 100, 100, then just change that line to:

circSprite.graphics.drawCircle(100,100,40);

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 14, 2014

update the matrix:

var rect:Rectangle=new Rectangle(0,0,800,600);

var bgColor:uint = 0xffffff;  //<- use your stage color

mat.tx+=3;

drawingBitmapData.fillRect(rect,bgColor);  //<- to make it look like the previously drawn object(s) were erased

drawingBitmapData.drawWithQuality(circSprite,mat,null,null, null,true,StageQuality.MEDIUM);

Known Participant
January 15, 2014

Hi kglad

Thanks, that worked! Had to remove this part of the code because otherwice the circle was cut off. It kinda working as a mask?

circSprite.graphics.beginFill(0xFF0000,0);

circSprite.graphics.drawRect(0,0,160,160);

circSprite.graphics.endFill();

Anyway, thanks a lot

kglad
Community Expert
Community Expert
January 15, 2014

you're welcome.

p.s. rob's suggestion would work too but is not the approach you should take if you wanted to "animate" your circle.  the code i suggested is the typical blitting code used to make it appear a blitted object is animated.