Marking NobleSprite with animation dirty before drawing - #65
Conversation
Fixed NobleSprite animation drawing in cases, when Graphics.sprite.getAlwaysRedraw() == false
Mark sprite dirty last time in pause() and stop() methods before blocking updates.
✅ Deploy Preview for cheery-choux-736619 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Update scene before drawing sprites
Fix NobleSprite: Dont delete coords for sprites before adding
…waysRedraw=false
PR NobleRobot#65 swapped the order so scene:update() runs before Graphics.sprite.update(). This breaks scenes that draw UI elements (Noble.Menu, Noble.Text, manual image:draw) in their update() method, because sprite.update() redraws dirty regions on top, erasing the UI. The markDirty() fixes from PR NobleRobot#65 in NobleSprite work correctly without the order swap, since sprite:update() and sprite:draw() both run inside Graphics.sprite.update().
…stream PR NobleRobot#65, adapted) Adds a NobleSprite:update() method that calls markDirty() when the sprite has an animation, replacing the unreliable markDirty() call inside draw(). Also marks the sprite dirty in pause() and stop() so the final frame renders, and NobleSprite:add() now defaults to the sprite's current self.x/self.y instead of 0,0. Adapted from upstream PR NobleRobot#65: the Noble.lua hunk (reordering Graphics.sprite.update() after currentScene:update() in the game loop) was deliberately dropped, as it would break the documented pattern of drawing animations directly in a scene's update() method (see Noble.Animation:draw() docs). Co-authored-by: Igor Stepanov <stiv-iv@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Commit 75f4526 (upstream PR NobleRobot#65) moved the markDirty() call from NobleSprite:draw() to a new NobleSprite:update() method, so that pause() and stop() actually halt an animation. However, subclasses that define their own update() method (the documented pattern, per the Noble.Animation:setState usage example) shadow NobleSprite:update(), so the sprite is never re-marked dirty and its animation freezes after one frame when "Graphics.sprite.setAlwaysRedraw(false)" is set. Restore a fallback markDirty() in draw(), gated on updatesEnabled(), which preserves the pause()/stop() fix while keeping overridden update() methods working. Refs upstream PR NobleRobot#65. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…stream PR NobleRobot#65, adapted) Adds a NobleSprite:update() method that calls markDirty() when the sprite has an animation, replacing the unreliable markDirty() call inside draw(). Also marks the sprite dirty in pause() and stop() so the final frame renders, and NobleSprite:add() now defaults to the sprite's current self.x/self.y instead of 0,0. Adapted from upstream PR NobleRobot#65: the Noble.lua hunk (reordering Graphics.sprite.update() after currentScene:update() in the game loop) was deliberately dropped, as it would break the documented pattern of drawing animations directly in a scene's update() method (see Noble.Animation:draw() docs). Co-authored-by: Igor Stepanov <stiv-iv@users.noreply.github.com>
Commit 75f4526 (upstream PR NobleRobot#65) moved the markDirty() call from NobleSprite:draw() to a new NobleSprite:update() method, so that pause() and stop() actually halt an animation. However, subclasses that define their own update() method (the documented pattern, per the Noble.Animation:setState usage example) shadow NobleSprite:update(), so the sprite is never re-marked dirty and its animation freezes after one frame when "Graphics.sprite.setAlwaysRedraw(false)" is set. Restore a fallback markDirty() in draw(), gated on updatesEnabled(), which preserves the pause()/stop() fix while keeping overridden update() methods working. Refs upstream PR NobleRobot#65.
|
I integrated this locally — the sprite-side changes are a real fix (
function NobleSprite:draw()
if (self.animation ~= nil) then
self.animation:draw()
if (self:updatesEnabled()) then
-- Normally NobleSprite:update() marks this sprite dirty each frame.
-- Also mark it here, in case a subclass has overridden update()
-- without calling its super method.
self:markDirty()
end
end
end |
Fixed NobleSprite animation drawing in cases, when Graphics.sprite.getAlwaysRedraw() == false