Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Drawing small sprite to large bitmap

Explorer ,
Jan 14, 2014 Jan 14, 2014

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

TOPICS
ActionScript
715
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 14, 2014 Jan 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);

Translate
Community Expert ,
Jan 14, 2014 Jan 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 14, 2014 Jan 14, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2014 Jan 14, 2014
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2014 Jan 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines