Since the last SDK update timer is behaving oddly. In the sample code below, it used to count down from 200 to 0 but now it jumps to 210 once it reaches 190!
Using Nova with SDK 2.4.2
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
local gfx <const> = playdate.graphics
local playTimer = nil
local playTime = 200 * 1000
local function resetTimer()
playTimer = playdate.timer.new(playTime, playTime, 0, playdate.easingFunctions.linear)
end
local function initialize()
local backgroundImage = gfx.image.new("images/background")
gfx.sprite.setBackgroundDrawingCallback(
function(x, y, width, height)
gfx.setClipRect(x, y, width, height)
gfx.setColor(playdate.graphics.kColorWhite)
gfx.fillRect(x, y, width, height)
gfx.clearClipRect()
end
)
resetTimer()
end
initialize()
function playdate.update()
playdate.timer.updateTimers()
gfx.sprite.update()
gfx.drawText("Time: " .. math.ceil(playTimer.value/1000), 5, 5)
end
I think I've figured out the issue: the numbers that are passed into your timer are being specified as integers, and because they're relatively large, they are creating an integer overflow situation in the easing function.
I'm looking at the best way to fix this (maybe by converting all numbers going into the easing functions to floats?), but in the meantime, you can fix your problem by explicitly declaring your numbers as floating point. One way to do this is by changing: