feat: tested load single audio/image
This commit is contained in:
parent
11e3362bf2
commit
c62bd6b209
|
@ -1044,7 +1044,7 @@ export default class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadSingleImage(key: string, path: string, isDependency: boolean, callbackIfLast: Function): void {
|
public singleImage(key: string, path: string, callbackIfLast: Function): void {
|
||||||
var image = new Image();
|
var image = new Image();
|
||||||
|
|
||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
|
@ -1064,7 +1064,7 @@ export default class ResourceManager {
|
||||||
image.src = path;
|
image.src = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public loadSingleAudio(key: string, path: string, callbackIfLast: Function): void {
|
public singleAudio(key: string, path: string, callbackIfLast: Function): void {
|
||||||
let audioCtx = AudioManager.getInstance().getAudioContext();
|
let audioCtx = AudioManager.getInstance().getAudioContext();
|
||||||
|
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest();
|
||||||
|
|
|
@ -7,6 +7,7 @@ import Color from "../../Wolfie2D/Utils/Color";
|
||||||
import Layer from "../../Wolfie2D/Scene/Layer";
|
import Layer from "../../Wolfie2D/Scene/Layer";
|
||||||
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
import Sprite from "../../Wolfie2D/Nodes/Sprites/Sprite";
|
||||||
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
import { GameEventType } from "../../Wolfie2D/Events/GameEventType";
|
||||||
|
import Input from "../../Wolfie2D/Input/Input";
|
||||||
|
|
||||||
enum Mode {
|
enum Mode {
|
||||||
GAME_MODE = "GameMode",
|
GAME_MODE = "GameMode",
|
||||||
|
@ -18,7 +19,7 @@ export default class SceneWithStory extends Scene {
|
||||||
private currentMode: Mode = Mode.GAME_MODE;
|
private currentMode: Mode = Mode.GAME_MODE;
|
||||||
private storytextLabel: Label;
|
private storytextLabel: Label;
|
||||||
private storyLayer: Layer;
|
private storyLayer: Layer;
|
||||||
// private primary: Layer;
|
private primary: Layer;
|
||||||
private story: Story;
|
private story: Story;
|
||||||
private storyProgress: number;
|
private storyProgress: number;
|
||||||
private storySprites: Array<Sprite>;
|
private storySprites: Array<Sprite>;
|
||||||
|
@ -27,22 +28,22 @@ export default class SceneWithStory extends Scene {
|
||||||
private currentContent: string;
|
private currentContent: string;
|
||||||
|
|
||||||
startScene(): void {
|
startScene(): void {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The code below are for testing only. Please comment them when submit
|
// The code below are for testing only. Please comment them when submit
|
||||||
|
|
||||||
// this.primary = this.addUILayer("primary");
|
this.primary = this.addUILayer("primary");
|
||||||
// const center = this.viewport.getCenter();
|
const center = this.viewport.getCenter();
|
||||||
// const loadStory = this.add.uiElement(UIElementType.BUTTON, "primary", { position: new Vec2(center.x, center.y), text: "LoadStory" });
|
const loadStory = this.add.uiElement(UIElementType.BUTTON, "primary", { position: new Vec2(center.x, center.y), text: "LoadStory" });
|
||||||
// loadStory.size.set(200, 50);
|
loadStory.size.set(200, 50);
|
||||||
// loadStory.borderWidth = 2;
|
loadStory.borderWidth = 2;
|
||||||
// loadStory.borderColor = Color.WHITE;
|
loadStory.borderColor = Color.WHITE;
|
||||||
// loadStory.backgroundColor = Color.TRANSPARENT;
|
loadStory.backgroundColor = Color.TRANSPARENT;
|
||||||
// loadStory.onClickEventId = "loadStory";
|
loadStory.onClickEventId = "loadStory";
|
||||||
|
|
||||||
|
|
||||||
// this.receiver.subscribe("loadStory");
|
this.receiver.subscribe("loadStory");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,12 +59,15 @@ export default class SceneWithStory extends Scene {
|
||||||
if (this.story.bgm) {
|
if (this.story.bgm) {
|
||||||
this.storyBGMs = new Array;
|
this.storyBGMs = new Array;
|
||||||
this.story.bgm.forEach((bgm) => {
|
this.story.bgm.forEach((bgm) => {
|
||||||
this.load.audio(bgm.key, bgm.path);
|
// this.load.audio(bgm.key, bgm.path);
|
||||||
console.log("audio:", bgm.key, "path:", bgm.path);
|
// console.log("audio:", bgm.key, "path:", bgm.path);
|
||||||
this.load.loadResourcesFromQueue(() => {
|
// this.load.loadResourcesFromQueue(() => {
|
||||||
console.log("finished loading audio");
|
// console.log("finished loading audio");
|
||||||
|
// this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
||||||
|
// });
|
||||||
|
this.load.singleAudio(bgm.key, bgm.path, () => {
|
||||||
this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
this.emitter.fireEvent(GameEventType.PLAY_SOUND, { key: bgm.key, loop: false, holdReference: true });
|
||||||
});
|
})
|
||||||
this.storyBGMs.push(bgm.key);
|
this.storyBGMs.push(bgm.key);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -99,13 +103,19 @@ export default class SceneWithStory extends Scene {
|
||||||
this.story.texts[this.storyProgress].actions.forEach(action => {
|
this.story.texts[this.storyProgress].actions.forEach(action => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "loadSprite":
|
case "loadSprite":
|
||||||
this.load.image(action.key, action.path);
|
// this.load.image(action.key, action.path);
|
||||||
this.load.loadResourcesFromQueue(() => {
|
// this.load.loadResourcesFromQueue(() => {
|
||||||
|
// tmp = this.add.sprite(action.key, "story");
|
||||||
|
// tmp.position.set(action.positon[0], action.positon[1]);
|
||||||
|
// tmp.scale.set(action.scale[0], action.scale[1]);
|
||||||
|
// this.storySprites.push(tmp);
|
||||||
|
// });
|
||||||
|
this.load.singleImage(action.key, action.path, () => {
|
||||||
tmp = this.add.sprite(action.key, "story");
|
tmp = this.add.sprite(action.key, "story");
|
||||||
tmp.position.set(action.positon[0], action.positon[1]);
|
tmp.position.set(action.positon[0], action.positon[1]);
|
||||||
tmp.scale.set(action.scale[0], action.scale[1]);
|
tmp.scale.set(action.scale[0], action.scale[1]);
|
||||||
this.storySprites.push(tmp);
|
this.storySprites.push(tmp);
|
||||||
});
|
})
|
||||||
break;
|
break;
|
||||||
case "loadAnimatedSprite":
|
case "loadAnimatedSprite":
|
||||||
this.load.spritesheet(action.key, action.path);
|
this.load.spritesheet(action.key, action.path);
|
||||||
|
@ -173,13 +183,13 @@ export default class SceneWithStory extends Scene {
|
||||||
while (this.receiver.hasNextEvent()) {
|
while (this.receiver.hasNextEvent()) {
|
||||||
let event = this.receiver.getNextEvent();
|
let event = this.receiver.getNextEvent();
|
||||||
// Testing code
|
// Testing code
|
||||||
// if (event.type === "loadStory" && this.currentMode === Mode.GAME_MODE) {
|
if (event.type === "loadStory" && this.currentMode === Mode.GAME_MODE) {
|
||||||
// this.storyLoader("shattered_sword_assets/jsons/samplestory.json");
|
this.storyLoader("shattered_sword_assets/jsons/samplestory.json");
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
// Testing code
|
// Testing code
|
||||||
// if (Input.isMouseJustPressed() && this.currentMode === Mode.STORY_MODE) {
|
if (Input.isMouseJustPressed() && this.currentMode === Mode.STORY_MODE) {
|
||||||
// this.updateStory();
|
this.updateStory();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user