Ser*_*vet 3 bitmap actionscript-3 bitmapdata
我试图在屏幕上绘制一些东西,然后将其复制到舞台上的位图上.
我以前做过这个,用程序绘制的形状像圆圈但是当我使用库项目时,大多数源像素被切断.
这是我的代码 - 在另一个函数中,位图对象被添加到舞台上,我可以看到copyPixels工作,但正如我所说的只复制了一些像素.我试过玩矩形但到目前为止没有运气.
var s:StarAsset = new StarAsset();
s.x = e.stageX;
s.y = e.stageY;
s.scaleX = e.pressure * 10;
s.scaleY = e.pressure * 10;
s.rotation = Math.random() * 360;
var bms:BitmapData = new BitmapData(s.width + 6, s.height + 6, true, 0x00000000);
bms.draw(s);
var srect:Rectangle = new Rectangle();
srect.width = s.width + 6;
srect.height = s.height + 6;
var destpoint:Point = new Point(s.x, s.y);
bmcontainer.copyPixels(bms, srect, destpoint, null, null, true);
Run Code Online (Sandbox Code Playgroud)
使用星级资产:

假设你正在舞台上的画布位图:
var canvas:BitmapData = new BitmapData(600, 600, true, 0x0);
var bitmap:Bitmap = new Bitmap(canvas, PixelSnapping.AUTO, true);
addChild(bitmap);
Run Code Online (Sandbox Code Playgroud)
此实现将实例化您的StarAsset,绘制它BitmapData,然后随机转换绘制到画布的每个副本的缩放,位置和旋转:
makeStars();
function makeStars():void
{
// get the star asset
var s:StarAsset = new StarAsset();
// copy star asset to bitmap data
var bd:BitmapData = new BitmapData(s.width, s.height, true, 0x0);
bd.draw(s);
// draw 100 variants on BitmapData
for(var i:uint = 0; i < 100; i++)
{
var positionX:Number = Math.random() * 600;
var positionY:Number = Math.random() * 600;
var scale:Number = Math.random();
var angle:Number = Math.random() * 360;
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
matrix.rotate(angle * Math.PI / 180);
matrix.translate(positionX, positionY);
canvas.draw(bd, matrix, null, null, null, true);
}
}
Run Code Online (Sandbox Code Playgroud)
哪个产生:

或者这里绘制了1000颗星:

或者最后绘制了10,000颗星:
