SoundEffectButton.ts
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Learn TypeScript:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
// - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
import { GameBasicSettings } from "../gameplay/settings/GameBasicSettings";
const { ccclass, property } = cc._decorator;
@ccclass
export default class SoundEffectButton extends cc.Component {
@property({ type: cc.AudioClip })
clip: cc.AudioClip = null as any as cc.AudioClip;
interactable: boolean = true;
// LIFE-CYCLE CALLBACKS:
onLoad() {
}
onEnable() {
this.node.on(cc.Node.EventType.TOUCH_END, this.onPlaySoundEffectCallback, this);
}
onDisable() {
this.node.off(cc.Node.EventType.TOUCH_END, this.onPlaySoundEffectCallback, this);
}
onPlaySoundEffectCallback(event) {
if (!this.clip) {
console.log("current clip is null.");
} else if (this.interactable) {
if (GameBasicSettings.soundVolume != 0)
cc.audioEngine.playEffect(this.clip, false)
}
}
start() {
}
// update (dt) {}
}