【发布时间】:2011-08-11 14:55:32
【问题描述】:
对于一个班级项目,我正在制作“Pissed Off Pigs”(我想你明白了,猪会报仇,别担心,我不会发布它!)我想创建用位图填充的圆圈(圆圈是因为碰撞数学更容易)。这是它们现在的样子。
当然,白色是问题所在。下面是我的“猪”课。有任何想法吗?我尝试过 gif、png、8 位 png 等,但似乎没有什么区别。图像本身是 20px 正方形,圆的半径是 10px(所以直径是 20px)。这是我正在使用的图像:
而且我知道我可能应该在类之外加载图像,并在创建新猪时传递 BitmapData,这样我就不必每次创建新猪时都加载图像,但现在它可以工作了! (有点)。
矩阵是翻译问题吗?
哦,我检查了 bmpImage.transparent 并且它返回 true(即使我没有在构造函数中指定 true)。
` 包裹 { 导入 flash.display.; 导入 flash.net。; 导入 flash.events.; 导入 flash.geom。; 导入 flash.display.BitmapDataChannel;
public class pig extends Sprite {
public var radius:uint;
public var velocity:Vec2;
public var tt:Sprite;
public var pigLoader:Loader;
public var bmpImage:BitmapData;
public var framesAlive:uint;
public function pig(xx:uint, yy:uint, radius:uint, vx:Number, vy:Number, sprite:String){
this.x = xx;
this.y = yy;
this.radius = radius;
this.velocity = new Vec2(vx, vy);
pigLoader = new Loader();
pigLoader.load(new URLRequest(sprite));
pigLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, picLoaded);
}
private function picLoaded(event:Event):void {
bmpImage = new BitmapData(pigLoader.width, pigLoader.height, true);
bmpImage.draw(pigLoader);
tt = new Sprite();
var matrix:Matrix;
matrix = new Matrix();
matrix.translate( -10, -10);
tt.graphics.beginBitmapFill(bmpImage, matrix, false, false);
tt.graphics.drawCircle(0, 0, this.radius)
tt.graphics.endFill();
this.addChild(tt);
}
}
}
`
【问题讨论】:
标签: flash actionscript-3 bitmap transparency bitmapdata