Patterns

Resource Loading

// Because snippets uses a bunder we load the image with an import
import playerUrl from './player.png';

// If you aren't using a bundler like parcel or webpack you can do this:
// const imagePlayer = new ex.ImageSource('./player.png')
const Resources = {
    ImagePlayer: new ex.ImageSource(playerUrl),
    //... more resources
}

const loader = new ex.Loader([...Object.values(Resources)]);

class Player extends ex.Actor {
    public onInitialize(engine: ex.Engine) {
        // set as the "default" drawing
        this.graphics.use(Resources.ImagePlayer.toSprite());
    }
}