Я пытаюсь загрузить изображения, которые будут использоваться в основном как монеты для моей игры в p5. Тем не менее, я не могу понять, как заставить их появиться. Частично проблема заключается в ошибке «e undefined» из p5.min. js, которая является моим нетронутым кодом p5. Что я делаю неправильно? Я просто не могу заставить их появляться на экране. Вот мой код (здесь монеты представлены как tp)
Я что-то упустил?
Из tp. js:
let tp
class Tp {
constructor(y, x) {
this.x = 500;
this.y = y;
this.width = 30
this.height = 30
this.tp = tp
}
preload() {
this.tp = loadImage("assets/tp.png");
}
draw() {
this.x -= 4;
image(this.img, this.x, this.y, this.width, this.height);
}
}
Из игры. js
let score = 0;
let gameEnd = false;
class Game {
constructor() {
this.background = new Background();
this.player = new Player();
this.tp = new Tp();
this.tps = [];
}
preload() {
this.background.preload();
this.player.preload();
}
setup() {
this.player.setup();
}
draw() {
this.background.draw();
this.player.draw();
if (frameCount % 60 === 0) {
let tp = new Tp();
tp.preload();
this.tps.push(new Tp ());
}
this.tps.forEach(
(tp, index) => {
tp.draw();
}
)
}
};