l ๐ค ์ฝ๋ l
์ฌ๋ฌ๊ฐ ๋ฒํผ ์๋ฆฌ ํ๋ฒ์ ๋ฃ๊ธฐ/ ์ฝ์ฝ์ค ํฌ๋ฆฌ์์ดํฐ โจ์ฝ๋๊ทธ๋ฆผ
CODEGREAM
2023. 7. 25. 00:09
๋ฐ์ํ
์๋ ํ์ธ์~
์ฝ๋๊ทธ๋ฆผ์ ๋๋ค.
์ฝ์ฝ์ค ํฌ๋ฆฌ์์ดํฐ์์ ๋ฒํผ ์ฌ๋ฌ๊ฐ์๋ค ํ๋ฒ์ ์ฌ์ด๋ ์ ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด๊ฒ ์ต๋๋ค.
1. ๋ ธ๋ํธ๋ฆฌ์์ ๋น ๋ ธ๋๋ฅผ ๋ง๋ ๋ค.
2. ๋ ธํธ๋ฅผ buttons๋ผ๊ณ ๋ช ๋ช ํ๊ณ ๋ ธ๋์์ ๋ฒํผ๋ค์ ๋ค ๋ฃ๋๋ค.
3. Buttons_sound๋ผ๋ ์๋ฐ์คํฌ๋ฆฝํธ ํ์ผ์ ์์ฑํ๋ค.
//๋ฒํผ์๋ฆฌ ์ค์ ํ์ผ
cc.Class({
extends: cc.Component,
properties: {
btn_sound: {
default: null,
type: cc.AudioClip
}
},
onLoad: function () {
var buttons = this.node.children;
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i].getComponent(cc.Button);
if (button) {
button.node.on('click', this.onButtonClick, this);
}
}
},
onButtonClick: function () {
// ๋ฒํผ ์๋ฆฌ ์ฌ์
if (this.btn_sound) {
cc.audioEngine.playEffect(this.btn_sound, false);
}
},
// update (dt) {},
});
์์๊ฐ์ด ์ฝ๋๋ฅผ ๋ฃ์ด์ค๋ค.
4. Buttons ๋ ธ๋์ Buttons_sound ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ฐ๋ํ๋ค.
5. Btn Sound audio-clip์ ๋ฒํผ ์๋ฆฌ mp3ํ์ผ์ ๋ฃ์ด์ค๋ค.
6. ์ ์ฅํ๊ณ ๊ฒ์์ ์ฌ์ํ๋ค.
์ฐธ~ ์ฝ์ฃ ์? ใ ใ ใ
๊ทธ๋ผ ์ค๋๋ ๋ชจ๋๋ชจ๋ ํ๋ณต์ฝ๋ฉํ์ญ์ผ!
์ฝ๋๊ทธ๋ฆผ์ด์์ต๋๋ค~!
๋ฐ์ํ