package {
import laya.display.Sprite;
import laya.display.Stage;
import laya.utils.HitArea;
/**
* ...
* @author yung
*/
public class LayaAirDemo {
private var red:Sprite;
private var box:Sprite;
public function LayaAirDemo() {
Laya.init(1200, 800);
Laya.stage.bgColor = "#efefef";
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
//绘制一个蓝色方块,不被抠图
var blue:Sprite = new Sprite();
blue.graphics.drawRect(0, 0, 500, 500, "#004080");
blue.pos(150, 150);
blue.size(500, 500);
blue.on("click", this, onClick);
Laya.stage.addChild(blue);
//增加一个容器
box = new Sprite();
//设置容器为画布缓存
box.cacheAs = "bitmap";
box.pos(200, 200);
Laya.stage.addChild(box);
//绘制红色方块
var red:Sprite = new Sprite();
red.graphics.drawRect(0, 0, 500, 500, "#ff0000");
box.addChild(red);
//绘制一个圆形区域,利用叠加模式,抠除上面红色区域
var circle:Sprite = new Sprite();
circle.graphics.drawCircle(0, 0, 50, "#ffff00");
circle.pos(50, 50);
//设置叠加模式
circle.blendMode = "destination-out";
box.addChild(circle);
var area:HitArea = new HitArea();
area.hit.drawRect(0, 0, 500, 500, "#ff0000");
area.unHit.drawCircle(250, 250, 50, "#ff0000");
box.hitArea = area;
box.mouseEnabled = true;
box.on("click", this, onBoxClick);
//绘制黑色区域,不被抠图
var black:Sprite = new Sprite();
black.graphics.drawRect(0, 0, 200, 200, "#000000");
black.pos(250, 250);
Laya.stage.addChild(black);
}
private function onBoxClick():void {
trace("box");
}
private function onClick():void {
trace("blue");
}
}
}