Pyv*_*yva 3 flash paint bitmap actionscript-3 bitmapdata
我正在制作一个模拟泛行业的游戏,其中一个过程就是绘画.
我想要做的是让玩家画平底锅,但我不希望它很容易使用FILL,我希望玩家用刷子刷平底锅,然后游戏检测所有区域是否都被涂上了让球员前进.
对于绘画我打算使用该库:http://www.nocircleno.com/graffiti/
但我不知道如何检测所有区域是否被绘制.有人能告诉我某种方式吗?
其中一种方法是 - 你制作一个屏蔽BitmapData,它具有透明度,并且在你需要你的玩家画画时是不透明的.(根据需要对其进行着色,但要确保颜色完全不透明).然后收集histogram()然后查询第255个值的alpha矢量,这将是填充零百分比的初始值.它们的范围为0-255,因此您不能使用100或任何其他固定值.然后,当玩家正在绘画时,您将画笔绘制在blendMode参数设置为的BitmapData上BlendMode.ERASE,这将净化您的BitmapData以获得绘制画笔的透明度.在播放器以任何方式完成绘制后(例如,绘画用完),您histogram()在BitmapData上运行另一个,并查询Alpha通道向量的第255个值.0表示位图是完全透明的(或者至少只有少量像素保持不透明),因此您可以将零计为100%填充,对于任何更大的使用比例.
var bd:BitmapData=new BitmapData(w,h,true,0x0); // fully transparent initial bitmap
bd.draw(yourPaintBase); // a shape that designates area to be painted. Must be fully opaque
var bm:Bitmap=new Bitmap(bd);
// position it as needed, so the area which should be painted is aligned to wherever you need
addChild(bm);
addEventListener(Event.ENTER_FRAME,doPaint);
var baseValue:int=bd.histogram()[3][255]; // Vector #3 contains alpha, #255 contains
// percentage of those pixels that have alpha of 255 = fully opaque
function doPaint(e:Event):void {
if (!areWePainting) return;
var sh:Shape=getBrush(); // shuold return an existing Shape object reference for performance
sh.x=e.localX;
sh.y=e.localY; // we are drawing where the mouse is
bd.draw(sh,null,null,BlendMode.ERASE);
decreasePaint(); // we have used some paint
if (noMorePaint()) {
e.target.removeEventListener(Event.ENTER_FRAME,doPaint);
var endValue:int=Math.floor(100*(1-bd.histogram()[3][255]/baseValue));
// aligning to percentage. This is the value you seek
reportFilledPercentage(endValue);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1830 次 |
| 最近记录: |