Skip to content

Commit

Permalink
Fix frame prop (#247)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Busby <[email protected]>
  • Loading branch information
jcblw and Will Busby authored Sep 19, 2021
1 parent 4f68201 commit 3b91f5f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/useSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useSprite = ({
reset,
scale = 1,
wrapAfter,
frame
}) => {
const prevTime = useRef()
const [currentFrame, setCurrentFrame] = useState(startFrame)
Expand Down Expand Up @@ -144,6 +145,12 @@ export const useSprite = ({
setCurrentFrame(startFrame)
}, [reset])

useEffect(() => {
if (typeof frame === 'number' && frame !== currentFrame) {
setCurrentFrame(frame)
}
}, [frame])

return {
backgroundImage: isLoaded ? `url(${sprite})` : null,
backgroundPosition: isLoaded ? getSpritePosition(currentFrame) : null,
Expand Down

0 comments on commit 3b91f5f

Please sign in to comment.