地址:https://github.com/Golangltd/LollipopCreator
版本刚刚开源,后续会持续更新!
框架文档地址:GameAIs.Com
LollipopCreator游戏框架
游戏客户端开发中,由于制作人或者策划立项的不同,导致前端开发并不像后端框架不变,例如 2D游戏开发,引擎选择就比较多,Unity、cocos、 白鹭等都可以,本系列就是给大家开源一套cocos creator引擎开发的2D游戏框架LollipopGo。 creator 系统为例,给大家梳理下前端2D游戏架构的基础设计思想。
1. 工程中的音效管理,涉及到按钮音效、背景音效、特效音效等
2. 包括预加载和资源释放调用等
例子:
playSound(file, moduleName) {
if (file && this.soundVolume > 0) {
moduleName = moduleName || 'master'
let modPath = (moduleName == 'master') ? 'Master/data/sound' : `SubModules/${moduleName}/data/sound`
let url = cc.url.raw(`resources/${modPath}/${file}.mp3`)
cc.log(url)
return cc.audioEngine.play(url, false, this.soundVolume)
}
return -1
}
注意点:主资源位置Master/data/sound
子游戏资源位置SubModules/${moduleName}/data/sound
class AudioManager {
constructor() {
this.model = {
musicID: -1,
musicFile: null
}
}
get soundVolume() {
return globalCfg.setting.soundVolume
}
set soundVolume(percent) {
globalCfg.setting.soundVolume = Math.max(0, Math.min(1, percent))
}
get musicVolume() {
return globalCfg.setting.musicVolume
}
set musicVolume(percent) {
globalCfg.setting.musicVolume = Math.max(0, Math.min(1, percent))
if (this.model.musicID >= 0) {
cc.audioEngine.setVolume(this.model.musicID, globalCfg.setting.musicVolume)
}
}
get soundEnable() {
return this.soundVolume > 0
}
get musicEnable() {
return this.musicVolume > 0
}
set soundEnable(val) {
this.soundVolume = val ? 0.5 : 0
}
set musicEnable(val) {
this.musicVolume = val ? 0.5 : 0
}
save() {
ut.storageSave('audio_setting', {
sound: globalCfg.setting.soundVolume,
music: globalCfg.setting.musicVolume,
})
}
load() {
let setting = ut.storageLoad('audio_setting', { sound: 0.5, music: 0.5 })
this.soundVolume = setting.sound
this.musicVolume = setting.music
}
playSound(file, moduleName) {
if (file && this.soundVolume > 0) {
moduleName = moduleName || 'master'
let modPath = (moduleName == 'master') ? 'Master/data/sound' : `SubModules/${moduleName}/data/sound`
let url = cc.url.raw(`resources/${modPath}/${file}.mp3`)
cc.log(url)
return cc.audioEngine.play(url, false, this.soundVolume)
}
return -1
}
playMusic(file, moduleName) {
moduleName = moduleName || 'master'
let modPath = (moduleName == 'master') ? 'Master/data/sound' : `SubModules/${moduleName}/data/sound`
let url = cc.url.raw(`resources/${modPath}/${file}.mp3`)
if (this.model.musicFile == url) {
return
}
this.stopMusic()
cc.log(url)
cc.log('musicVolumn', this.musicVolume)
this.model.musicID = cc.audioEngine.play(url, true, this.musicVolume)
if (this.model.musicID >= 0) {
this.model.musicFile = url
} else {
this.model.musicFile = null
this.model.musicID = -1
}
}
stopSound(audioID) {
if (audioID >= 0) {
cc.audioEngine.stop(audioID)
}
}
stopMusic() {
if (this.model.musicID >= 0) {
cc.audioEngine.stop(this.model.musicID)
this.model.musicFile = null
this.model.musicID = -1
}
}
}
window.audioMgr = new AudioManager()
版权申明:内容来源网络,版权归原创者所有。除非无法确认,我们都会标明作者及出处,如有侵权烦请告知,我们会立即删除并表示歉意。谢谢。