Commit 22254b11 authored by Vũ Gia Vương's avatar Vũ Gia Vương

add sound

parent 07d5311e
This diff is collapsed.
...@@ -6,3 +6,5 @@ export const SHOW_START_SCREEN = 'SHOW_START_SCREEN'; ...@@ -6,3 +6,5 @@ export const SHOW_START_SCREEN = 'SHOW_START_SCREEN';
export const SHOW_CARD_POPUP = 'SHOW_CARD_POPUP'; export const SHOW_CARD_POPUP = 'SHOW_CARD_POPUP';
export const STOP_ANIM_CHUM = 'STOP_ANIM_CHUM'; export const STOP_ANIM_CHUM = 'STOP_ANIM_CHUM';
export const SHOW_SELECT_POPUP = 'SHOW_SELECT_POPUP'; export const SHOW_SELECT_POPUP = 'SHOW_SELECT_POPUP';
export const PLAY_ROLLING_SOUND = 'PLAY_ROLLING_SOUND';
\ No newline at end of file
...@@ -20,7 +20,6 @@ export default class BuaController extends cc.Component { ...@@ -20,7 +20,6 @@ export default class BuaController extends cc.Component {
this._chumCtrl = this.chumNode.getComponent(ChumController); this._chumCtrl = this.chumNode.getComponent(ChumController);
this.spine = this.node.getComponent(sp.Skeleton); this.spine = this.node.getComponent(sp.Skeleton);
// this.spine.setSkin(this._skins[this.index % this._skins.length]);
this.spine.setSkin('Bua'); this.spine.setSkin('Bua');
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
...@@ -33,7 +32,6 @@ export default class BuaController extends cc.Component { ...@@ -33,7 +32,6 @@ export default class BuaController extends cc.Component {
private onTouchStart(): void { private onTouchStart(): void {
this._actions[this._count].bind(this)(); this._actions[this._count].bind(this)();
console.log('this._count', this._count)
this._count = (this._count + 1) % this._actions.length; this._count = (this._count + 1) % this._actions.length;
} }
......
import { eventTarget, PLAY_ROLLING_SOUND } from "../Events";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class HuController extends cc.Component { export default class HuController extends cc.Component {
@property(cc.Label)
private text: cc.Label = null;
private spine: sp.Skeleton = null; private spine: sp.Skeleton = null;
...@@ -16,16 +19,17 @@ export default class HuController extends cc.Component { ...@@ -16,16 +19,17 @@ export default class HuController extends cc.Component {
protected onLoad(): void { protected onLoad(): void {
this.spine = this.node.getComponent(sp.Skeleton); this.spine = this.node.getComponent(sp.Skeleton);
// this.setRotateAnim();
// this.node.on(cc.Node.EventType.TOUCH_START, this.toggleAnim, this);
this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this); 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_END, this.onTouchEnd, this)
this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this) this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
this.spine.setCompleteListener(() => this.setRotateAnim()); this.spine.setCompleteListener(() => this.setRotateAnim());
this.scheduleOnce(() => this.testDevice, 1); }
protected start(): void {
this.scheduleOnce(() => this.testDevice, 1);
console.log('testDevice',)
} }
private testDevice() { private testDevice() {
...@@ -33,6 +37,10 @@ export default class HuController extends cc.Component { ...@@ -33,6 +37,10 @@ export default class HuController extends cc.Component {
if (!event.accelerationIncludingGravity) { if (!event.accelerationIncludingGravity) {
return; return;
} }
this.text.string = `
x: ${event.accelerationIncludingGravity.x},
y: ${event.accelerationIncludingGravity.y},
z: ${event.accelerationIncludingGravity.z}`;
const x = event.accelerationIncludingGravity.x; const x = event.accelerationIncludingGravity.x;
const y = event.accelerationIncludingGravity.y; const y = event.accelerationIncludingGravity.y;
...@@ -58,6 +66,17 @@ export default class HuController extends cc.Component { ...@@ -58,6 +66,17 @@ export default class HuController extends cc.Component {
if (this._count > 5) { if (this._count > 5) {
this._count = 0; this._count = 0;
this.shakeBottle();
}
this._x = x;
this._y = y;
this._z = z;
});
}
private shakeBottle() {
eventTarget.emit(PLAY_ROLLING_SOUND);
cc.tween(this.node) cc.tween(this.node)
.to(0.2, { position: cc.v3(20, 0, 0) }) .to(0.2, { position: cc.v3(20, 0, 0) })
.to(0.2, { position: cc.v3(-20, 0, 0) }) .to(0.2, { position: cc.v3(-20, 0, 0) })
...@@ -67,13 +86,6 @@ export default class HuController extends cc.Component { ...@@ -67,13 +86,6 @@ export default class HuController extends cc.Component {
.start(); .start();
} }
this._x = x;
this._y = y;
this._z = z;
});
}
private onTouchStart(event: cc.Event.EventTouch): void { private onTouchStart(event: cc.Event.EventTouch): void {
if (!this._pointStart) { if (!this._pointStart) {
this.setRotateAnim(); this.setRotateAnim();
......
import { eventTarget, PLAY_ROLLING_SOUND } from "./Events";
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.AudioSource)
private rollingSound: cc.AudioSource = null;
onLoad () {
eventTarget.on(PLAY_ROLLING_SOUND, this.playRollingSound, this);
}
private playRollingSound() {
this.rollingSound.play();
}
}
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