Для вывода спрайтов реализуем вспомогательный метод в классе Application:
res(key) {
return this.loader.resources[key].texture;
}
sprite(key) {
return new PIXI.Sprite(this.res(key));
}
Все загруженные ресурсы хранятся в свойстве resources нашего класса Loader. Получив нужный ресурс по ключу, можно создать экземпляр PIXI.Sprite. Теперь в коде игры достаточно вызвать App.sprite, чтобы получить нужный PIXI.Sprite и работать с ним. Выведем фоновое изображение:
export class Game {
constructor() {
this.container = new PIXI.Container();
this.createBackground();
}
createBackground() {
this.bg = App.sprite("bg");
this.bg.width = window.innerWidth;
this.bg.height = window.innerHeight;
this.container.addChild(this.bg);
}