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 debug callbacks #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions modules/NobleScene.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ NobleScene.name = ""
--
NobleScene.backgroundColor = Graphics.kColorWhite

--- This is the color the scene will use for the `drawDebug` method.
--
NobleScene.debugColor = Graphics.kColorWhite

--- Tables
-- @section tables

Expand Down Expand Up @@ -126,7 +130,9 @@ end
-- --[Your code here]--
-- end
--
function NobleScene:enter() end
function NobleScene:enter()
playdate.setDebugDrawColor(table.unpack(self.debugColor))
end

--- Implement if you have code to run once the transition to this scene is complete. This method signifies the full activation of a scene. If this scene's `inputHandler` is defined, it is enabled now.
-- @see inputHandler
Expand Down Expand Up @@ -184,6 +190,17 @@ function NobleScene:drawBackground(__x, __y, __width, __height)
end
end

--- Implement this function to draw debug elements in the simulator.
--- This will only run when using the simulator.
--
-- @usage
-- function YourSceneName:drawBackground(__x, __y, __width, __height)
-- YourSceneName.super.drawBackground(self) -- optional, invokes default behavior.
-- --[Your code here]--
-- end
--
function NobleScene:drawDebug() end

--- Implement this in your scene if you have "goodbye" code to run when a transition to another scene
-- begins, such as UI animation, saving to disk, etc.
--
Expand All @@ -198,6 +215,7 @@ function NobleScene:exit()
sprite:setUpdatesEnabled(false)
sprite:setCollisionsEnabled(false)
end
self:disableDebug()
end

--- Implement this in your scene if you have code to run when a transition to another scene
Expand Down Expand Up @@ -239,4 +257,27 @@ function NobleScene:pause() end
-- YourSceneName.super.resume(self)
-- --[Your code here]--
-- end
function NobleScene:resume() end
function NobleScene:resume() end

--- `enableDebug()` / `disableDebug()`
--
--- Use this to enable the `drawDebug` function in the simulator.
--
-- Implement one or both of these in your scene if you want something to happen.
-- These are useful if you want to toggle fps with `Noble.showFPS = true`.
--
-- @usage
-- function YourSceneName:enableDebug()
-- YourSceneName.super.enableDebug(self)
-- --[Your code here]--
-- end
function NobleScene:enableDebug()
function playdate.debugDraw()
self:drawDebug()
end
end

function NobleScene:disableDebug()
Noble.showFPS = false
function playdate.debugDraw() end
end