1 修改坐标控制 组件

2 新增显示node位置和大小的组件
This commit is contained in:
WoNiu 2024-03-24 17:57:19 +08:00
parent 763cec406f
commit 33484b3406
3 changed files with 68 additions and 2 deletions

View File

@ -1,9 +1,9 @@
/*
* @Author: WoNiu
* @Date: 2024-03-23 13:22:27
* @LastEditTime: 2024-03-23 16:12:16
* @LastEditTime: 2024-03-24 16:04:20
* @LastEditors: WoNiu
* @Description:
* @Description: node坐标控制
*/
import {
_decorator,
@ -22,6 +22,9 @@ import {
const { ccclass, property } = _decorator;
@ccclass("LocationImportComponent")
/**
* @description: node坐标控制
*/
export class LocationImportComponent extends Component {
editBox: EditBox;
@ -66,6 +69,8 @@ export class LocationImportComponent extends Component {
textLabel.color = Color.RED;
textLabel.node.setPosition(0, 50);
textLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2);
}
update(deltaTime: number) {}

View File

@ -0,0 +1,52 @@
/*
* @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) {
}
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "9ef9c0ff-8d63-448d-b95f-89b02e1455f3",
"files": [],
"subMetas": {},
"userData": {}
}