remove canvas requirement for camera
This commit is contained in:
parent
f5f08be505
commit
34c58dcd71
2 changed files with 5 additions and 22 deletions
|
|
@ -1,28 +1,14 @@
|
|||
export default class Camera {
|
||||
constructor(canvas) {
|
||||
constructor() {
|
||||
this.x = 0
|
||||
this.y = 0
|
||||
|
||||
// TODO: when canvas resizes, this should
|
||||
// syncronize with the cam
|
||||
this.width = canvas.width
|
||||
this.height = canvas.height
|
||||
|
||||
this.zoom = 1
|
||||
this.minZoom = .1
|
||||
this.maxZoom = 6
|
||||
this.zoomStep = .05
|
||||
}
|
||||
|
||||
rect() {
|
||||
return {
|
||||
x: -this.x,
|
||||
y: -this.y,
|
||||
w: this.width / this.zoom,
|
||||
h: this.height / this.zoom,
|
||||
}
|
||||
}
|
||||
|
||||
move(x, y) {
|
||||
this.x += x / this.zoom
|
||||
this.y += y / this.zoom
|
||||
|
|
@ -34,10 +20,7 @@ export default class Camera {
|
|||
return false
|
||||
}
|
||||
|
||||
const zoomToCoord = viewportCoordCenter || {
|
||||
x: this.width / 2,
|
||||
y: this.height / 2
|
||||
}
|
||||
const zoomToCoord = viewportCoordCenter
|
||||
const zoomFactor = (1 / this.zoom) - (1 / zoom)
|
||||
|
||||
this.x -= Math.round(zoomToCoord.x * zoomFactor)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue