Laya layout算法

        /**
         * <p>重置对象的 <code>X</code> 轴(水平方向)布局。</p>
         * @private
         */
        public function resetLayoutX():void {
            var owner:Sprite = this.owner as Sprite;
            if (!owner) return;
            var parent:Sprite = owner.parent as Sprite;
            if (parent) {
                if (!isNaN(centerX)) {
                    owner.x = Math.round((parent.width - owner.displayWidth) * 0.5 + centerX + owner.pivotX * owner.scaleX);
                } else if (!isNaN(left)) {
                    owner.x = Math.round(left + owner.pivotX * owner.scaleX);
                    if (!isNaN(right)) {
                        //TODO:如果用width,会死循环
                        owner.width = (parent._width - left - right) / (owner.scaleX || 0.01);
                    }
                } else if (!isNaN(right)) {
                    owner.x = Math.round(parent.width - owner.displayWidth - right + owner.pivotX * owner.scaleX);
                }
            }
        }

 其中,

displayWidth是width*scaleX
posted @ 2019-08-26 11:41  ixenos  阅读(547)  评论(0编辑  收藏  举报