1
0
forked from noxious/client

npm run format, started working on follow player logic, refactor some camera logic

This commit is contained in:
2024-09-22 02:14:32 +02:00
parent 42291b93eb
commit 9b592d6c7c
14 changed files with 101 additions and 111 deletions

View File

@ -3,35 +3,22 @@ import { useGameStore } from '@/stores/gameStore'
export function useCameraControls(scene: Phaser.Scene): any {
const gameStore = useGameStore()
const camera = ref(scene.cameras.main)
const isDragging = ref(false)
// Resize center camera on character.
window.addEventListener('resize', () => {
console.log('woep')
// Need to change camera position next frame
setTimeout(() => {
scene.cameras.main.setScroll(-(scene.cameras.main.worldView.width/2) + gameStore.character.relativePosition.x, -(scene.cameras.main.worldView.height/2) + gameStore.character.relativePosition.y)
}, 0)
})
const camera = scene.cameras.main
function onPointerDown(pointer: Phaser.Input.Pointer) {
if (pointer.event instanceof MouseEvent || pointer.event.shiftKey) {
isDragging.value = true
gameStore.setMovingCamera(true)
gameStore.setPlayerDraggingCamera(true)
}
}
function onPointerUp() {
isDragging.value = false
gameStore.setMovingCamera(false)
gameStore.setPlayerDraggingCamera(false)
}
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerUp)
return {
camera,
isDragging
camera
}
}