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)
end
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)
test_sprite:add()
scroll_timer = playdate.timer.new(scroll_delay, update_scroll)
scroll_timer.repeats = true
end,
shutdown = function()
print("Leaving sprite scroll test state.")
test_sprite:remove()
test_sprite = nil
test_image = nil
scroll_timer:remove()
end,
update = function()
end,
draw = function()
end
}
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.
Cheers
Alex