Commit 3811eacc authored by Vũ Gia Vương's avatar Vũ Gia Vương

fix rotate

parent c4ac75bf
......@@ -4,9 +4,8 @@ const { ccclass, property } = cc._decorator;
@ccclass
export default class HuController extends cc.Component {
private spine: sp.Skeleton = null;
private _isRotate: boolean = false;
private _spine: sp.Skeleton = null;
private _pointStart: cc.Vec2 = null;
private _x: number = 0;
private _y: number = 0;
......@@ -15,17 +14,63 @@ export default class HuController extends cc.Component {
private _isShake = false;
protected onLoad(): void {
this.spine = this.node.getComponent(sp.Skeleton);
this._spine = this.node.getComponent(sp.Skeleton);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
this.spine.setCompleteListener(() => {
this._spine.setCompleteListener(() => {
console.log('setCompleteListener',)
this.setRotateAnim();
});
this.scheduleOnce(this.setDeviceMotion, 2);
this.initBottle();
}
private initBottle() {
this.setRotateAnim();
let state = this._spine.getState();
let track = state.tracks[1];
track.trackTime = 3 / 4;
this._spine.timeScale = 0;
}
private onTouchStart(event: cc.Event.EventTouch): void {
// if (!this._pointStart) {
// this.setRotateAnim();
// }
this._pointStart = event.getLocation();
this._spine.timeScale = 0;
}
private onTouchEnd(): void {
this.scheduleOnce(() => this._spine.timeScale = 0, 0.5);
let state = this._spine.getState();
let track = state.tracks[1];
if (track.trackTime < 0) {
track.trackTime = 0;
}
}
private onTouchMove(event: cc.Event.EventTouch): void {
const newPoint = event.getLocation();
const distance = newPoint.x - this._pointStart.x;
if (Math.abs(distance) < 5) {
this._spine.timeScale = 0;
return;
}
this._pointStart = newPoint;
this._spine.timeScale = distance > 0 ? -1 : 1;
}
private setRotateAnim(): void {
this._spine.setAnimation(1, "Rotate", false);
this._spine.timeScale = this._pointStart ? 0 : 0.5;
}
private setDeviceMotion() {
......@@ -80,60 +125,4 @@ export default class HuController extends cc.Component {
private randomY(): number {
return Math.random() * 100 - 50;
}
private onTouchStart(event: cc.Event.EventTouch): void {
if (!this._pointStart) {
this.setRotateAnim();
}
this._pointStart = event.getLocation();
this.spine.timeScale = 0;
}
private onTouchEnd(): void {
this.scheduleOnce(() => this.spine.timeScale = 0, 0.5);
let state = this.spine.getState(); // Lấy AnimationState
let track = state.tracks[1]; // Lấy track 0 (thay số 0 nếu cần track khác)
console.log('this.spine.timeScale', this.spine.timeScale)
console.log('track', track)
}
private onTouchMove(event: cc.Event.EventTouch): void {
const newPoint = event.getLocation();
const distance = newPoint.x - this._pointStart.x;
if (Math.abs(distance) < 5) {
this.spine.timeScale = 0;
return;
}
this._pointStart = newPoint;
this.spine.timeScale = distance > 0 ? -1 : 1;
}
private setRotateAnim(): void {
this.spine.setAnimation(1, "Rotate", false);
this.spine.timeScale = this._pointStart ? 0 : 0.5;
}
private pauseAnim(): void {
this.spine.timeScale = 0;
}
private unPauseAnim(): void {
this.spine.timeScale = 0.5;
}
private toggleAnim(): void {
if (this._isRotate) {
this.unPauseAnim();
} else {
this.pauseAnim();
}
this._isRotate = !this._isRotate;
}
private setIdleAnim(): void {
this.spine.setAnimation(1, "Idle", false);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment