如何给所有的按钮点击,添加一个默认声音。每个回调里加一行代码,太麻烦 了
写一个组件,挂载到按钮上
cc.Class({
extends: cc.Component,
properties: {
clickSound: {default: null, displayName: "按钮声音", url: cc.AudioClip},
},
onLoad: function () {
this.node.on(cc.Node.EventType.TOUCH_START, function () {
if (this.clickSound) {
// 播放选择的声音
} else {
// 播放默认的声音
}
return true;
}, this);
this.node.on(cc.Node.EventType.TOUCH_END, function () {
}, this);
this.node.on(cc.Node.EventType.TOUCH_CANCEL, function () {
}, this);
this.node.on(cc.Node.EventType.TOUCH_MOVE, function () {
}, this);
},
});