当前位置:网站首页>Cocos learning diary 2 - scripts and attributes
Cocos learning diary 2 - scripts and attributes
2022-06-23 04:40:00 【herb. dr】
Catalog
2.1 To configure vscode Environmental Science
3、 ... and 、 Knowledge of scripts
3.3 Check the script execution
Four 、 Event response processing
5、 ... and 、 debugging JS Code
6.1 TypeScript, Strongly typed JavaScript
6.2 JavaScript It's a weak type of language
7.1 Show properties in the engine
One 、 Add scripts to nodes


Two 、VScode Edit script
2.1 To configure vscode Environmental Science

2.2 Write a script

3、 ... and 、 Knowledge of scripts
3.1 How scripts work
1、 The game engine loads all nodes
2、 Load all the components of the node
var comp = new PigScript();
node["PigScript"]= comp;
comp.onLoad();
comp.start();
3.2 Lifetime callback
Lifetime callback Life-Cycle Callback
onLoad() Execute when the component is initialized
start() Execute before the first activation
update() Execute every frame
onEnable() Called when the component is enabled
onDisable() Called when the component is disabled
onDestroy() Call... When the component is destroyed

3.3 Check the script execution
1、 Simulator

2、 Console

Four 、 Event response processing
Event handling , and HTML Inside JavaScript Similar events
Click event mousedown / mouseup / mousemove ...
Keyboard events keyup / keydown
Touch event touchstart / touchend / touchcancel ...

The above effect has realized : Click on it. , The picture will move to the left
5、 ... and 、 debugging JS Code
Not yet , This one is used to occupy space
6、 ... and 、TypeScript
6.1 TypeScript, Strongly typed JavaScript
https://www.typescriptlang.org
6.2 JavaScript It's a weak type of language
var str = "shaofa";
var a = 10;
var node = this.node;Because there is no type identifier , So the editor can't accurately prompt
6.3 Contrastive writing
1、 Variable
JavaScript:
var str = "shaofa";
var a = 10;
var node = this.node;
TypeScript:
let str : string = "shaofa";
let a : number = 10;
let node : cc.Node = this.node;
2、 Method parameters
JavaScript:
moveLeft(evt) {
}
TypeScript:
moveLeft(evt : cc.Event.EventMouse) {
}
3、 Return value of method
JavaScript:
sum(x, y) {
return x + y;
}
TypeScript:
sum(x:number, y:number):number {
returnx + y;
}
7、 ... and 、 attribute
7.1 Show properties in the engine


7.2 Definition of attribute
1、 stay TypeScript Add a class , You can add attributes to the class
Form the following :
@property("string")
time : string="";
among ,@property It's called a decorator ( Same as Java Annotation syntax in )
2、 Rules for defining attributes
(1) If there is no @property annotation , Will not appear in Cocos Creator Property panel
(2) @property in , The type should be indicated
@property("string")
@property(cc.Node)
(3) Basic types , Can not specify type
string,number,boolean,bigint
3、TypeScript Are there in number and Number Two types of
number It's a basic type
Number It is a reference type ( object )
7.3 Application of attributes
Genus is generally divided into two types :
1、 Basic types
string,number,boolean,bigint
2、 Reference type
cc.Node node
cc.SpriteFrame Picture frame resources
cc.AudioClip Audio resources
3、 application

7.4 Reference type properties

边栏推荐
- 应急响应-hw复习
- Idea import module
- PTA:7-63 计算高考状元
- Pta:7-63 calculate the number one in the college entrance examination
- Audio and video development journey (63) - animation and rendering of Lottie source code analysis
- svg d3. JS generate tree tree view
- Cocos学习日记1——节点
- PTA: Simulation Implementation of 7-87 set (class template)
- 离线数仓建模中常见的概念-术语
- 在线JSON转CSharp(C#)Class工具
猜你喜欢

Mobile terminal city list sorting JS plug-in vertitylist js

【二叉樹進階】AVLTree - 平衡二叉搜索樹

国家药品不良反应监测中心 ADR 电子传输EDI解决方案

Pytoch --- pytoch customizes the dataset

Zhongang Mining: the demand for fluorite in the new energy and new material industry chain has increased greatly

【一起上水硕系列】Day Three - preview4

Pytoch --- use pytoch's pre training model to realize four weather classification problems

Cocos学习日记1——节点
![Fundamentals of 3D mathematics [16] formulas for uniformly accelerated linear motion](/img/51/5b05694bbd0f4fd01dd26cf55b22c7.png)
Fundamentals of 3D mathematics [16] formulas for uniformly accelerated linear motion

8位全加器原理
随机推荐
396. 矿场搭建
Redis启动有问题
抖音x-bogus和_signature参数分析
Pta:7-63 calculate the number one in the college entrance examination
在线JSON转CSharp(C#)Class工具
PTA: Simulation Implementation of 7-87 set (class template)
Getting started with tensorflow
Pta:6-29 application of virtual base classes - people, teachers and students
关于php里tcp通讯用swoole框架出现的小问题
Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
After Huawei online battle service players quickly match, different players receive different lists of players in the same room
Prince language on insect date class
What is metadata
Pytoch --- pytoch customizes the dataset
Photoshop PS viewing pixel coordinates, pixel colors, pixel HSB colors
Online JSON to CSharp (c) class tool
leetcode 91. Decode ways (medium)
JVM调优简要思想及简单案例-为什么需要JVM调优?
PTA:7-85 数据的间距问题(重载+函数模板)
How does flutter achieve different zoom animation effects