Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
moshuying committed Jul 26, 2023
1 parent a27c7f4 commit c7759aa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,24 @@ export class Canvas extends RenderRoot2D {
this.node.getPosition(this._pos);
const nodeSize = view.getDesignResolutionSize();
const trans = this.node._uiProps.uiTransformComp!;
Vec3.set(_worldPos, nodeSize.width * trans.anchorX, nodeSize.height * trans.anchorY, 0);

let scaleX = this.node.scale.x;
let anchorX = trans.anchorX;
if (scaleX < 0) {
anchorX = 1.0 - anchorX;
scaleX = -scaleX;
}
nodeSize.width = scaleX === 0 ? nodeSize.width : nodeSize.width / scaleX;

let scaleY = this.node.scale.y;
let anchorY = trans.anchorY;
if (scaleY < 0) {
anchorY = 1.0 - anchorY;
scaleY = -scaleY;
}
nodeSize.height = scaleY === 0 ? nodeSize.height : nodeSize.height / scaleY;

Vec3.set(_worldPos, nodeSize.width * anchorX, nodeSize.height * anchorY, 0);

if (!this._pos.equals(_worldPos)) {
this.node.setPosition(_worldPos);
Expand Down

0 comments on commit c7759aa

Please sign in to comment.