forked from noxious/client
Minor camera improvements
This commit is contained in:
parent
80bb38a6f7
commit
cd9316a384
@ -23,10 +23,16 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
|
|||||||
function dragZone(pointer: Phaser.Input.Pointer) {
|
function dragZone(pointer: Phaser.Input.Pointer) {
|
||||||
if (!gameStore.isPlayerDraggingCamera) return
|
if (!gameStore.isPlayerDraggingCamera) return
|
||||||
|
|
||||||
|
// Check if action is actually a drag by checking if the pointer has moved
|
||||||
|
if (pointer.prevPosition.x === pointer.x && pointer.prevPosition.y === pointer.y) return
|
||||||
|
|
||||||
const { x, y, prevPosition } = pointer
|
const { x, y, prevPosition } = pointer
|
||||||
const { scrollX, scrollY, zoom } = camera
|
const { scrollX, scrollY, zoom } = camera
|
||||||
camera.setScroll(scrollX - (x - prevPosition.x) / zoom, scrollY - (y - prevPosition.y) / zoom)
|
camera.setScroll(scrollX - (x - prevPosition.x) / zoom, scrollY - (y - prevPosition.y) / zoom)
|
||||||
|
|
||||||
|
// Check if camera has moved if not return
|
||||||
|
if (camera.scrollX === scrollX && camera.scrollY === scrollY) return
|
||||||
|
|
||||||
lastDragTime.value = Date.now()
|
lastDragTime.value = Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +63,7 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
|
|||||||
|
|
||||||
const deltaY = pointer.event.deltaY
|
const deltaY = pointer.event.deltaY
|
||||||
let zoomLevel = camera.zoom - deltaY * 0.005
|
let zoomLevel = camera.zoom - deltaY * 0.005
|
||||||
if(zoomLevel <= 0 || zoomLevel >= 3) return
|
if(zoomLevel <= 1 || zoomLevel >= 3) return
|
||||||
camera.setZoom(zoomLevel)
|
camera.setZoom(zoomLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,10 +8,12 @@ export function useCameraControls(scene: Phaser.Scene): any {
|
|||||||
const camera = scene.cameras.main
|
const camera = scene.cameras.main
|
||||||
|
|
||||||
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
function onPointerDown(pointer: Phaser.Input.Pointer) {
|
||||||
|
if (gameStore.isPlayerDraggingCamera) return
|
||||||
gameStore.setPlayerDraggingCamera(true)
|
gameStore.setPlayerDraggingCamera(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPointerUp() {
|
function onPointerUp() {
|
||||||
|
if (!gameStore.isPlayerDraggingCamera) return
|
||||||
gameStore.setPlayerDraggingCamera(false)
|
gameStore.setPlayerDraggingCamera(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user