Not sure if this is the right place for this, but since there is no help topic....
Making a simple game to learn Pixelbox.js, and I cant seem to render my enemy. Ive been trying for hours. Here is code to spawn enemy:
function spawnEnemy() { var enemy = { key: 152, x: random(128), y: random(128), width: 8, height: 8, followSpeed: 4, update: function () { this.x += (player.x - this.x) / (player.x - this.x) * this.followSpeed; this.y += (player.y - this.y) / (player.y - this.y) * this.followSpeed; } } enemies.push(enemy); }
"enemies" is an empty array. Then, in the update function, I call,
for (var i = 0; i < enemies.length; i++) { var e = enemies[i]; sprite(e.frame, e.x, e.y); }
For some reason, it doesnt show anything. Any idea why?
Edit: If it will help, here is my entire render function, which I call in update:
function render() {
cls();
draw(background, 0, 0);
sprite(Math.round(player.frame), player.x, player.y, player.isFacingLeft);
sprite(sword.frame, sword.x, sword.y);
for (var i = 0; i < enemies.length; i++) {
var e = enemies[i];
sprite(e.frame, e.x, e.y);
}
draw(foreground, 0, 0);
}