tilegame/src/viewport.js

24 lines
401 B
JavaScript

import { canvas } from './canvas'
class Viewport {
constructor (x, y, scale = 1) {
this.x = x
this.y = y
this.scale = scale
}
get width () {
return canvas.width
}
get height () {
return canvas.height
}
chunkIn (size) {
return { x: Math.floor((this.x + this.width / 2) / size), y: Math.floor((this.y + this.height / 2) / size) }
}
}
export default Viewport