If crank is spun in a constant direction at high speed while playdate.update is performing heavy but burdensome processing, the value returned by playdate.cranked will be incorrect.
Source
import 'CoreLibs/graphics.lua'
local gfx = playdate.graphics
local _crank = 1
function playdate.update()
gfx.clear(gfx.kColorWhite)
local img1 = gfx.image.new("test01.png")
local img2 = gfx.image.new("test02.png")
img1:drawRotated(0, 0, _crank % 360, 2)
img2:drawRotated(400, 0, _crank % 360, 2)
img1:drawRotated(400, 240, _crank % 360, 2)
img2:drawRotated(0, 240, _crank % 360, 2)
end
function playdate.cranked(change, acceleratedChange)
print("cranked", change, acceleratedChange)
_crank = _crank + change
end
Log
cranked 4.952881 2.471159
cranked 52.90158 111.3356
cranked -177.5961 -878.8915
cranked 155.7728 760.3572
cranked -176.9019 -875.2085
cranked -176.4962 -873.0543
cranked 161.4194 791.6566
cranked -175.3091 -866.741
cranked 40.18457 61.52943
cranked 0.4657593 0.1980723
CrankTest.zip (4.8 KB)
In the example, we keep moving the crank forward, but the argument of playdate.cranked will randomly return a positive or negative value.
This is only occurring on Playdate devices.