Код AS3:
package by.ppchu.tests
{
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Rectangle;
[SWF(width="200", height="200")]
public class Test4 extends Sprite
{
public static const CIRCLE_RADIUS:Number = 50;
public static const SQUARE_SIZE:Number = 200;
private var movie:Sprite = new Sprite();
private var circle:Sprite = new Sprite();
private var square:Sprite = new Sprite();
public function Test4()
{
addChild(movie);
square.graphics.beginFill(0xFF0000, 1);
square.graphics.drawRect(0, 0, SQUARE_SIZE, SQUARE_SIZE);
movie.addChild(square);
circle.graphics.beginFill(0, 1);
circle.graphics.drawCircle(SQUARE_SIZE / 2, SQUARE_SIZE / 2, CIRCLE_RADIUS);
movie.addChild(circle);
square.mask = circle;
trace("pixel bounds native : " + movie.transform.pixelBounds);
trace("pixel bounds :" + getPixelBounds(movie));
}
public static function getPixelBounds(sprite:Sprite):Rectangle
{
var matrix:Matrix = new Matrix();
var rect:Rectangle = sprite.getBounds(sprite);
var bmd:BitmapData = new BitmapData(rect.width, rect.height, true, 0x0);
var result:Rectangle;
rect.x = Math.floor(rect.x);
rect.y = Math.floor(rect.y);
rect.width = Math.ceil(rect.width);
rect.height = Math.ceil(rect.height);
matrix.tx = -rect.x;
matrix.ty = -rect.y;
bmd.draw(sprite, matrix);
var w:int = rect.width;
var h:int = rect.height;
result = bmd.getColorBoundsRect(0xFF000000, 0x00000000, false);
return result;
}
}
}
Код:
pixel bounds native : (x=0, y=0, w=200, h=200)
pixel bounds :(x=50, y=50, w=100, h=100)
В первый день появления темы набросал, да отправить забыл.
Решил исправиться. Правда, товарищ
Wolsh уже указал на этот путь решения.