-
I am using the Parcel template to create an excalibur game. I am loading sounds, and this works, but the browser gives a whole lot of warnings before the game even starts (during loading of the assets):
After clicking the "play game" button, the sound is working, but I wonder how I can prevent these warnings? Resources.ts import { ImageSource, Sound } from "excalibur"
import crate from "../images/crate.png"
import coinsound from "url:../sound/coin.mp3" // needs url: otherwise sounds are not imported
let Resources = {
Crate: new ImageSource(crate),
CoinSound: new Sound(coinsound)
}
export { Resources } Game.ts import { Actor, Color, DisplayMode, Engine, Loader, Vector, Physics, Sound } from "excalibur"
import { Resources } from "./resources"
class Game extends Engine {
constructor() {
super({ width: 800, height: 600 })
const loader = new Loader([
Resources.Crate,
Resources.CoinSound
])
this.start(loader).then(() => this.startGame())
}
startGame(){
Resources.CoinSound.play()
}
}
new Game() UPDATE I load the sound as a static file now, meaning the file won't be picked up by parcel. You have to copy it manually to the dist folder: let Resources = {
Crate: new ImageSource(crate),
CoinSound: new Sound("./coin.mp3")
} Now I only get the following warning. It seems excalibur attempts to play the sound while loading?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@KokoDoko I think this is a bug in the parsing, it must be getting confused by the If you are using the play button this should not show up, this also seems like a bug.. Thanks for bringing this up! |
Beta Was this translation helpful? Give feedback.
@KokoDoko I think this is a bug in the parsing, it must be getting confused by the
coin.f74d9d70.mp3
. The audio does still play correct? I'll make a bug for this.If you are using the play button this should not show up, this also seems like a bug..
Decorators.ts:82 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
Thanks for bringing this up!