game-engine/modules/game-objects/sprite.js

30 lines
736 B
JavaScript

import { GameObject } from "./game-object.js";
export class Sprite extends GameObject {
constructor({ image, x = 0, y = 0, width = 0, height = 0, index = 0 }) {
super({ x, y, height, width });
this.index = index;
this.image = image;
this.imageWidth = this.image.width;
this.imageHeight = this.image.height;
}
render(ctx, destinationX, destinationY) {
ctx.drawImage(
this.image,
this.x,
this.y,
this.width,
this.height,
destinationX,
destinationY,
this.width,
this.height
);
if (this.debug) {
ctx.fillStyle = "Red";
ctx.font = "normal 8pt Pixelify Sans";
ctx.fillText(this.index, destinationX, destinationY + 8);
}
}
}