Sprites off screen due to setDrawOffset still cause screen updates

I wrote a test because I want to have a very large scrolling area and use setDrawOffset to scroll around in it. I have a sprite at 100,100, and when I use setDrawOffset to move the camera the sprite moves as expected and the screen updates and all is cool. But when it goes off screen, the last position of the sprite on the display before it went off screen remains updating whenever I call setDrawOffset even if that's not where the sprite is.

Here is code that recreates the problem:

local gfx <const> = playdate.graphics
local img <const> = playdate.graphics.image

local test_sprite = nil
local test_image = nil
local scroll_timer = nil

local scroll_delay = 20
local scroll_val = 0
local scroll_amount = 1200
local scroll_speed = 0.1

function update_scroll()
    scroll_val += scroll_speed    
    gfx.setDrawOffset(math.sin(scroll_val) * scroll_amount, 0)

state_spritescrolltest = {

    init = function()
        print("Entering sprite scroll test state.")
        test_image = img.new("images/sharpener/pencil_sharp_med")
        test_sprite = gfx.sprite.new(test_image)
        test_sprite:moveTo(100, 100)
        scroll_timer = playdate.timer.new(scroll_delay, update_scroll)
        scroll_timer.repeats = true

    shutdown = function()
        print("Leaving sprite scroll test state.")        
        test_sprite = nil
        test_image = nil

    update = function()

    draw = function()


Am I just doing it wrong? I would expect the sprite not to be trying to update the screen at all if it's off screen.




This was reproduced in 2.0.1.

This seems familiar, I think you can see it as part of this weird bug.

1 Like

Very interesting. This dirty rect stuff is really tricky, I'm really impressed by how well it works tbh. I did not expect set draw offset to work as well as it did with it.

This one has been bugging me for a while, so thanks for the kick in the pants. :slight_smile: Turns out the problem is the sprite's "here's the area of the screen I've drawn on" record doesn't get cleared when it moves offscreen. I've added a fix for that, but we'll definitely want to test it thoroughly before pushing it--if I screwed up and I'm clearing that record in cases where I shouldn't be it'll leave garbage pixels on the screen.


My fix for this is in today's 2.3 update. Please let us know if this doesn't actually fix the problem!

1 Like