You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
4 weeks ago
|
// Learn TypeScript:
|
||
|
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
|
||
|
// Learn Attribute:
|
||
|
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
|
||
|
// Learn life-cycle callbacks:
|
||
|
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
|
||
|
|
||
|
const {ccclass, property} = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
export default class RotateScripts extends cc.Component {
|
||
|
|
||
|
@property(cc.Float)
|
||
|
rotate: number = 20;
|
||
|
|
||
|
@property(cc.Float)
|
||
|
time: number = 0.1;
|
||
|
tw = null;
|
||
|
|
||
|
// LIFE-CYCLE CALLBACKS:
|
||
|
|
||
|
onLoad () {
|
||
|
// cc.tween(this.node).repeatForever(cc.tween().to(0.5,{angle:0.8}).to(0.5,{angle:1})).start();
|
||
|
}
|
||
|
stop(){
|
||
|
if (this.tw !=null){
|
||
|
console.log("rotate stop");
|
||
|
this.node.angle = 0;
|
||
|
this.tw.stop();
|
||
|
this.tw = null;
|
||
|
}
|
||
|
}
|
||
|
start () {
|
||
|
console.log("rotate start")
|
||
|
this.tw = cc.tween(this.node)
|
||
|
.repeatForever(
|
||
|
cc.tween()
|
||
|
.to(this.time, { angle: this.rotate })
|
||
|
.to(this.time*2, { angle: -this.rotate })
|
||
|
.to(this.time, { angle: 0 })
|
||
|
.to(this.time, { angle: this.rotate })
|
||
|
.to(this.time*2, { angle: -this.rotate })
|
||
|
.to(this.time, { angle: 0 })
|
||
|
.delay(this.time*5)
|
||
|
)
|
||
|
.start()
|
||
|
}
|
||
|
startCustom () {
|
||
|
console.log("rotate start")
|
||
|
this.tw = cc.tween(this.node)
|
||
|
.repeatForever(
|
||
|
cc.tween()
|
||
|
.to(this.time, { angle: this.rotate })
|
||
|
.to(this.time*2, { angle: -this.rotate })
|
||
|
.to(this.time, { angle: 0 })
|
||
|
.to(this.time, { angle: this.rotate })
|
||
|
.to(this.time*2, { angle: -this.rotate })
|
||
|
.to(this.time, { angle: 0 })
|
||
|
.delay(this.time*5)
|
||
|
)
|
||
|
.start()
|
||
|
}
|
||
|
// update (dt) {}
|
||
|
}
|