1
0
forked from noxious/client

Spawn anim bug fix

This commit is contained in:
Dennis Postma 2024-08-17 23:14:20 +02:00
parent 522b4958b5
commit 7064c7b7f3

View File

@ -47,11 +47,19 @@ const props = withDefaults(defineProps<Props>(), {
const currentX = ref(0)
const currentY = ref(0)
const tween = ref<Phaser.Tweens.Tween | null>(null)
const isInitialPosition = ref(true)
const updatePosition = (x: number, y: number) => {
const targetX = tileToWorldX(props.layer, x, y)
const targetY = tileToWorldY(props.layer, x, y)
if (isInitialPosition.value) {
currentX.value = targetX
currentY.value = targetY
isInitialPosition.value = false
return
}
if (tween.value && tween.value.isPlaying()) {
tween.value.stop()
}
@ -72,9 +80,11 @@ const updatePosition = (x: number, y: number) => {
})
}
watch(() => props.character, (newChar) => {
watch(() => props.character, (newChar, oldChar) => {
if (newChar) {
updatePosition(newChar.position_x, newChar.position_y)
if (!oldChar || newChar.position_x !== oldChar.position_x || newChar.position_y !== oldChar.position_y) {
updatePosition(newChar.position_x, newChar.position_y)
}
}
}, { immediate: true, deep: true })