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

add sound

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