I'm using the crank.lua coreLib in my project and have it so it triggers twice every revolution.
By default this will trigger as it passes 0 degrees and 180 degrees.
How would I amend the Lib file to "tick" at 90 degrees and 270 degrees instead?
I'm using the crank.lua coreLib in my project and have it so it triggers twice every revolution.
By default this will trigger as it passes 0 degrees and 180 degrees.
How would I amend the Lib file to "tick" at 90 degrees and 270 degrees instead?
Thinking out loud... maybe simplest to use 4 ticks, and just ignore the unwanted 2?
Hmm... maybe.
The function only returns a +1 or a -1 depending on direction It think so I don't really know how I would do that.
Maybe if I set it to 4 ticks and then read the location of the crank when the tick is returned...
I thought there might be a simpler answer but thank you for your suggestion.
I filed a feature request for this. I think something this this should do the trick:
[...]
local tick_lastCrankReading = nil
local tick_crankOffset = nil
function playdate.setCrankTickOffset(offset) tick_crankOffset = offset end
function playdate.getCrankTicks(ticksPerRotation)
local totalSegments = ticksPerRotation
local degreesPerSegment = 360 / ticksPerRotation
local thisCrankReading = playdate.getCrankPosition() - tick_crankOffset
if tick_lastCrankReading == nil then
tick_lastCrankReading = thisCrankReading
end
[...]
If you want to give it a try just copy CoreLibs/crank.lua into your project and edit that version so you don't have to worry about an SDK update overwriting it.
I didn't know about the tick function!
I've been managing them myself using playdate.getCrankPosition() and mod and now I feel rather stupid.