Phaser加载所有文件,但无法加载音频文件。
具有资源的JSON 文件(图像和音频文件):
"assets": {
"background_image": {
"type": "image",
"source": "assets/images/background.png"
},
"background_audio":{
"type": "audio",
"source":"assets/sound/intro_screen_sound.wav"
}
代码用于加载JSON文件:
RPG.LoadingState.prototype.preload = function () {
"use strict";
var assets, asset_key, asset;
assets = this.level_data.assets;
for (asset_key in assets) { // load assets according to asset key
asset = assets[asset_key];
switch (asset.type) {
case "image":
this.game.load.image(asset_key, asset.source);
break;
case "audio":
this.game.load.audio(asset_key, asset.source);
break;
case "spritesheet":
this.load.spritesheet(asset_key, asset.source, asset.frame_width, asset.frame_height, asset.frames, asset.margin,
asset.spacing);
break;
case "tilemap":
this.load.tilemap(asset_key,asset.source,null,Phaser.Tilemap.TILED_JSON);
break;
}
this.load.text("user_input", this.level_data.user_input);
}