Option to always redraw individual sprites

I'd love the option to set a flag on an individual sprite to force it to always redraw. This would mirror the global sprite.setAlwaysRedraw(flag) with a sprite:setAlwaysRedraw(flag).

My use case is a simple stopwatch sprite. It only needs to draw when the timer isn't paused. I could avoid the need for an update function to mark it dirty every frame and keep the logic entirely internal to the class if I could just toggle an always redraw flag for the sprite when pausing/unpausing the timer.

For example:

function Stopwatch:start()
    self.timer:start()
    self:setAlwaysRedraw(true)
end

function Stopwatch:pause()
    self.timer:pause()
    self:setAlwaysRedraw(false)
    self:markDirty() -- draw one last frame to make sure the final time is drawn
end

function Stopwatch:draw()
    font:drawText(string.format("%05.2f", self:elapsedTime() / 1000):gsub("%.", ":"), 0, 0)
end
2 Likes

I'm reminded (:man_facepalming:) that update is called automatically on all sprites, which means that I can accomplish the same result with:

function Stopwatch:update()
    if not self.timer.paused then
        self:markDirty()
    end
end

I suppose there's still something to be said for the parity having the sprite-specific version would provide, although the benefit is minimal so this is pretty low priority.

2 Likes