(四)、“仙剑出鞘”---准心的周期运行

主要代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

@property(cc.Node)
mZhunXinHengTiao: cc.Node = null;

@property(cc.Node)
mZhunXin: cc.Node = null;


@property(cc.Integer)
time_speed:Number = 1; // 时间流逝倍率
@property(cc.Integer)
cycle_time:Number = 5; // 一个周期所用时间

max_x:Number = 0; // 最大偏移
total_move_time:Number = 0; // 总移动时间
per_move_time:Number = 0; // 每帧移动时间


start () {
this.max_x = this.mZhunXinHengTiao.width/2
this.total_move_time = 0
}
update (dt) {
let PI = 3.14159
this.per_move_time = dt*Number(this.time_speed) // 每帧移动时间
this.total_move_time = Number(this.total_move_time) + Number(this.per_move_time) // 总移动时间
this.mZhunXin.x = Number(this.max_x)*Math.sin(2*PI*(Number(this.total_move_time)/Number(this.cycle_time))) // 准心的偏移量
}

主要涉及的cocos函数

1、Math.sin

正弦余弦

2、update(dt)

dt代表的每帧所用时间