节点的常用方法属性
const {ccclass, property} = cc._decorator;

@ccclass
export default class Helloworld extends cc.Component {

    @property(cc.Node)
    nodeVar:cc.Node = null

    start () {
        this.node.active = false //设置激活状态
        this.node.parent = this.nodeVar //设置父节点 等价于下面两行
        this.node.removeFromParent(false)
        this.nodeVar.addChild(this.node)

        //更改位置
        this.node.x = 100
        this.node.y = 100
        this.node.setPosition(100,100)
        this.node.setPosition(cc.v2(100,100))
        this.node.position = cc.v2(100,100)

        //更改旋转
        this.node.rotation = 90
        this.node.setRotation(90)

        //更改缩放
        this.node.scaleX = 2
        this.node.scaleY = 2
        this.node.setScale(2,2)

        //更改节点尺寸
        this.node.setContentSize(100,100)
        this.node.setContentSize(cc.size(100,100))
        this.node.width = 100
        this.node.height = 100

        //更改节点锚点位置
        this.node.anchorX = 1
        this.node.anchorY = 0
        this.node.setAnchorPoint(1,0)
    }
}

首页 我的博客
粤ICP备17103704号