-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/punky-lab/punky-tma
- Loading branch information
Showing
26 changed files
with
229 additions
and
55 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import f01 from "./01.gif"; | ||
import f02 from "./02.gif"; | ||
import f03 from "./03.gif"; | ||
import f04 from "./04.gif"; | ||
|
||
const frames = [f01, f02, f03, f04]; | ||
|
||
export default frames; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import f01 from "./01.gif"; | ||
import f02 from "./02.gif"; | ||
import f03 from "./03.gif"; | ||
import f04 from "./04.gif"; | ||
|
||
const frames = [f01, f02, f03, f04]; | ||
|
||
export default frames; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import f01 from "./01.gif"; | ||
import f02 from "./02.gif"; | ||
import f03 from "./03.gif"; | ||
import f04 from "./04.gif"; | ||
|
||
const frames = [f01, f02, f03, f04]; | ||
|
||
export default frames; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import Image from "next/image"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import ThinkingBubble from "./thinkingBubble"; | ||
|
||
interface FramesProps { | ||
frames: { src: string }[]; // frames 是包含 src 字段的对象数组 | ||
interval: number; // 动画帧切换间隔 | ||
width: number; // 图片宽度 | ||
height: number; // 图片高度 | ||
once?: boolean; | ||
onEnd?: () => void; | ||
} | ||
|
||
export default function Frames({ | ||
frames, | ||
interval, | ||
width, | ||
height, | ||
once, | ||
onEnd, | ||
}: FramesProps) { | ||
const [currentFrame, setCurrentFrame] = useState(0); // 当前帧索引 | ||
const preloadedImages = useRef<HTMLImageElement[]>([]); // 用于存储预加载的图像 | ||
const [imagesLoaded, setImagesLoaded] = useState(false); | ||
|
||
// 预加载图像 | ||
useEffect(() => { | ||
if (frames.length === 0) return; | ||
|
||
let loadedCount = 0; | ||
console.log("..frames..", frames); | ||
preloadedImages.current = frames.map((frame) => { | ||
const img = new window.Image(); | ||
img.src = frame.src; | ||
img.onload = () => { | ||
loadedCount++; | ||
if (loadedCount === frames.length) { | ||
setImagesLoaded(true); | ||
} | ||
}; | ||
return img; | ||
}); | ||
}, [frames]); | ||
|
||
// 使用定时器切换动画帧 | ||
useEffect(() => { | ||
if (!imagesLoaded) return; | ||
|
||
const timer = setInterval(() => { | ||
setCurrentFrame((prevFrame) => { | ||
if (once && prevFrame === frames.length - 1) { | ||
// If once is true and we're at the last frame, stay there | ||
clearInterval(timer); | ||
onEnd?.(); | ||
return prevFrame; | ||
} | ||
// Otherwise continue to next frame | ||
return (prevFrame + 1) % frames.length; | ||
}); | ||
}, interval); | ||
|
||
return () => clearInterval(timer); // 在组件卸载时清理定时器 | ||
}, [frames.length, interval, imagesLoaded, once, onEnd]); | ||
|
||
return ( | ||
<div style={{ width, height, position: "relative" }}> | ||
{preloadedImages.current.map((img, index) => ( | ||
<Image | ||
key={index} | ||
src={img.src} // 使用缓存的图像对象 | ||
alt={`frames-${index}`} | ||
width={width} | ||
height={height} | ||
unoptimized | ||
priority={index === 0} | ||
style={{ | ||
position: "absolute", | ||
top: 0, | ||
left: 0, | ||
opacity: index === currentFrame ? 1 : 0, | ||
}} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.