gpt4 book ai didi

actionscript-3 - AS3 : How do I clear graphics in a specific pixel/area

转载 作者:行者123 更新时间:2023-12-04 06:38:22 25 4
gpt4 key购买 nike

我知道你用 graphics.clear要清除所有图形但从舞台上清除图形,我想清除特定像素中或 x-y 值之间的图形,我该怎么做?

最佳答案

没有办法用图形来做到这一点。我刚试过,绘制透明形状不会产生洞,唉。

您应该将您拥有的图形转换为 Bitmap 实例并使用像素:

package
{
import flash.geom.Matrix;
import flash.geom.Rectangle;

import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;

public class Holey extends Sprite
{
public function Holey()
{
super();

// Lets create some example graphics.
graphics.beginFill(0x990000);
graphics.drawCircle(200, 200, 100);
graphics.endFill();

// Convert into raster and make 1 pixel transparent.
var aBit:Bitmap = rasterize(this);
aBit.bitmapData.setPixel32(50, 50, 0x00000000);

graphics.clear();
addChild(aBit);
}

private function rasterize(source:DisplayObject):Bitmap
{
// Obtain bounds of the graphics.
var aBounds:Rectangle = source.getBounds(source);

// Create raster of appropriate size.
var aRaster:BitmapData = new BitmapData(aBounds.width, aBounds.height, true, 0x00000000);

// Make an offset to capture all the graphics.
var aMatrix:Matrix = new Matrix;
aMatrix.translate(-aBounds.left, -aBounds.top);

aRaster.draw(source, aMatrix);
return new Bitmap(aRaster);
}
}
}

关于actionscript-3 - AS3 : How do I clear graphics in a specific pixel/area,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42622235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com