tilegame/src/viewport.js

29 lines
520 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
}
get adjustCentered () {
return { x: Math.floor(this.x + this.width / 2), y: Math.floor(this.y + this.height / 2) }
}
chunkIn (size) {
let adj = this.adjustCentered
return { x: Math.floor(adj.x / size), y: Math.floor(adj.y / size) }
}
}
export default Viewport