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.
43 lines
931 B
43 lines
931 B
|
1 week ago
|
import { Tween } from 'cc';
|
||
|
|
import { Quat } from 'cc';
|
||
|
|
import { tween } from 'cc';
|
||
|
|
import { _decorator, Component, Node } from 'cc';
|
||
|
|
const { ccclass, property, executeInEditMode } = _decorator;
|
||
|
|
|
||
|
|
@ccclass('SelfRotate')
|
||
|
|
@executeInEditMode
|
||
|
|
export class SelfRotate extends Component {
|
||
|
|
|
||
|
|
@property
|
||
|
|
speed: number = 360;
|
||
|
|
|
||
|
|
@property
|
||
|
|
onLoadPlay: boolean = true;
|
||
|
|
|
||
|
|
public IsPlaying: boolean = false;
|
||
|
|
|
||
|
|
start() {
|
||
|
|
if (this.onLoadPlay) {
|
||
|
|
this.play();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
protected update(dt: number): void {
|
||
|
|
if (this.IsPlaying)
|
||
|
|
this.node.angle -= this.speed * dt
|
||
|
|
//this.node.rotate(Quat.fromEuler(new Quat(), 0, 0, -this.speed * dt))
|
||
|
|
}
|
||
|
|
|
||
|
|
play() {
|
||
|
|
this.IsPlaying = true;
|
||
|
|
// Tween.stopAllByTarget(this.node);
|
||
|
|
// tween(this.node).by(1, { angle: this.speed }).repeatForever().start();
|
||
|
|
}
|
||
|
|
|
||
|
|
stop() {
|
||
|
|
this.IsPlaying = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|