mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-05 19:28:10 +08:00
添加圆的匀速运动
This commit is contained in:
@@ -41,8 +41,8 @@
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0.2735742330551149,
|
||||
"y": 0.2735742330551149,
|
||||
"x": 0.27357423305511475,
|
||||
"y": 0.27357423305511475,
|
||||
"z": 1
|
||||
},
|
||||
"_quat": {
|
||||
@@ -529,7 +529,7 @@
|
||||
"_id": "aefG3hjpNAnaSIWwfrO4A9"
|
||||
},
|
||||
{
|
||||
"__type__": "a2006XCMehNSpGjCn0Q+KOv",
|
||||
"__type__": "c213f3DKQxMSaAcM7zBkGet",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
@@ -539,8 +539,8 @@
|
||||
"nodePath": {
|
||||
"__id__": 10
|
||||
},
|
||||
"circle": 50,
|
||||
"speed": 10,
|
||||
"_id": "a8Bcd1Z3VMGqcw+iqBTUqe"
|
||||
"r": 50,
|
||||
"speed": 100,
|
||||
"_id": "93hKGb6pFEdJa4zQYFKozA"
|
||||
}
|
||||
]
|
||||
75
CirclePath/assets/Script/CircleRun.js
Normal file
75
CirclePath/assets/Script/CircleRun.js
Normal file
@@ -0,0 +1,75 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodePath: cc.Node,
|
||||
r: 50,
|
||||
speed: 10,
|
||||
},
|
||||
|
||||
/**
|
||||
* 构造函数,不能在此操作this.node
|
||||
* 只能做变量初始化
|
||||
*/
|
||||
ctor() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件脚本的初始化,可以操作this.node
|
||||
*/
|
||||
onLoad() {
|
||||
this.startX = this.r;
|
||||
this.perimeterMax = 2 * this.r * Math.PI;
|
||||
this.speed = this.speed;
|
||||
this.perimeter = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* 注册事件
|
||||
*/
|
||||
registerEvent() {
|
||||
},
|
||||
|
||||
/**
|
||||
* 使用cc.instantiate()创建实例时
|
||||
* 通过getComponent(脚本名称)取得脚本实例
|
||||
* 然后使用init(data)来传递参数
|
||||
* @param {*} data
|
||||
*/
|
||||
init(data) {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 通常用于初始化一些中间状态的数据
|
||||
*/
|
||||
start() {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 每一帧回调
|
||||
* @param {*} dt
|
||||
*/
|
||||
update(dt) {
|
||||
//长度增长。
|
||||
this.perimeter += dt * this.speed;
|
||||
if (this.perimeter >= this.perimeterMax) {
|
||||
this.perimeter = 0;
|
||||
}
|
||||
//得到弧度
|
||||
let radian = this.perimeter / this.r;
|
||||
console.log('radian=', radian);
|
||||
let x = this.r * Math.cos(radian);
|
||||
let y = this.r * Math.sin(radian);
|
||||
console.log('x=', x, 'y=', y);
|
||||
this.nodePath.setPosition(cc.v2(x, y));
|
||||
},
|
||||
|
||||
/**
|
||||
* 统一回收组件
|
||||
*/
|
||||
onDestroy() {
|
||||
}
|
||||
});
|
||||
9
CirclePath/assets/Script/CircleRun.js.meta
Normal file
9
CirclePath/assets/Script/CircleRun.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "c213fdc3-290c-4c49-a01c-33bcc19067ad",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user