我想画的东西在屏幕上,然后复制到一个位图是在舞台上。
我也这样做过,有程序上绘制的形状就像一个圆,但是当我使用的库项目的大部分源的像素会被裁切。
这是我的code - 在另一个函数的位图对象添加到舞台上,我可以看到,copyPixels工作,但正如我刚才所说的副本只有部分像素。我曾尝试与矩形,但至今没有运气玩。
变种S:StarAsset =新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 =新的BitmapData(s.width + 6,s.height + 6,真实,00000000);
bms.draw(多个);
VAR srect:矩形=新的Rectangle();
srect.width = s.width + 6;
srect.height = s.height + 6;
VAR destpoint:点=新的点(s.x,s.y);
bmcontainer.copyPixels(BMS,srect,destpoint,NULL,NULL,TRUE);
解决方案
使用星型资产:
和假设你是位块传输到画布上的位图在舞台上:
VAR帆布:的BitmapData =新的BitmapData(600,600,真正的,为0x0);
VAR位:位图=新位图(帆布,PixelSnapping.AUTO,真正的);
的addChild(位);
该实现将实例化 StarAsset
,画为的BitmapData ,然后随机变换的规模,位置和每份转画到画布上:
makeStars();
功能makeStars():无效
{
//获取星资产
变种S:StarAsset =新StarAsset();
//拷贝星资产为位图数据
变种BD:的BitmapData =新的BitmapData(s.width,s.height,真实,为0x0);
bd.draw(多个);
//借鉴的BitmapData 100变种
对于(VAR我:UINT = 0; I< 100;我++)
{
VAR位X:数=的Math.random()* 600;
VAR positionY:数=的Math.random()* 600;
VAR规模:数=的Math.random();
VAR角度:数=的Math.random()* 360;
VAR矩阵:矩阵=新的Matrix();
matrix.scale(秤,秤);
matrix.rotate(角* Math.PI / 180);
matrix.translate(位X,positionY);
canvas.draw(BD,矩阵,NULL,NULL,NULL,TRUE);
}
}
主要生产:
在这里还是1000恒星绘制:
终于还是万星被吸引:
I am trying to draw something on the screen and then, copy that onto a bitmap which is on stage.
I have done this before, with a procedurally drawn shape like a circle but when I use a library item most of the source pixels get cut off.
here's my code - in another function the bitmap object is added to the stage and I can see that copyPixels work but as I have said copies only some of the pixels. I have tried playing with the Rectangle but no luck so far.
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);
解决方案
Using a star asset:
And assuming your are blitting to a canvas bitmap on the stage:
var canvas:BitmapData = new BitmapData(600, 600, true, 0x0);
var bitmap:Bitmap = new Bitmap(canvas, PixelSnapping.AUTO, true);
addChild(bitmap);
This implementation would instantiate your StarAsset
, draw it to BitmapData
, and then randomly transform scale, position, and rotation per copy drawn to the canvas:
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);
}
}
Which produces:
Or here 1,000 stars are drawn:
Or finally 10,000 stars are drawn:
下一篇:嵌入的声音切断早声音