DaFuWeng/assets/GlobalScript/CommonComponent/ShowNodeBorder.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

/*
* @Author: WoNiu
* @Date: 2024-03-24 16:09:55
* @LastEditTime: 2024-03-24 16:30:46
* @LastEditors: WoNiu
* @Description: node的位置和大小01
*/
import { _decorator, Color, Component, Graphics, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ShowNodeBorder')
/**
* @description: node的位置和大小01
*/
export class ShowNodeBorder extends Component {
graphics: Graphics;
onLoad() {
if(this.node.getComponent(Graphics)){
this.graphics = this.node.getComponent(Graphics);
}else{
this.graphics = this.node.addComponent(Graphics);
}
this.updateBorder();
}
updateBorder() {
const borderColor = Color.YELLOW;
const borderWidth = 4;
const contentSize = this.node.getComponent(UITransform).contentSize;
this.graphics.clear();
this.graphics.strokeColor = borderColor;
this.graphics.lineWidth = borderWidth;
// this.graphics.rect(-contentSize.width / 2, -contentSize.height / 2, contentSize.width, contentSize.height);// 锚点 (0,0)
this.graphics.rect(0, 0, contentSize.width, -contentSize.height); //锚点 (0,1)
this.graphics.stroke();
}
start() {
}
update(deltaTime: number) {
}
}