Skip to content

fix: round up framesH and framesV calc to solve visual shake in SpriteAnimator#1876

Merged
netgfx merged 1 commit intopmndrs:masterfrom
juniorxsound:fix/sprite-animator-precision
Mar 16, 2024
Merged

fix: round up framesH and framesV calc to solve visual shake in SpriteAnimator#1876
netgfx merged 1 commit intopmndrs:masterfrom
juniorxsound:fix/sprite-animator-precision

Conversation

@juniorxsound
Copy link
Contributor

@juniorxsound juniorxsound commented Mar 16, 2024

(👋 first time contributor here, just wanted to say thank you for all your work)

Why

Using SpriteAnimator (most noticeable with large) spritesheets sometimes results in sprite shaking. Looked at why that happens (at first was thinking sprite texture filtering...etc) it seems the framesH and framesV calculations have small precision issues which result in visual shake in the sprite as it's playing (since it's use to calculate the texture offsets). Simply rounding them solves the visual shake .

Here is a small Codesandbox reproduction of the issue (Sandbox / Demo)

And here is a quick sandbox implementing the fix (Sandbox / Demo)

What

  • Wrap the framesH and framesV in Math.round (since they can be suffer from decimal precision instability which makes the sprite shake)

Checklist

  • Ready to be merged

@vercel
Copy link

vercel bot commented Mar 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drei ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 16, 2024 1:39am

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@netgfx
Copy link
Contributor

netgfx commented Mar 16, 2024

@juniorxsound thank you for your contribution!

@netgfx netgfx merged commit 8d3be59 into pmndrs:master Mar 16, 2024
@github-actions
Copy link

🎉 This PR is included in version 9.102.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@juniorxsound juniorxsound deleted the fix/sprite-animator-precision branch March 23, 2024 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants