playdate.graphics.sprite.markDirty([rect])

Request for an optional parameter to sprite.markDirty() to specify the rect in sprite coordinates (ie 0,0 is the top left of the sprite) to mark dirty. Omitting the parameter means 'whole sprite' as it does now.

Motivation: the dirty rect passed into the draw() function of a sprite is in 'sprite' coordinates. If you have draw optimized sprites which do minimal updates by checking the dirty rect against some internal sprite relative rects you also will want to invalidate those rects to queue them up for redraw.
In the sprite you're always working in sprite-relative coordinates, so you really want a function ON the sprite which takes a aprite relative rect and invalidates it. Making that an optional parameter to markDirty() seems quite natural.

obviously all this really does is call gfx.sprite.addDirtyRect(rect:offsetBy(self.x, self.y):unpack())

but having it as a sprite method prevents you from forgetting to convert to screen coordinates every time you do this. I've had a couple of tricky to track down bugs forgetting this.

2 Likes