CocosCreator 向量与标量

156 阅读1分钟

标量 : 只有大小的量.

向量 : 既有大小的量,也有方向.

向量的模 : 向量的大小.

单位向量 : 大小为1的向量.

单位化,归一化 :把向量转为单位向量的过程。 向量的计算

加法:

A(x1,y1) +  B(x2,y2) = x1+x2 ,y1+y2 

减法:

A(x1,y1) -  B(x2,y2) = x1-x2 ,y1-y2 

乘法:

A(x1y1)x2 = x1x2,y1x2

点乘:得到两个向量之间的夹角

A · B = x1x2 + y1y2 = n (一个结果) = |A||B|cosθ

TypeScript

@property 开放属性

const {ccclass, property} = cc._decorator;

@ccclass export default class Test extends cc.Component {

@property(cc.Label)
label: cc.Label = null;

@property
text: string = 'hello';

@property
sss: string = 'ss';
// LIFE-CYCLE CALLBACKS:

// 初始化调用
onLoad() {
    console.debug("onLoad")
}

onEnable() {
    console.debug("onEnable")
}

// 初始化调用
start() {
    console.debug("start")
}

// 每一帧都会调用
update() { }

onDisable(){
    console.debug("onDisable")
}
// 销毁调用
onDestroy() {
    console.debug("onDestroy")
}

获取子节点方法

    // 获取子节点
    // this.node.children[0]
    // this.node.getChildByName("name")
    // cc.find("Canvas/Main Camera")
    // 获取父节点
    // this.node.getParent();
    // this.node.setParent(ddd)
    // 移除所有子节点
    // this.node.removeAllChildren()
    // 移除某个节点
    // this.node.removeChild(ddd)
    // 从父节点中移除掉
    // this.node.removeFromParent();
    // 访问位置
    // this.node.x
    // this.node.y
    // this.node.setPosition(1, 2)
    // this.node.setParent(cc.v2(3,4))

    // 选址
    // this.node.rotation
    // // 缩放
    // this.node.scale
    // // 喵点
    // this.node.anchorX

    // 节点开关
    // this.node.active = false

    // 组件开关
    // this.enabled = false;

    // 获取组件
    // let sprite = this.getComponent(cc.Sprite)

    // this.getComponentInChildren(cc.Sprite)