var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/**
 * @module annie
 */
var annie;
(function (annie) {
    /**
     * 显示对象抽象类,不能直接实例化。一切显示对象的基类,包含了显示对象需要的一切属性
     * DisplayObject 类本身不包含任何用于在屏幕上呈现内容的 API。
     * 因此,如果要创建 DisplayObject 类的自定义子类,您将需要扩展其中一个具有在屏幕
     * 上呈现内容的 API 的子类,如 Shape、Sprite、Bitmap、TextField 或 MovieClip 类。
     * @class annie.DisplayObject
     * @since 1.0.0
     * @extends annie.EventDispatcher
     */
    var DisplayObject = (function (_super) {
        __extends(DisplayObject, _super);
        // events:
        /**
         * annie.DisplayObject显示对象加入到舞台事件
         * @event ADD_TO_STAGE
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject显示对象从舞台移出事件
         * @event REMOVE_TO_STAGE
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject显示对象 循环帧事件
         * @event ENTER_FRAME
         * @since 1.0.0
         */
        //MouseEvent
        /**
         * annie.DisplayObject鼠标或者手指按下事件
         * @event MOUSE_DOWN
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject鼠标或者手指抬起事件
         * @event MOUSE_UP
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject鼠标或者手指单击
         * @event CLICK
         * @type {string}
         */
        /**
         * annie.DisplayObject鼠标或者手指移动事件
         * @event MOUSE_MOVE
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject鼠标或者手指移入到显示对象上里触发的事件
         * @event MOUSE_OVER
         * @since 1.0.0
         */
        /**
         * annie.DisplayObject鼠标或者手指移出显示对象边界触发的事件
         * @event MOUSE_OUT
         * @since 1.0.0
         */
        //
        /**
         * @method DisplayObject
         * @since 1.0.0
         * @public
         */
        function DisplayObject() {
            _super.call(this);
            //更新信息对象是否更新矩阵 a2x_ua 是否更新Alpha a2x_uf 是否更新滤镜
            this.a2x_um = false;
            this.a2x_ua = false;
            this.a2x_uf = false;
            this._isCache = false;
            this._cacheAsBitmap = false;
            /**
             * 此显示对象所在的舞台对象,如果此对象没有被添加到显示对象列表中,此对象为空。
             * @property stage
             * @public
             * @since 1.0.0
             * @type {Stage}
             * @default null;
             * @readonly
             * */
            this.stage = null;
            /**
             * 显示对象的父级
             * @property parent
             * @since 1.0.0
             * @public
             * @type {annie.Sprite}
             * @default null
             * @readonly
             */
            this.parent = null;
            //显示对象在显示列表上的最终表现出来的透明度,此透明度会继承父级的透明度依次相乘得到最终的值
            this._cAlpha = 1;
            //显示对象上对显示列表上的最终合成的矩阵,此矩阵会继承父级的显示属性依次相乘得到最终的值
            this._cMatrix = new annie.Matrix();
            /**
             * 是否可以接受点击事件,如果设置为false,此显示对象将无法接收到点击事件
             * @property mouseEnable
             * @type {boolean}
             * @public
             * @since 1.0.0
             * @default false
             */
            this.mouseEnable = true;
            /**
             * 每一个显示对象都可以给他命一个名字,这样我们在查找子级的时候就可以直接用this.getChildrndByName("name")获取到这个对象的引用
             * @property name
             * @since 1.0.0
             * @public
             * @type {string}
             * @default ""
             */
            this.name = "";
            this._x = 0;
            this._offsetX = 0;
            this._offsetY = 0;
            this._y = 0;
            this._scaleX = 1;
            this._scaleY = 1;
            this._rotation = 0;
            this._alpha = 1;
            this._skewX = 0;
            this._skewY = 0;
            this._anchorX = 0;
            this._anchorY = 0;
            this._visible = true;
            this._blendMode = 0;
            this._matrix = new annie.Matrix();
            this._mask = null;
            this._filters = [];
            //是否自己的父级发生的改变
            this._cp = true;
            this._isUseToMask = 0;
            this._hitArea = null;
            /**
             * <h4><font color="red">小游戏不支持 小程序不支持</font></h4>
             * 是否对图片对象使用像素碰撞检测透明度,默认关闭
             * @property hitTestWithPixel
             * @type {boolean}
             * @default false
             * @since 1.1.0
             */
            this.hitTestWithPixel = false;
            // 缓存起来的纹理对象。最后真正送到渲染器去渲染的对象
            this._texture = null;
            this._bounds = new annie.Rectangle();
            this._splitBoundsList = [];
            this._needCheckDrawBounds = false;
            /**
             * 当前对象包含的声音列表
             * @property soundList
             * @public
             * @since 2.0.0
             * @type {Array}
             * @default []
             */
            this.soundList = [];
            //每个Flash文件生成的对象都有一个自带的初始化信息
            this._a2x_res_obj = {};
            //这里为什么要用undefined呢,这样可以知道一个对象是否从未添加到舞台过
            this._isOnStage = undefined;
            this._changeTransformInfo = [false, false, false, false, false, false];
            this._instanceType = "annie.DisplayObject";
        }
        Object.defineProperty(DisplayObject.prototype, "isCache", {
            /**
             * 是否被缓存了
             * @property isCache
             * @since 3.2.0
             * @type {boolean}
             */
            get: function () {
                return this._isCache;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "cacheAsBitmap", {
            /**
             * 是否将这个对象缓存为位图了
             * @property cacheAsBitmap
             * @since 3.2.0
             * @return {boolean}
             */
            get: function () {
                return this._cacheAsBitmap;
            },
            set: function (value) {
                var s = this;
                if (value != s._cacheAsBitmap) {
                    s._cacheAsBitmap = value;
                    s._isCache = (s._cacheAsBitmap || s._filters.length > 0 || s._blendMode != 0);
                    s.a2x_uf = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "x", {
            /**
             * 显示对象位置x
             * @property x
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._x;
            },
            set: function (value) {
                var s = this;
                if (value != s._x) {
                    s._x = value;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[0] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "y", {
            /**
             * 显示对象位置y
             * @property y
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._y;
            },
            set: function (value) {
                var s = this;
                if (value != s._y) {
                    s._y = value;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[1] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "scaleX", {
            /**
             * 显示对象x方向的缩放值
             * @property scaleX
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 1
             */
            get: function () {
                return this._scaleX;
            },
            set: function (value) {
                var s = this;
                if (value != s._scaleX) {
                    s._scaleX = value;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[2] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "scaleY", {
            /**
             * 显示对象y方向的缩放值
             * @property scaleY
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 1
             */
            get: function () {
                return this._scaleY;
            },
            set: function (value) {
                var s = this;
                if (value != s._scaleY) {
                    s._scaleY = value;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[3] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "rotation", {
            /**
             * 显示对象旋转角度
             * @property rotation
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._rotation;
            },
            set: function (value) {
                var s = this;
                if (value != s._rotation || s._skewX != 0 || s._skewY != 0) {
                    s._rotation = value;
                    s._skewX = 0;
                    s._skewY = 0;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[4] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "alpha", {
            /**
             * 显示对象透明度
             * @property alpha
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 1
             */
            get: function () {
                return this._alpha;
            },
            set: function (value) {
                var s = this;
                if (value != s._alpha) {
                    s._alpha = value;
                    s.a2x_ua = true;
                }
                s._changeTransformInfo[5] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "skewX", {
            /**
             * 显示对象x方向的斜切值
             * @property skewX
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._skewX;
            },
            set: function (value) {
                var s = this;
                if (value != s._skewX || s._rotation != 0) {
                    s._skewX = value;
                    s._rotation = 0;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[4] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "skewY", {
            /**
             * 显示对象y方向的斜切值
             * @property skewY
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._skewY;
            },
            set: function (value) {
                var s = this;
                if (value != s._skewY || s._rotation != 0) {
                    s._skewY = value;
                    s._rotation = 0;
                    s.a2x_um = true;
                }
                s._changeTransformInfo[4] = true;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "anchorX", {
            /**
             * 显示对象上x方向的缩放或旋转点
             * @property anchorX
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._anchorX;
            },
            set: function (value) {
                var s = this;
                if (value != s._anchorX) {
                    s._anchorX = value;
                    s.a2x_um = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "anchorY", {
            /**
             * 显示对象上y方向的缩放或旋转点
             * @property anchorY
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._anchorY;
            },
            set: function (value) {
                var s = this;
                if (value != s._anchorY) {
                    s._anchorY = value;
                    s.a2x_um = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "visible", {
            /**
             * 显未对象是否可见
             * @property visible
             * @public
             * @since 1.0.0
             * @type {boolean}
             * @default 0
             */
            get: function () {
                return this._visible;
            },
            set: function (value) {
                var s = this;
                if (value != s._visible) {
                    s._cp = true;
                    s._visible = value;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "blendMode", {
            /**
             * 显示对象的混合模式
             * 支持的混合模式大概有23种,具体查看annie.BlendMode
             * @property blendMode
             * @public
             * @since 1.0.0
             * @type {number}
             * @default 0
             */
            get: function () {
                return this._blendMode;
            },
            set: function (value) {
                var s = this;
                if (value != s._blendMode) {
                    s._blendMode = value;
                    s._isCache = (s._cacheAsBitmap || s._filters.length > 0 || s._blendMode != 0);
                    s.a2x_uf = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "matrix", {
            /**
             * 显示对象的变形矩阵
             * @property matrix
             * @public
             * @since 1.0.0
             * @type {annie.Matrix}
             * @default null
             */
            get: function () {
                return this._matrix;
            },
            enumerable: true,
            configurable: true
        });
        ;
        Object.defineProperty(DisplayObject.prototype, "mask", {
            /**
             * 显示对象的遮罩, 是一个Shape显示对象或是一个只包含shape显示对象的MovieClip
             * @property mask
             * @public
             * @since 1.0.0
             * @type {annie.DisplayObject}
             * @default null
             */
            get: function () {
                return this._mask;
            },
            set: function (value) {
                var s = this;
                if (value != s._mask) {
                    if (value instanceof annie.DisplayObject) {
                        value._isUseToMask++;
                    }
                    else {
                        if (s._mask instanceof annie.DisplayObject) {
                            s._mask._isUseToMask--;
                        }
                    }
                    s._mask = value;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DisplayObject.prototype, "filters", {
            /**
             * <h4><font color="red">小游戏不支持 小程序不支持</font></h4>
             * 显示对象的滤镜数组
             * @property filters
             * @since 1.0.0
             * @public
             * @type {Array}
             * @default null
             */
            get: function () {
                return this._filters;
            },
            set: function (value) {
                var s = this;
                if (value instanceof Array) {
                    if (value.length != 0 || s._filters.length != 0) {
                        s._filters.length = 0;
                        for (var i = 0; i < value.length; i++) {
                            s.filters[i] = value[i];
                        }
                        s.a2x_uf = true;
                    }
                }
                else {
                    if (s._filters.length > 0) {
                        s._filters.length = 0;
                        s.a2x_uf = true;
                    }
                }
                s._isCache = (s._cacheAsBitmap || s._filters.length > 0 || s._blendMode != 0);
            },
            enumerable: true,
            configurable: true
        });
        /**
         *将全局坐标转换到本地坐标值
         * @method globalToLocal
         * @since 1.0.0
         * @public
         * @param {annie.Point} point
         * @return {annie.Point}
         */
        DisplayObject.prototype.globalToLocal = function (point, bp) {
            if (bp === void 0) { bp = null; }
            return this._cMatrix.invert().transformPoint(point.x, point.y, bp);
        };
        /**
         *将本地坐标转换到全局坐标值
         * @method localToGlobal
         * @public
         * @since 1.0.0
         * @param {annie.Point} point
         * @return {annie.Point}
         */
        DisplayObject.prototype.localToGlobal = function (point, bp) {
            if (bp === void 0) { bp = null; }
            return this._cMatrix.transformPoint(point.x, point.y, bp);
        };
        Object.defineProperty(DisplayObject.prototype, "hitArea", {
            get: function () {
                return this._hitArea;
            },
            /**
             * annie.Sprite显示容器的接受鼠标点击的区域。一但设置,容器里所有子级将不会触发任何鼠标相关的事件。
             * 相当于 mouseChildren=false,但在有大量子级显示对象的情况下,此方法的性能搞出mouseChildren几个数量级,建议使用。
             * @property hitArea
             * @param {annie.Rectangle} rect
             * @since 3.0.1
             */
            set: function (rect) {
                this._hitArea = rect;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * 点击碰撞测试,就是舞台上的一个point是否在显示对象内,在则返回该对象,不在则返回null
         * @method hitTestPoint
         * @public
         * @since 1.0.0
         * @param {annie.Point} hitPoint 要检测碰撞的点
         * @param {boolean} isGlobalPoint 是不是全局坐标的点,默认false是本地坐标
         * @return {annie.DisplayObject}
         */
        DisplayObject.prototype.hitTestPoint = function (hitPoint, isGlobalPoint) {
            if (isGlobalPoint === void 0) { isGlobalPoint = false; }
            var s = this;
            if (!s.visible || !s.mouseEnable)
                return null;
            var p;
            if (isGlobalPoint) {
                p = s.globalToLocal(hitPoint, DisplayObject._p1);
            }
            else {
                p = hitPoint;
            }
            //如果有设置鼠标活动区域,则优先使用活动区域
            if (s._hitArea) {
                if (s._hitArea.isPointIn(p)) {
                    return s;
                }
            }
            if (s._bounds.isPointIn(p)) {
                if (s.hitTestWithPixel) {
                    var texture = s._texture;
                    if (!texture || texture.width == 0 || texture.height == 0) {
                        return null;
                    }
                    var _canvas = DisplayObject._canvas;
                    var ctx = _canvas.getContext('2d');
                    _canvas.width = 1;
                    _canvas.height = 1;
                    ctx.clearRect(0, 0, 1, 1);
                    ctx.drawImage(texture, p.x - s._offsetX, p.y - s._offsetY, 1, 1, 0, 0, 1, 1);
                    if (ctx.getImageData(0, 0, 1, 1).data[3] > 0) {
                        return s;
                    }
                }
                else {
                    return s;
                }
            }
            return null;
        };
        DisplayObject.prototype.getBounds = function () {
            return this._bounds;
        };
        /**
         * 获取对象形变后外切矩形
         * 可以从这个方法中读取到此显示对象变形后x方向上的宽和y方向上的高
         * @method getDrawRect
         * @public
         * @since 1.0.0
         * @return {annie.Rectangle}
         */
        DisplayObject.prototype.getDrawRect = function (matrix, bounds) {
            if (matrix === void 0) { matrix = null; }
            if (bounds === void 0) { bounds = null; }
            var s = this;
            if (matrix == void 0) {
                matrix = s.matrix;
            }
            if (bounds == void 0) {
                bounds = s.getBounds();
            }
            var x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
            matrix.transformPoint(x, y, DisplayObject._p1);
            matrix.transformPoint(x + w, y, DisplayObject._p2);
            matrix.transformPoint(x + w, y + h, DisplayObject._p3);
            matrix.transformPoint(x, y + h, DisplayObject._p4);
            return annie.Rectangle.createFromPoints(DisplayObject._transformRect, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
        };
        DisplayObject.prototype._onUpdateMatrixAndAlpha = function () {
            var s = this, cm, pcm, ca, pca;
            var isHadParent = s.parent instanceof annie.Sprite;
            cm = s._cMatrix;
            ca = s._cAlpha;
            if (isHadParent) {
                pcm = s.parent._cMatrix;
                pca = s.parent._cAlpha;
            }
            if (s.a2x_um) {
                s._matrix.createBox(s._x, s._y, s._scaleX, s._scaleY, s._rotation, s._skewX, s._skewY, s._anchorX, s._anchorY);
            }
            if (s._cp) {
                s.a2x_um = s.a2x_ua = s.a2x_uf = true;
                s._cp = false;
            }
            else {
                if (isHadParent) {
                    var PUI = s.parent;
                    if (PUI.a2x_um) {
                        s.a2x_um = true;
                    }
                    if (PUI.a2x_ua) {
                        s.a2x_ua = true;
                    }
                }
            }
            if (s.a2x_um) {
                cm.setFrom(s._matrix);
                if (isHadParent) {
                    cm.prepend(pcm);
                }
            }
            if (s.a2x_ua) {
                ca = s._alpha;
                if (isHadParent) {
                    ca *= pca;
                }
                s._cAlpha = ca;
            }
        };
        Object.defineProperty(DisplayObject.prototype, "width", {
            /**
             * 获取或者设置显示对象在父级里的x方向的宽,不到必要不要用此属性获取高
             * 如果你要同时获取宽高,建议使用 getWH()方法获取宽和高
             * @property  width
             * @public
             * @since 1.0.3
             * @return {number}
             */
            get: function () {
                this._onUpdateMatrixAndAlpha();
                this.getDrawRect();
                return DisplayObject._transformRect.width;
            },
            set: function (value) {
                var s = this;
                s._onUpdateMatrixAndAlpha();
                s.getDrawRect();
                var w = DisplayObject._transformRect.width;
                if (w > 0) {
                    var sx = value / w;
                    s.scaleX *= sx;
                }
                else {
                    s.scaleX = 1;
                }
            },
            enumerable: true,
            configurable: true
        });
        /**
         * 获取宽高
         * @method getWH
         * @since 1.1.0
         * @return {{w: number; h: number}}
         */
        DisplayObject.prototype.getWH = function () {
            this._onUpdateMatrixAndAlpha();
            this.getDrawRect();
            return { w: DisplayObject._transformRect.width, h: DisplayObject._transformRect.height };
        };
        Object.defineProperty(DisplayObject.prototype, "height", {
            /**
             * 获取或者设置显示对象在父级里的y方向的高,不到必要不要用此属性获取高
             * 如果你要同时获取宽高,建议使用getWH()方法获取宽和高
             * @property  height
             * @public
             * @since 1.0.3
             * @return {number}
             */
            get: function () {
                this._onUpdateMatrixAndAlpha();
                this.getDrawRect();
                return DisplayObject._transformRect.height;
            },
            set: function (value) {
                var s = this;
                s._onUpdateMatrixAndAlpha();
                s.getDrawRect();
                var h = DisplayObject._transformRect.height;
                if (h > 0) {
                    var sy = value / h;
                    s.scaleY *= sy;
                }
                else {
                    s.scaleY = 1;
                }
            },
            enumerable: true,
            configurable: true
        });
        /**
         * 停止这个显示对象上的所有声音
         * @method stopAllSounds
         * @public
         * @since 2.0.0
         * @return {void}
         */
        DisplayObject.prototype.stopAllSounds = function () {
            var sounds = this.soundList;
            if (sounds instanceof Array) {
                for (var i = sounds.length - 1; i >= 0; i--) {
                    sounds[i].stop();
                }
            }
        };
        /**
         * 更新boundsList矩阵
         * @method _updateSplitBounds
         * @private
         */
        DisplayObject.prototype._updateSplitBounds = function () {
            var s = this;
            var sbl = [];
            var bounds = s.getBounds();
            if (bounds.width * bounds.height > 0) {
                var row = 1;
                var col = 1;
                var br = 0;
                var bc = 0;
                var newWidth = bounds.width;
                var newHeight = bounds.height;
                if (annie.isCutDraw) {
                    br = 1024;
                    bc = 1024;
                    newWidth = br + 2;
                    newHeight = bc + 2;
                    if (bounds.width > br) {
                        row = Math.ceil(bounds.width / br);
                    }
                    if (bounds.height > bc) {
                        col = Math.ceil(bounds.height / bc);
                    }
                }
                for (var i = 0; i < row; i++) {
                    for (var j = 0; j < col; j++) {
                        var newX = i * br;
                        var newY = j * bc;
                        if (i == row - 1) {
                            newWidth = bounds.width - newX;
                        }
                        if (j == col - 1) {
                            newHeight = bounds.height - newY;
                        }
                        sbl.push({
                            isDraw: true,
                            rect: new annie.Rectangle(newX + bounds.x, newY + bounds.y, newWidth, newHeight)
                        });
                    }
                }
            }
            s._splitBoundsList = sbl;
            s._needCheckDrawBounds = true;
        };
        DisplayObject.prototype._checkDrawBounds = function () {
            var s = this;
            //检查所有bounds矩阵是否在可视范围里
            var sbl = s._splitBoundsList;
            if (s.stage) {
                for (var i = 0; i < sbl.length; i++) {
                    sbl[i].isDraw = annie.Rectangle.testRectCross(s.getDrawRect(s._cMatrix, sbl[i].rect), s.stage.viewPort);
                }
            }
            s._needCheckDrawBounds = false;
        };
        /**
         * @method getSound
         * @param {number|string} id
         * @return {Array} 这个对象里所有叫这个名字的声音引用数组
         * @since 2.0.0
         */
        DisplayObject.prototype.getSound = function (id) {
            var sounds = this.soundList, newSounds = [];
            if (sounds instanceof Array) {
                if (typeof (id) == "string") {
                    for (var i = sounds.length - 1; i >= 0; i--) {
                        if (sounds[i].name == id) {
                            //这里是全部找出来
                            newSounds.push(sounds[i]);
                        }
                    }
                }
                else {
                    if (id >= 0 && id < sounds.length) {
                        newSounds.push(sounds[id]);
                    }
                }
            }
            return newSounds;
        };
        /**
         * 返回一个id,这个id你要留着作为删除他时使用。
         * 这个声音会根据这个显示对象添加到舞台时播放,移出舞台而关闭
         * @method addSound
         * @param {annie.Sound} sound
         * @return {void}
         * @since 2.0.0
         * @public
         */
        DisplayObject.prototype.addSound = function (sound) {
            var s = this;
            if (!(s.soundList instanceof Array)) {
                s.soundList = [];
            }
            s.soundList.push(sound);
        };
        /**
         * 删除一个已经添加进来的声音
         * @method removeSound
         * @public
         * @since 2.0.0
         * @param {number|string} id
         * @return {void}
         */
        DisplayObject.prototype.removeSound = function (id) {
            var sounds = this.soundList;
            if (sounds instanceof Array) {
                if (typeof (id) == "string") {
                    for (var i = sounds.length - 1; i >= 0; i--) {
                        //这里是全部找出来
                        if (sounds[i].name == id) {
                            sounds.splice(i, 1);
                        }
                    }
                }
                else {
                    if (id >= 0 && id < sounds.length) {
                        sounds.splice(id, 1);
                    }
                }
            }
        };
        DisplayObject.prototype.destroy = function () {
            var s = this;
            //清除相应的数据引用
            s.stopAllSounds();
            for (var i = 0; i < s.soundList.length; i++) {
                s.soundList[i].destroy();
            }
            s.soundList = null;
            s._a2x_res_obj = null;
            s.mask = null;
            s.filters = null;
            s.parent = null;
            s.stage = null;
            s._bounds = null;
            s._splitBoundsList = null;
            s._matrix = null;
            s._cMatrix = null;
            s._texture = null;
            _super.prototype.destroy.call(this);
        };
        DisplayObject.prototype._onRemoveEvent = function (isReSetMc) {
            //如果有音乐,则关闭音乐
            var s = this;
            s._isOnStage = false;
            var sounds = s.soundList;
            if (sounds.length > 0) {
                for (var i = 0; i < sounds.length; i++) {
                    sounds[i].stop2();
                }
            }
            s.dispatchEvent(annie.Event.REMOVE_TO_STAGE);
        };
        DisplayObject.prototype._onAddEvent = function () {
            var s = this;
            s._isOnStage = true;
            //如果有音乐,则播放音乐
            var sounds = s.soundList;
            if (sounds.length > 0) {
                for (var i = 0; i < sounds.length; i++) {
                    sounds[i].play2();
                }
            }
            s.dispatchEvent(annie.Event.ADD_TO_STAGE);
        };
        DisplayObject.prototype._onUpdateFrame = function (mcSpeed) {
            if (mcSpeed === void 0) { mcSpeed = 1; }
            if (this._visible) {
                this.dispatchEvent(annie.Event.ENTER_FRAME);
            }
        };
        /**
         * 启动鼠标或者触摸拖动
         * @method startDrag
         * @param {boolean} isCenter 指定将可拖动的对象锁定到指针位置中心 (true),还是锁定到用户第一次单击该对象的位置 (false) 默认false
         * @param {annie.Rectangle} bounds 相对于显示对象父级的坐标的值,用于指定 Sprite 约束矩形
         * @since 1.1.2
         * @public
         * @return {void}
         */
        DisplayObject.prototype.startDrag = function (isCenter, bounds) {
            if (isCenter === void 0) { isCenter = false; }
            if (bounds === void 0) { bounds = null; }
            var s = this;
            annie.Stage._dragDisplay = s;
            annie.Stage._isDragCenter = isCenter;
            annie.Stage._lastDragPoint.x = Number.MAX_VALUE;
            annie.Stage._lastDragPoint.y = Number.MAX_VALUE;
            if (bounds) {
                annie.Stage._dragBounds.x = bounds.x;
                annie.Stage._dragBounds.y = bounds.y;
                annie.Stage._dragBounds.width = bounds.width;
                annie.Stage._dragBounds.height = bounds.height;
            }
            else {
                annie.Stage._dragBounds.x = 0;
                annie.Stage._dragBounds.y = 0;
                annie.Stage._dragBounds.width = Number.MIN_VALUE;
                annie.Stage._dragBounds.height = Number.MIN_VALUE;
            }
        };
        /**
         * 停止鼠标跟随
         * @method stopDrag
         */
        DisplayObject.prototype.stopDrag = function () {
            annie.Stage._dragDisplay = null;
        };
        /**
         * 如果你在mc更改了对象的x y scale rotation alpha,最后想还原,不再需要自我控制,可以调用这方法
         * @method clearCustomTransform
         * @param transId{number}  //0->x,1->y,2->scaleX,3->scaleY,4->rotation,5->alpha,-1->all
         * @public
         * @since 3.1.0
         */
        DisplayObject.prototype.clearCustomTransform = function (transId) {
            if (transId === void 0) { transId = -1; }
            var s = this;
            if (transId = -1) {
                for (var i = 0; i < 6; i++) {
                    s._changeTransformInfo[i] = false;
                }
            }
            else {
                s._changeTransformInfo[transId] = false;
            }
        };
        DisplayObject.prototype.clearBounds = function () {
            this._bounds.x = 0;
            this._bounds.y = 0;
            this._bounds.width = 0;
            this._bounds.height = 0;
        };
        //为了 hitTestPoint,localToGlobal,globalToLocal等方法不复新不重复生成新的点对象而节约内存
        DisplayObject._p1 = new annie.Point();
        DisplayObject._p2 = new annie.Point();
        DisplayObject._p3 = new annie.Point();
        DisplayObject._p4 = new annie.Point();
        //画缓存位图的时候需要使用
        //<h4><font color="red">小游戏不支持 小程序不支持</font></h4>
        DisplayObject._canvas = window.document.createElement("canvas");
        DisplayObject._transformRect = new annie.Rectangle();
        return DisplayObject;
    }(annie.EventDispatcher));
    annie.DisplayObject = DisplayObject;
})(annie || (annie = {}));

    
Top