【发布时间】:2016-09-08 17:19:48
【问题描述】:
谁能帮我解决 Phaser 声音问题?
我编写了一个带有在 TypeScript 中播放声音的功能的按钮,但是当我按下 chrome 上的按钮时,Phaser 在 chrome 控制台上给了我以下警告:
Phaser.Cache.getSound: Key "sample" not found in Cache.
一开始我以为按下按钮的时候mp3文件还没有完全加载,但是等了足够长的时间,情况还是一样……
export class PlayState extends Phaser.State {
private sampleSound: Phaser.Sound;
private testButton: Phaser.Sprite;
preload() {
this.load.image("test", "assets/image/test.png")
this.load.audio("sample", "assets/audio/sample.mp3");
}
create() {
// Add test button
this.testButton = this.add.sprite(50, 50, "test");
this.testButton.anchor.setTo(0.5);
this.testButton.inputEnabled = true;
this.testButton.events.onInputDown.add(this.test);
// Add audio
this.sampleSound = this.add.audio("sample");
}
private test = () => {
this.sampleSound.play();
}
}
我在assets/audio目录下肯定有sample.mp3文件,所以Phaser应该能找到。
【问题讨论】:
标签: typescript phaser-framework