diff --git a/src/routes/(game)/game/play/[sessionCode]/+page.svelte b/src/routes/(game)/game/play/[sessionCode]/+page.svelte index 50b681d..706e143 100644 --- a/src/routes/(game)/game/play/[sessionCode]/+page.svelte +++ b/src/routes/(game)/game/play/[sessionCode]/+page.svelte @@ -95,6 +95,9 @@ // If we have device heading, rotate relative to it; otherwise just use absolute bearing arrowRotation = heading !== null ? bearing - heading : bearing; + } else { + distance = null; + arrowRotation = 0; } }); @@ -218,6 +221,11 @@ } } + function startAllTracking() { + startLocationTracking(); + void startOrientationTracking(); + } + function stopLocationTracking() { if (watchId !== null) { navigator.geolocation.clearWatch(watchId); @@ -231,8 +239,7 @@ onMount(() => { if (currentStep?.type === 'location' && isCurrentActiveStep) { checkLocationPermission().then(() => { - startLocationTracking(); - startOrientationTracking(); + startAllTracking(); }); } @@ -241,6 +248,17 @@ }; }); + // If step data arrives after mount, start/stop tracking reactively. + $effect(() => { + if (currentStep?.type === 'location' && isCurrentActiveStep) { + if (watchId === null) { + startAllTracking(); + } + } else if (watchId !== null) { + stopLocationTracking(); + } + }); + function handleOrientation(event: Event) { const e = event as DeviceOrientationEvent; if (e.absolute && e.alpha !== null) { @@ -412,7 +430,7 @@