ActionScript 3.0 drawRect works weird

I have a BitmapData object named myBitmapData. It was downloaded PNG in size 104x104. This PNG is a red circle on a transparent background. There is also a Sprite object named myBackground. I want to make this red circle in myBackground.

myBackground.graphics.beginBitmapFill(myBitmapData); myBackground.graphics.drawRect(0, 0, myBitmapData.width, myBitmapData.height); myBackground.graphics.endFill(); addChild(myBackground); 

Everything is good. I see a red circle at the top left of myBackground.

But when I change the third line to

 myBackground.graphics.drawRect(0, 52, myBitmapData.width, myBitmapData.height); 

and we expect that my circle will be translated 52 pixels down, I really get something strange (for me :)): there are two red semicircles (they form an hourglass).

So the question is how to make myBitmapData into a random position myBackground?

PS In the case of

 myBackground.graphics.drawRect(0, 104, myBitmapData.width, myBitmapData.height); 

rounded again :)

+4
source share
1 answer

This is called by the beginBitmapFill parameter default repeat = true . Here is an example in the docs. Disabling repetition will not work, but you will only get half a circle.

There are several ways to fix this:

  • Use Matrix with translation (offset) as an argument in beginBitmapFill .
  • Draw a rectangle in 0,0 on another Sprite and move this sprite to where you want it in the background.
  • Do not draw directly on the background, but on another bitmap using copyPixels . Then fill the background with a bitmap.
+4
source

All Articles