top-down-action-adventure/src/game.js

35 lines
647 B
JavaScript
Raw Normal View History

2025-06-01 15:30:12 -04:00
export default class Game {
constructor(canvas) {
this.canvas = canvas
this.ctx = canvas.getContext("2d")
2025-06-01 15:37:12 -04:00
this.timestamp = 0
}
start() {
requestAnimationFrame(this.loop.bind(this))
}
loop(timestamp) {
const dt = timestamp - this.timestamp
this.timestamp = timestamp
this.tick(dt)
this.draw()
requestAnimationFrame(this.loop.bind(this))
}
tick(dt) {
console.log(dt)
2025-06-01 15:30:12 -04:00
}
draw() {
const { canvas, ctx } = this
ctx.clearRect(0, 0, canvas.width, canvas.height)
ctx.beginPath()
ctx.fillColor = "#FF0000"
ctx.rect(200, 100, 80, 50)
ctx.fill()
ctx.closePath()
}
}