Playdate.update() and third party libraries

The SDK let you override playdate.update() to put stuff for the main loop of your app. Depending on what you use, you'll most likely also call things like playdate.graphics.sprite.update(), playdate.timer.updateTimers() or playdate.frameTimer.updateTimers() from there.

Problem is, how do we deal with separate librairies needing, for example, frame timers to be updated but we want to make sure that it's not called twice?

We could manage all this in the main code, but that's rather fragile (i.e. if you forget to add the call to playdate.frameTimer.updateTimers() then the libraries don't work properly).

Other problem is librairies might have things that they want to update in there too, so those libraries expose an update() method that the user needs to remember to call otherwise the library doesn't work.

I'm thinking of putting together a small update library that would be the sole keeper of playdate.update(), allowing others to say "I need to update frame timers!" or "I need to update sprites!" and also to add their own callbacks that will be called during playdate.update().

That sounds cleaner to me but maybe I'm missing something obvious that's already there?

1 Like

I wrote this quickly today. Still curious if there is an easier way I've missed but for the time being it lets me cleanly and automatically handle playdate.update() between all dependencies.