Commit 0f3b7ef9 authored by Vũ Gia Vương's avatar Vũ Gia Vương

fix sound

parent a3d9668a
...@@ -81,10 +81,10 @@ ...@@ -81,10 +81,10 @@
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 20 "__id__": 22
}, },
{ {
"__id__": 21 "__id__": 23
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -340,15 +340,18 @@ ...@@ -340,15 +340,18 @@
}, },
{ {
"__id__": 11 "__id__": 11
},
{
"__id__": 18
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 18 "__id__": 20
}, },
{ {
"__id__": 19 "__id__": 21
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -879,6 +882,87 @@ ...@@ -879,6 +882,87 @@
}, },
"_id": "f90tlUC7RA1YLuKG15c4Pu" "_id": "f90tlUC7RA1YLuKG15c4Pu"
}, },
{
"__type__": "cc.Node",
"_name": "beer-bottle-rolling-on-a-sidewalk-82234",
"_objFlags": 0,
"_parent": {
"__id__": 7
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 19
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "fcC9SDAdpKh6z4m06bLq2V"
},
{
"__type__": "cc.AudioSource",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 18
},
"_enabled": true,
"_clip": {
"__uuid__": "639035b2-15a3-4a79-ac7f-abd23df23aff"
},
"_volume": 1,
"_mute": false,
"_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false,
"preload": false,
"_id": "80k2g8qvZFAZ/Vd/Ci7e0G"
},
{ {
"__type__": "4cdbdL97VxHIokBkhUMm2qL", "__type__": "4cdbdL97VxHIokBkhUMm2qL",
"_name": "", "_name": "",
...@@ -893,6 +977,9 @@ ...@@ -893,6 +977,9 @@
"backgroundMusic": { "backgroundMusic": {
"__uuid__": "a61f36bb-65e5-43e9-82b6-5a8d59050d31" "__uuid__": "a61f36bb-65e5-43e9-82b6-5a8d59050d31"
}, },
"rollingSound": {
"__id__": 19
},
"_id": "45maHBUxRJZZuwRoPaDXFL" "_id": "45maHBUxRJZZuwRoPaDXFL"
}, },
{ {
......
...@@ -15,12 +15,13 @@ export default class DevicemotionController extends cc.Component { ...@@ -15,12 +15,13 @@ export default class DevicemotionController extends cc.Component {
protected onLoad(): void { protected onLoad(): void {
this._debug = this.node.getComponentInChildren(cc.Label); this._debug = this.node.getComponentInChildren(cc.Label);
if (cc.sys.os === cc.sys.OS_IOS) { this.scheduleOnce(this.setDeviceMotion, 2);
this.setDeviceMotionIOS(); // if (cc.sys.os === cc.sys.OS_IOS) {
} // this.setDeviceMotionIOS();
else { // }
this.scheduleOnce(this.setDeviceMotion, 2); // else {
} // this.scheduleOnce(this.setDeviceMotion, 2);
// }
} }
private setDeviceMotionIOS() { private setDeviceMotionIOS() {
......
import { eventTarget, PLAY_BREAKING_SOUND, PLAY_DROP_SOUND, PLAY_ROLLING_SOUND } from "./Events"; import { eventTarget, PLAY_BREAKING_SOUND, PLAY_DROP_SOUND, PLAY_ROLLING_SOUND } from "./Events";
const {ccclass, property} = cc._decorator; const {ccclass, property} = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class NewClass extends cc.Component {
@property(cc.AudioSource)
private rollingSound: cc.AudioSource = null;
@property(cc.AudioSource) @property(cc.AudioSource)
private breakingSound: cc.AudioSource = null; private breakingSound: cc.AudioSource = null;
...@@ -16,15 +10,10 @@ export default class NewClass extends cc.Component { ...@@ -16,15 +10,10 @@ export default class NewClass extends cc.Component {
private dropSound: cc.AudioSource = null; private dropSound: cc.AudioSource = null;
onLoad () { onLoad () {
eventTarget.on(PLAY_ROLLING_SOUND, this.playRollingSound, this);
eventTarget.on(PLAY_BREAKING_SOUND, this.playBreakingSound, this); eventTarget.on(PLAY_BREAKING_SOUND, this.playBreakingSound, this);
eventTarget.on(PLAY_DROP_SOUND, this.playDropSound, this); eventTarget.on(PLAY_DROP_SOUND, this.playDropSound, this);
} }
private playRollingSound() {
this.rollingSound.play();
}
private playBreakingSound() { private playBreakingSound() {
this.breakingSound.play(); this.breakingSound.play();
} }
......
import { eventTarget, PLAY_ROLLING_SOUND } from "../Events";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -7,14 +8,21 @@ export default class StartScreen extends cc.Component { ...@@ -7,14 +8,21 @@ export default class StartScreen extends cc.Component {
private selectBtnNode: cc.Node = null; private selectBtnNode: cc.Node = null;
@property(cc.AudioClip) @property(cc.AudioClip)
private backgroundMusic: cc.AudioClip = null; private backgroundMusic: cc.AudioClip = null;
@property(cc.AudioSource)
private rollingSound: cc.AudioSource = null;
protected onLoad(): void { protected onLoad(): void {
this.selectBtnNode.on('click', this.onSelectBtnClick, this); this.selectBtnNode.on('click', this.onSelectBtnClick, this);
cc.director.preloadScene('main'); cc.director.preloadScene('main');
if (!cc.audioEngine.isMusicPlaying()) { if (!cc.audioEngine.isMusicPlaying()) {
cc.audioEngine.playMusic(this.backgroundMusic, true); cc.audioEngine.playMusic(this.backgroundMusic, true);
} }
eventTarget.on(PLAY_ROLLING_SOUND, this.playRollingSound, this);
}
private playRollingSound() {
this.rollingSound.play();
} }
private onSelectBtnClick() { private onSelectBtnClick() {
......
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