From efa0d249da62eac6d7025bb9bc45edb773a5ec54 Mon Sep 17 00:00:00 2001 From: JoneLau <32630749+JoneLau@users.noreply.github.com> Date: Thu, 25 Apr 2019 10:11:28 +0800 Subject: [PATCH] fix bug (#4297) --- cocos/3d/ui/components/canvas-component.ts | 15 +++++---------- cocos/3d/ui/components/widget-manager.ts | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/cocos/3d/ui/components/canvas-component.ts b/cocos/3d/ui/components/canvas-component.ts index 8993d7d531..be3bd43757 100644 --- a/cocos/3d/ui/components/canvas-component.ts +++ b/cocos/3d/ui/components/canvas-component.ts @@ -28,11 +28,11 @@ import { CameraComponent } from '../../../3d/framework/camera-component'; import { Component } from '../../../components/component'; import { ccclass, executeInEditMode, executionOrder, menu, property, requireComponent } from '../../../core/data/class-decorator'; import { Size, Vec3 } from '../../../core/value-types'; +import { vec3 } from '../../../core/vmath'; import { GFXClearFlag } from '../../../gfx/define'; import { Camera } from '../../../renderer/scene/camera'; import { UITransformComponent } from './ui-transfrom-component'; -const _tempPos = new Vec3(); const _worldPos = new Vec3(); /** @@ -223,10 +223,7 @@ export class CanvasComponent extends Component { if (CC_EDITOR) { // nodeSize = designSize = cc.engine.getDesignResolutionSize(); nodeSize = designSize = this._designResolution; - _tempPos.x = designSize.width * 0.5; - _tempPos.y = designSize.height * 0.5; - _tempPos.z = 0; - + vec3.set(_worldPos, designSize.width * 0.5, designSize.height * 0.5, 1); } else { const canvasSize = cc.visibleRect; @@ -241,13 +238,11 @@ export class CanvasComponent extends Component { offsetY = (designSize.height - canvasSize.height) * 0.5; } - _tempPos.x = canvasSize.width * 0.5 + offsetX; - _tempPos.y = canvasSize.height * 0.5 + offsetY; - _tempPos.z = 0; + vec3.set(_worldPos, canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY, 1); } - if (this._pos.equals(_tempPos)) { - this.node.setPosition(_tempPos); + if (!this._pos.equals(_worldPos)){ + this.node.setPosition(_worldPos); } if (this.node.width !== nodeSize.width) { diff --git a/cocos/3d/ui/components/widget-manager.ts b/cocos/3d/ui/components/widget-manager.ts index 0e2090238c..55604849f3 100644 --- a/cocos/3d/ui/components/widget-manager.ts +++ b/cocos/3d/ui/components/widget-manager.ts @@ -558,7 +558,7 @@ export const widgetManager = cc._widgetManager = { l += zero.x; l *= one.x; temp = pos.x - myAP.x * widgetNode.width! * widgetNodeScale.x - l; - if (widget.isAbsoluteLeft) { + if (!widget.isAbsoluteLeft) { temp /= matchSize.width; } @@ -570,7 +570,7 @@ export const widgetManager = cc._widgetManager = { let r = (1 - parentAP.x) * matchSize.width; r += zero.x; temp = (r *= one.x) - (pos.x + (1 - myAP.x) * widgetNode.width! * widgetNodeScale.x); - if (widget.isAbsoluteRight) { + if (!widget.isAbsoluteRight) { temp /= matchSize.width; }