zoukankan      html  css  js  c++  java
  • 白鹭引擎

    class Main extends egret.DisplayObjectContainer {
    
        /**
         * Main 类构造器, 初始化的时候自动执行, ( 子类的构造函数必须调用父类的构造函数 super )
         * constructor 是类的构造函数, 类在实例化的时候调用
         * egret.Event.ADDED_TO_STAGE, 在将显示对象添加到舞台显示列表时调度
         */
        public constructor() {
            super();
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        }
    
        /**
         * 添加到显示列表, 容器.addChild(显示对象)
         * 移除出显示列表, 容器.removeChild(显示对象)
         * 需要注意的几个点如下:
         * 1, 显示对象在运行时会被高频率的添加到显示列表或从中删除,但显示对象独立于显示列表
         * 2, 显示对象的坐标系是相对坐标系,而非绝对坐标系, 相对于父容器
         * 3, 同一个显示对象无论被代码加入显示列表多少次,在屏幕上只绘制一次
         * 4, 显示对象必须有父级容器, 才能被删除, 如果删除的显示对象不再容器中, 会抛异常
         * 5, Uncaught Error: [Fatal]child未被addChild到该parent:
         * 6, 在删除显示对象时, 建议判断器是否存在腹肌 => 显示对象.parent
         */
        private onAddToStage(event: egret.Event) {
    
            // 绘制一个可以显示和取消的正方形
            var circle: egret.Shape = new egret.Shape();
            circle.graphics.beginFill(0xff0000);
            circle.graphics.drawRect(50,50,100,100);
            circle.graphics.endFill();
            this.addChild(circle);
    
            // 绘制一个可以点击的按钮
            var button: egret.Shape = new egret.Shape();
            button.graphics.beginFill(0xff0000);
            button.graphics.drawRect(500,800,100,100);
            button.graphics.endFill();
            this.addChild(button);
    
            // 点击屏幕时, 显示和消失
            var isShow: boolean = true, myThis: Main = this;
            button.touchEnabled = true;
            button.addEventListener(egret.TouchEvent.TOUCH_TAP, onAddRemove, this);
            function onAddRemove(ev: egret.TouchEvent) {
                if (isShow) {
                    myThis.removeChild(circle);
                } else {
                    myThis.addChild(circle);
                }
                isShow = !isShow;
            }
    
        }
    }
  • 相关阅读:
    Python for Infomatics 第14章 数据库和SQL应用四(译)
    展望2017
    bing的简单英文字典工具
    自我安慰
    Python for Infomatics 第14章 数据库和SQL应用三(译)
    Python for Infomatics 第14章 数据库和SQL应用二(译)
    Python for Infomatics 第14章 数据库和SQL应用一(译)
    希望父亲早日恢复
    Python for Infomatics 第13章 网页服务四(译)
    Python for Infomatics 第13章 网页服务三(译)
  • 原文地址:https://www.cnblogs.com/lovling/p/8399123.html
Copyright © 2011-2022 走看看