818人加入学习
(6人评价)
Cocos Creator初学者零基础小白入门教程2024最新版-基于3.8.x

完成于2024年12月27日 使用Cocos Creator 3.8.4 编辑器使用VS Code

价格 免费

input.on(Input.EventType.KEY_DOWN,this.method,this)

 

method(event:EventKeyboard){

switch(event.keyCode){

case KeyCode.SPACE:

console.log("被按下了")

}

}

[展开全文]

@property(Prefab)

@property({type:Prefab})

pr:Prefab=null

if(this.pr){

let newNode=instantiate(this.pr)

this.node.addChild(newNode)

newNode.setPosition(100,100)

}else{

console.log("请设置预制体:)

}

[展开全文]

let newPosition = this.node.getPosition().add3f(100*deltaTime,0,0)

this.node.setPosition(newPosition)

 

[展开全文]

conts v1 = new Vec2(1,0)

const v2 = new Vec2(0,50)

 

v1.add(v2)

v1.subtract(v2)

v1.multiplyScalar(3)

v1.dot(v2)

v1.length()

v1.normalize()

[展开全文]

 const = worldPosition

=this.node.getWordPosition;

this.node.setWorldPosition(300,40);

 

 

[展开全文]

this.node.setPosition(100,200)

this.node.setRotationFromEuler(0,0,45)

this.node.setScale(2,2)

 

let newNode = new Node("newnode")

this.node.addChild(newNode)

directior.getScene().addChild(newNode)

newNode.setParent(this.node)

this.node.getChildByName("newNode")

find("Canvas/bird").name

this.node.removeAllChildren()

this.node.destroy()

 

[展开全文]

director.addPersistRootNode(this.node);

切换场景不会消失

[展开全文]

//本地坐标转换为世界坐标
let worldPos = this.node.getComponent(UITransform).convertToWorldSpaceAR(this.node.getPosition()):
console.log(worldPos);
//世界坐标转换为本地坐标
let localPos = this.node.getComponent(UITransform).convertToNodeSpaceAR(worldPos)
console.log(localPos):

[展开全文]

this.node.setRotationFromEuler(0,0,90);

二维角度

[展开全文]

throw new Error

throw 语句用于抛出用户自定义的异常。当前函数的执行将停止(throw 之后的语句不会被执行),并且控制权将传递给调用堆栈中第一个 catch 块。如果调用函数中没有 catch 块,则程序将终止。

[展开全文]

授课教师

老师Jokey

课程特色

下载资料(3)
视频(82)