Why is my image width and height equal to 0? [duplicate]
Why is my image width and height equal to 0? [duplicate] This question already has an answer here: I am trying to make a infinite scrolling game in javascript. The following code works as expected (it doesn't work here because the images cannot be uploaded): class Vec { constructor(x = 0, y = 0) { this.x = x; this.y = y; } } class Rect { constructor(src) { this.pos = new Vec; this.vel = new Vec; this.image = new Image(); this.image.src = src; } get left() { return this.pos.x; } get right() { return this.pos.x + this.image.width; } get top() { return this.pos.y; } get bottom() { return this.pos.y + this.image.height; } } class Player extends Rect { constructor() { super("images/frog-still.png"); this.pos.x = 100; this.pos.y = HEIGHT - GROUND_Y - this.image.height; } } class Enemy extends Rect { constructor() { super("images/spike.png"); this.image.width = this.image.width / ...
