zoukankan      html  css  js  c++  java
  • ActionScript图形之遮罩

    ActionScript图形之遮罩

    2011-03-12 21:41:53| 分类: flex | 标签:actionscript图形之遮罩 |字号 订阅

    xxx.mask=yyy 这样xxx中只有与yyy交叉的部分才可见,这就是遮罩。
    例子:
    比较取消注释后的效果,和当前的效果
    package
    {
    import flash.display.Shape;
    import flash.display.Sprite;
    public class TestMask extends Sprite
    {
    private var circle:Shape;
    private var rec:Shape;
    public function TestMask()
    {
    super();
    circle = new Shape();
    circle.graphics.beginFill(0xfff000);
    circle.graphics.drawCircle(250,250,250);
    circle.graphics.endFill();
    rec = new Shape();
    rec.graphics.beginFill(0xff0000);
    rec.graphics.drawRect(0,0,500,20);
    rec.graphics.endFill();
    //circle.mask = rec;
    this.addChild(rec);
    this.addChild(circle);
    }
    }
    }

    动态遮罩
    package
    {
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class TestMask extends Sprite
    {
    private var circle:Sprite;
    private var rec:Sprite;
    public function TestMask()
    {
    super();
    circle = new Sprite();
    rec = new Sprite();
    rec.graphics.beginFill(0xfff000);
    rec.graphics.drawRect(50, 50, 200,200);
    rec.graphics.endFill();

    this.addChild(circle);
    this.addChild(rec);
    rec.addEventListener(MouseEvent.MOUSE_MOVE, createRec);
    rec.addEventListener(MouseEvent.MOUSE_OUT, dropRec);
    }
    private function createRec(evt:MouseEvent):void
    {
    circle.graphics.clear();
    circle.graphics.beginFill(0xff000);
    circle.graphics.drawCircle(evt.localX,evt.localY,100);
    circle.graphics.endFill();
    rec.mask = circle;

    }
    private function dropRec(evt:MouseEvent):void
    {
    rec.mask = null;
    }
    }
    }

    百叶窗
    package
    {
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    public class TestMask2 extends Sprite
    {
    private var circle:Sprite;
    private var rec:Sprite;
    public function TestMask2()
    {
    super();
    rec = new Sprite();
    rec.graphics.beginFill(0xfff000);
    rec.graphics.drawRect(50,50,500,20);
    rec.graphics.drawRect(50,80,500,20);
    rec.graphics.drawRect(50,110,500,20);
    rec.graphics.drawRect(50,140,500,20);
    rec.graphics.drawRect(50,170,500,20);
    rec.graphics.endFill();
    circle = new Sprite();
    circle.graphics.beginFill(0xff0000);
    circle.graphics.drawCircle(450/2, 110, 100);
    circle.graphics.endFill();
    rec.mask = circle;
    this.addChild(circle);
    this.addChild(rec);
    }
    }
    }
  • 相关阅读:
    for循环
    3.9 作业
    while循环
    深浅拷贝
    条件与判断
    可变与不可变
    与用户交互与运算符
    垃圾回收机制
    【AC自动机】文本生成器
    【AC自动机】最短母串
  • 原文地址:https://www.cnblogs.com/xiayong123/p/3717072.html
Copyright © 2011-2022 走看看