Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for terminating/locking/unlocking/sleep callback #55

Open
GammaGames opened this issue Jul 25, 2023 · 3 comments
Open

Add support for terminating/locking/unlocking/sleep callback #55

GammaGames opened this issue Jul 25, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@GammaGames
Copy link
Contributor

Describe the feature
Someone on the discord discovered a catalog game that had an exit animation and implemented it in their own game:

Playdate_2023-07-24_222512.mp4

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
@GammaGames GammaGames added the enhancement New feature or request label Jul 25, 2023
@Mark-LaCroix
Copy link
Member

Mark-LaCroix commented Jul 25, 2023

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?

@GammaGames
Copy link
Contributor Author

GammaGames commented Jul 25, 2023

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

@GammaGames
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To-do
Development

No branches or pull requests

2 participants