Psuedo code for movement
This commit is contained in:
@ -35,6 +35,7 @@ let pointerUpTimer: number | null = null
|
||||
|
||||
const DRAG_DELAY = 150
|
||||
const MOVE_RESET_DELAY = 100
|
||||
const CAMERA_SPEED = 4 // Adjust this value to change arrow key movement speed
|
||||
|
||||
function updateWaypoint(pointer: Phaser.Input.Pointer) {
|
||||
const { x: px, y: py } = scene.cameras.main.getWorldPoint(pointer.x, pointer.y)
|
||||
@ -94,11 +95,37 @@ function onPointerUp() {
|
||||
}, MOVE_RESET_DELAY)
|
||||
}
|
||||
|
||||
function handleKeyboardInput() {
|
||||
const cursors = scene.input.keyboard?.createCursorKeys()
|
||||
|
||||
if (!cursors) return
|
||||
|
||||
if (cursors.left.isDown) {
|
||||
cam.value.scrollX -= CAMERA_SPEED
|
||||
}
|
||||
if (cursors.right.isDown) {
|
||||
cam.value.scrollX += CAMERA_SPEED
|
||||
}
|
||||
if (cursors.up.isDown) {
|
||||
cam.value.scrollY -= CAMERA_SPEED
|
||||
}
|
||||
if (cursors.down.isDown) {
|
||||
cam.value.scrollY += CAMERA_SPEED
|
||||
}
|
||||
|
||||
if (cursors.left.isDown || cursors.right.isDown || cursors.up.isDown || cursors.down.isDown) {
|
||||
gameStore.setMovingCamera(true)
|
||||
} else {
|
||||
gameStore.setMovingCamera(false)
|
||||
}
|
||||
}
|
||||
|
||||
function setupEventListeners() {
|
||||
scene.input.on(Phaser.Input.Events.POINTER_MOVE, updateWaypoint)
|
||||
scene.input.on(Phaser.Input.Events.POINTER_WHEEL, handleZoom)
|
||||
scene.input.on(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
||||
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerUp)
|
||||
scene.events.on(Phaser.Scenes.Events.UPDATE, handleKeyboardInput)
|
||||
}
|
||||
|
||||
function cleanupEventListeners() {
|
||||
@ -107,6 +134,7 @@ function cleanupEventListeners() {
|
||||
scene.input.off(Phaser.Input.Events.POINTER_DOWN, onPointerDown)
|
||||
scene.input.off(Phaser.Input.Events.POINTER_UP, onPointerUp)
|
||||
scene.input.off(Phaser.Input.Events.POINTER_WHEEL, handleZoom)
|
||||
scene.events.off(Phaser.Scenes.Events.UPDATE, handleKeyboardInput)
|
||||
|
||||
if (pointerDownTimer) {
|
||||
clearTimeout(pointerDownTimer)
|
||||
@ -118,8 +146,6 @@ function cleanupEventListeners() {
|
||||
}
|
||||
}
|
||||
|
||||
setupEventListeners()
|
||||
|
||||
watch(tool, (newTool) => {
|
||||
if (newTool === 'move') {
|
||||
scene.input.on(Phaser.Input.Events.POINTER_MOVE, dragZone)
|
||||
@ -128,5 +154,6 @@ watch(tool, (newTool) => {
|
||||
}
|
||||
})
|
||||
|
||||
setupEventListeners()
|
||||
onBeforeUnmount(cleanupEventListeners)
|
||||
</script>
|
||||
</script>
|
Reference in New Issue
Block a user