Skip to content

Commit

Permalink
feature: player trails now erase
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlumsden authored and shuji-koike committed Feb 22, 2024
1 parent ded9c9c commit 1a046ec
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/app/demo/FrameView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,22 @@ export const FramePlayer: React.FC<{ player: Player }> = ({ player }) => {
}

export const TrailView: React.FC = () => {
const frame = useMatch((state) => state.frame)
const round = useMatch((state) => state.round)
const ref = React.useRef<HTMLCanvasElement>(null)
React.useEffect(() => {
const context = ref.current?.getContext?.("2d")
if (context) {
context.clearRect(0, 0, 1024, 1024)
round?.Frames.forEach((e) => {
const from = frame ? round?.Frames.indexOf(frame) : 0
round?.Frames.slice(from)?.forEach((e) => {
for (const player of e.Players) {
context.fillStyle = teamColor(player.Team)
context.fillRect(player.X, player.Y, 1, 1)
}
})
}
}, [round])
}, [frame, round])
if (isSafari) return // ref https://bugs.webkit.org/show_bug.cgi?id=23113
return (
<foreignObject x={0} y={0} width={1024} height={1024}>
Expand Down

0 comments on commit 1a046ec

Please sign in to comment.