You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: NineTileBox draws tiles when Sprite's src does not cover the whole image - #4233
Canvas.drawImageNine() always uses the whole image as its source, so sprites with an offset or smaller than the image rendered the wrong region.
Draw the nine tiles with Canvas.drawImageRect() from sprite.src when the sprite does not cover the full image, and keep Canvas.drawImageNine() for full-image sprites.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Small destinations cause the nine-tile fallback to draw corners outside the destination and invert center rectangles, requiring border scaling and a regression test.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Changing the source region on a same-sized NineTileBoxWidget can leave stale content visible because shouldRepaint always returns false; visual-input comparisons and a region-only update regression test are needed.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The atlas fallback can bleed neighboring pixels when filtering is enabled and produce anti-aliased seams at fractional positions, causing rendering differences from the native nine-patch path.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Antialiased fallback draws can leave seams between tiles
packages/flame/lib/src/nine_tile_box.dart:185
With the default anti-aliased paint, independently drawn tiles can leave background-colored seams where shared edges fall between pixels. Flutter's paint flags apply anti-aliasing to drawImageRect but not drawImageNine (default-branch commit e736af5). Pass a paint copy with isAntiAlias = false to the fallback without mutating the caller's paint, and add a fractional-position golden test.
Filtered atlas draws sample neighboring pixels at sprite edges
packages/flame/lib/src/nine_tile_box.dart:230
With overridePaint.filterQuality = FilterQuality.low and 2× magnification, these draws can blend neighboring atlas pixels into the box's outer edges. drawImageRect permits sampling outside src, whereas Impeller's native nine-patch renderer clamps each tile with kStrict (Flutter default-branch commit e736af5). Thus the atlas and full-image paths still render differently when filtering is enabled. Please preserve clamped sampling—for example, by caching an isolated sprite image and using drawImageNine—and add a filtered atlas golden with contrasting neighboring pixels.
The atlas fallback can bleed neighboring pixels when filtering is enabled and produce anti-aliased seams at fractional positions, causing rendering differences from the native nine-patch path.
No open issues 🎉 2 previously missed issues
1 resolved since last review
* <img alt="Medium severity" width="62" height="18" src="https://camo.githubusercontent.com/7dc8929f1372d7be218d83fe61e6c3fb67ed8bc61cd50c1e8e4696827da90595/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f7374617469632f696d616765732f69636f6e732f636f70696c6f742d636f64652d7265766965772f6d656469756d2d76322d6c696768742e706e67"> [Repaint when the nine-tile source region changes](https://github.com/flame-engine/flame/pull/4233#discussion_r4608540799)
Review effort: Balanced
When using overridePaint with Paint.filterQuality enabled (other than .none), the seams between tiles bleed or blend with neighboring tiles, which differs from the behavior of the original Canvas.drawImageNine().
When filterQuality = .low, Canvas.drawImageNine() vs. _drawTiles():
I intend not to handle this case, as I currently don't have a good solution in mind.
A possible solution is to crop and cache the sprite from the source image, then use Canvas.drawImageNine() throughout. However, this places the burden on the consumer to call dispose() to free the resource. Also, it potentially breaks sprite batching, though I haven't verified this.
@NagaChiang since the most common use-case is to use the whole image, this PR becomes a regression to current behavior right? We can't have that. Also even if you would fix it by cutting up the image manually, the performance would be worse. So I'm leaning to keeping it the way it is now and just document the behaviorinstead.
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
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
Canvas.drawImageNine()always uses the whole image as its source, so sprites with an offset or smaller than the image rendered the wrong region.Draw the nine tiles with
Canvas.drawImageRect()fromsprite.srcwhen the sprite does not cover the full image, and keepCanvas.drawImageNine()for full-image sprites.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Fixes #4232