Created
September 8, 2022 06:15
-
-
Save RenaudRohlinger/02909775cedc192f2c602b94e6806f0a to your computer and use it in GitHub Desktop.
Synchronize gsap and r3f raf loop
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
import React, { useEffect } from 'react' | |
import gsap from 'gsap' | |
import { useFrame } from '@react-three/fiber' | |
// sync gsap raf to r3f raf | |
gsap.ticker.remove(gsap.updateRoot) | |
export const GsapTicker = () => { | |
const pg = React.useRef(0) | |
gsap.ticker.remove(gsap.updateRoot) | |
useFrame((_, delta) => { | |
pg.current += delta | |
gsap.updateRoot(pg.current) | |
}) | |
useEffect(() => { | |
return () => { | |
gsap.ticker.remove(gsap.updateRoot) | |
} | |
}) | |
return null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment