forked from noxious/client
npm run format, started working on follow player logic, refactor some camera logic
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user