NobleEngine
NobleEngine copied to clipboard
Add support for terminating/locking/unlocking/sleep callback
Describe the feature Someone on the discord discovered a catalog game that had an exit animation and implemented it in their own game:
https://github.com/NobleRobot/NobleEngine/assets/7832163/eb180161-7784-4f25-b6aa-24a7359e93d4
They don't use Noble, but they shared their code and it was surprisingly simple. I think it would be nice to easily support it on a per-scene basis. The other use for the function is to save data when the device does the thing.
Describe alternatives you've considered You could do it manually, which is what I'm doing now.
What problems would this solve or help prevent, if any It would show off the lesser-known parts of the SDK and easier saving when not using autosave on a per-scene basis
Additional context Here's my case scene:
class("BaseScene").extends(NobleScene)
function BaseScene:enter()
BaseScene.super.enter(self)
function pd.gameWillTerminate() self:terminate() end
function pd.deviceWillSleep() self:sleep() end
function pd.deviceWillLock() self:lock() end
function pd.deviceDidUnlock() self:unlock() end
end
function BaseScene:exit()
BaseScene.super.exit(self)
function pd.gameWillTerminate() end
function pd.deviceWillSleep() end
function pd.deviceWillLock() end
function pd.deviceDidUnlock() end
end
function BaseScene:terminate() end
function BaseScene:sleep() end
function BaseScene:lock() end
function BaseScene:unlock() end
I like this a lot! I'd want to create it so that it's app-specific behavior which mostly governs this, but that it can be overridden or amended with scene-specific behavior. But that's more a design problem than a technical problem. This does seem easy to implement. The trick would be to add enough value so it's not just wrapping the SDK call, without encouraging users to re-implement their code for every scene if they only want to do one thing.
Also, what's the limit to what can be done during those callbacks, and how can Noble Engine guide users to honor that limit?
There's a 10 second watchdog timer that will force close/sleep your game if passed. I think that's the main limitation, which isn't too bad considering it was designed for saving game state. The animations are just a nice little side effect!
This would also be nice if the transitions were generalized so they could be used. A simple fade out would be awesome!
Here's a super simple example. The screen doesn't seem to update on non-mac simulator so I can't get a gif:
function pd.GameWillTerminate()
local timer = gfx.animator.new(350, 0, 1)
while not timer:ended() do
gfx.getWorkingImage():vcrPauseFilterImage():draw(0, 0)
pd.display.flush()
end
end
Note that regular timers don't actually update, since the game is paused. Only animators will work
Maybe the option to have the callbacks in your Noble.Settings
namespace? Per-scene would be cool (and I think it'd make sense game-save wise) but I see the value in moving the functions out and generalizing their use