feat: Adding bleed option to SpriteBatch#3871
Draft
erickzanardo wants to merge 8 commits intomainfrom
Draft
Conversation
wolfenrain
reviewed
Mar 23, 2026
wolfenrain
reviewed
Mar 23, 2026
Comment on lines
+325
to
+327
| if (bleed == 0) { | ||
| return transform; | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| if (bleed == 0) { | |
| return transform; | |
| } | |
| if (bleed <= 0) { | |
| return transform; | |
| } |
wolfenrain
reviewed
Mar 23, 2026
Comment on lines
+334
to
+335
| final scos = transform.scos * scaleX; | ||
| final ssin = transform.ssin * scaleY; |
Contributor
There was a problem hiding this comment.
We should not scale by x or y but by math.max of either so we can preserve rotation (and ensure scale happens uniformly even if width and height are not equal).
And then the tx and ty should be multiplied by the scos and ssin (subtract for tx, addition for ty). That should keep the centerr fixed to bleed across the borders when we are dealing with rotation
Member
|
Any update on this @erickzanardo ? |
…ng path Bleed was only applied via _computeBleedTransform for the drawAtlas path. The non-atlas (web fallback) path used batchItem.destination which was always set to Offset.zero & source.size, ignoring bleed entirely. Now BatchItem expands its destination rect by the bleed amount in each direction when bleed > 0, so drawImageRect in the fallback path also renders the sprite slightly larger to prevent edge seams. The replace() method is updated to recalculate destination when the source changes.
- Zero-size source guard in _computeBleedTransform to prevent Infinity/NaN - Convert BatchItem.matrix lazy field to nullable+getter so replace() can invalidate it when source or transform changes, fixing stale matrix bug in the non-atlas render path - Use original source rect (not bleed-expanded destination) for the background color drawRect in the non-atlas path, matching atlas path behaviour - Fix wording of transform/rotation comment in _computeBleedTransform - Document the non-square uniform-scale trade-off in bleed docstrings - Document that bleed cannot be changed via replace() - Add tests: negative bleed assertion, non-square atlas scale behaviour, non-square non-atlas exact expansion, zero-size source guard, matrix invalidation after replace(transform) and replace(source) - Add CHANGELOG entry - Fill in PR description and checklist - Fix trailing whitespace in example description string
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
bleedparameter toSpriteBatch.add()andSpriteBatch.addTransform()that slightly expands the rendered sprite beyond its source boundaries in all directions. This prevents seam artifacts (visible lines between tiles) that appear when texture filtering samples neighbouring pixels at tile edges in tilemaps.How it works
useAtlas = true, default): applies a uniform scale to theRSTransformvia_computeBleedTransform, keeping the sprite centre fixed in world space. A uniform scale usingmax(bleedScaleX, bleedScaleY)is used to preserve rotation; for non-square source rects the shorter axis is scaled slightly beyond the requestedbleedvalue.useAtlas = false/ web fallback): expandsBatchItem.destinationbybleedpixels in every direction. This always expands by exactlybleedpixels on every side, regardless of aspect ratio.For best results, the atlas should include padding between sprites.
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Addresses seam/ghost-line artifacts commonly reported when using
SpriteBatchfor tilemaps.