mirror of
https://github.com/artiemis/artie.moe.git
synced 2026-02-14 09:01:55 +00:00
press and hold for audio interaction
This commit is contained in:
parent
a51b6a6946
commit
29a70525da
@ -19,11 +19,12 @@
|
|||||||
|
|
||||||
let canvas = $state<HTMLCanvasElement>();
|
let canvas = $state<HTMLCanvasElement>();
|
||||||
let isLoaded = $state(false);
|
let isLoaded = $state(false);
|
||||||
|
let holdTimeout = $state<number>();
|
||||||
|
|
||||||
let audio = $state<HTMLAudioElement>();
|
let audio = $state<HTMLAudioElement>();
|
||||||
let volume = $state(50);
|
let volume = $state(50);
|
||||||
let volumeLabel = $state<string>();
|
let volumeLabel = $state<string>();
|
||||||
let volumeLabelTimeout = $state<ReturnType<typeof setTimeout>>();
|
let volumeLabelTimeout = $state<number>();
|
||||||
|
|
||||||
let app: PIXI.Application;
|
let app: PIXI.Application;
|
||||||
let model: Live2DModel;
|
let model: Live2DModel;
|
||||||
@ -75,7 +76,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleModelDoubleClick() {
|
function handleMouseDown() {
|
||||||
|
model.motion("Tap");
|
||||||
|
|
||||||
|
holdTimeout = window.setTimeout(() => {
|
||||||
|
if (holdTimeout) {
|
||||||
|
handleAudioInteraction();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMouseUp() {
|
||||||
|
clearTimeout(holdTimeout);
|
||||||
|
holdTimeout = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAudioInteraction() {
|
||||||
if (!audio && isLoaded) {
|
if (!audio && isLoaded) {
|
||||||
showVolumeLabel();
|
showVolumeLabel();
|
||||||
audio = new Audio(audioSrc);
|
audio = new Audio(audioSrc);
|
||||||
@ -96,7 +112,10 @@
|
|||||||
function showVolumeLabel() {
|
function showVolumeLabel() {
|
||||||
volumeLabel = `${volume}%`;
|
volumeLabel = `${volume}%`;
|
||||||
clearTimeout(volumeLabelTimeout);
|
clearTimeout(volumeLabelTimeout);
|
||||||
volumeLabelTimeout = setTimeout(() => (volumeLabel = undefined), 1000);
|
volumeLabelTimeout = window.setTimeout(
|
||||||
|
() => (volumeLabel = undefined),
|
||||||
|
1000
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
@ -168,9 +187,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<canvas
|
<canvas
|
||||||
bind:this={canvas}
|
bind:this={canvas}
|
||||||
ondblclick={handleModelDoubleClick}
|
onmousedown={handleMouseDown}
|
||||||
|
onmouseup={handleMouseUp}
|
||||||
id="live2d"
|
id="live2d"
|
||||||
onpointerdown={() => model.motion("Tap")}
|
|
||||||
class="lg:w-96 w-44 transition-opacity {isLoaded
|
class="lg:w-96 w-44 transition-opacity {isLoaded
|
||||||
? 'opacity-1'
|
? 'opacity-1'
|
||||||
: 'opacity-0'}"
|
: 'opacity-0'}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user