/* * @Author: WoNiu * @Date: 2024-03-23 13:22:27 * @LastEditTime: 2024-03-24 16:04:20 * @LastEditors: WoNiu * @Description: node坐标控制 */ import { _decorator, Color, Component, EditBox, Font, HorizontalTextAlignment, Node, Size, Sprite, UITransform, v2, VerticalTextAlignment, } from "cc"; const { ccclass, property } = _decorator; @ccclass("LocationImportComponent") /** * @description: node坐标控制 */ export class LocationImportComponent extends Component { editBox: EditBox; onLoad(): void { const node = new Node(); node.setPosition(0, 30); const uit = node.addComponent(UITransform); uit.anchorPoint = v2(0, 1); uit.setContentSize(new Size(150, 30)); const sp = node.addComponent(Sprite); sp.color = Color.WHITE; const editBox = node.addComponent(EditBox); editBox.inputMode = EditBox.InputMode.SINGLE_LINE; this.editBox = editBox; this.node.addChild(node); //* 修改 node 的坐标 editBox.node.on("editing-did-ended", (text: EditBox) => { const los = text.textLabel.string.split(','); this.node.setPosition(Number(los[0]),Number(los[1])); }); } start() { const placeholderLabel = this.editBox.placeholderLabel; placeholderLabel.string = "坐标"; placeholderLabel.horizontalAlign = HorizontalTextAlignment.LEFT; placeholderLabel.verticalAlign = VerticalTextAlignment.TOP; placeholderLabel.fontSize = 20; placeholderLabel.color = Color.RED; placeholderLabel.node.setPosition(0, 50); placeholderLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2); const textLabel = this.editBox.textLabel; textLabel.horizontalAlign = HorizontalTextAlignment.LEFT; textLabel.verticalAlign = VerticalTextAlignment.TOP; textLabel.fontSize = 20; textLabel.color = Color.RED; textLabel.node.setPosition(0, 50); textLabel.node.getComponent(UITransform).anchorPoint = v2(0, 2); } update(deltaTime: number) {} }