NobleScene
An abstract scene class.
Do not copy this file as a template for your scenes. Instead, your scenes will extend this class.
See templates/SceneTemplate.lua for a blank scene that you can copy and modify for your own scenes.
If you are using NobleEngine-ProjectTemplate,
see scenes/ExampleScene.lua
for an implementation example.
Usage
YourSceneName = {} class("YourSceneName").extends(NobleScene) local scene = YourSceneName
Properties
- noblescene.name
-
The name of this scene. Optional.
If you do not set this value, it will take on the scene's
className
. - noblescene.backgroundColor
- This is the background color of this scene.
Tables
- noblescene.inputHandler
-
All scenes have a default inputHandler which is made active when the scene starts.
If you do not define your scene's inputHandler, it is
nil
and input is disabled when this scene starts.See
Usage
YourSceneName.inputHandler = { AButtonDown = function() // Your code here end, AButtonHold = function() // Your code here end, -- ... -- ... } -- OR... -- Use a non-scene-specific inputHandler, defined elsewhere. YourSceneName.inputHandler = somePreviouslyDefinedInputHandler -- OR... -- Reuse another scene's inputHandler. YourSceneName.inputHandler = SomeOtherSceneName.inputHandler
- noblescene.sprites
-
When you add a sprite to your scene, it is put in this table so the scene can keep track of it.
This is intended as
read-only
. You should not modify this table directly.See
Methods
- noblescene:addSprite(__sprite)
-
Use this to add sprites to your scene instead of
playdate.graphics.sprite:add()
.If your sprite is a NobleSprite, using
NobleSprite:add()
will also call this method.Sprites added with this method that are tracked by the scene. Any not manually removed before transitioning to another scene are automatically removed in finish.
Parameters
- __sprite
playdate.graphics.sprite
The sprite to add to the scene.
See
- __sprite
playdate.graphics.sprite
- noblescene:removeSprite(__sprite)
-
Use this to remove sprites from your scene instead of
playdate.graphics.sprite:remove()
.If your sprite is a NobleSprite, using
NobleSprite:remove()
will also call this method.Sprites not manually removed before transitioning to another scene are automatically removed in finish.
Parameters
- __sprite
playdate.graphics.sprite
The sprite to add to the scene.
See
- __sprite
playdate.graphics.sprite
Callbacks
- noblescene:init(__sceneProperties)
-
Implement this in your scene if you have code to run when your scene's object is created.
Parameters
- __sceneProperties
Usage
function YourSceneName:init() YourSceneName.super.init(self) --[Your code here]-- end
- __sceneProperties
- noblescene:enter()
-
Implement if you want to run code as the transition to this scene begins, such as UI animation, triggers, etc.
Usage
function YourSceneName:enter() YourSceneName.super.enter(self) --[Your code here]-- end
- noblescene:start()
-
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
Usage
function YourSceneName:start() YourSceneName.super.start(self) --[Your code here]-- end
- noblescene:update()
-
Implement to run scene-specific code on every frame while this scene is active.
NOTE: you may use coroutine.yield() here, because it only runs inside of playdate.update(), which is a coroutine.
Usage
function YourSceneName:update() YourSceneName.super.update(self) --[Your code here]-- end
- noblescene:drawBackground(__x, __y, __width, __height)
-
Implement this function to draw background visual elements in your scene.
This runs when the engine need to redraw a background area.
By default it runs every frame and fills the background with self.backgroundColor. All arguments are optional.
Use
Graphics.sprite.setAlwaysRedraw(false)
afterNoble.new()
to optimize partial redraw.Parameters
- __x
- __y
- __width
- __height
Usage
function YourSceneName:drawBackground(__x, __y, __width, __height) YourSceneName.super.drawBackground(self) -- optional, invokes default behavior. --[Your code here]-- end
- __x
- noblescene:exit()
-
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.
Usage
function YourSceneName:exit() YourSceneName.super.exit(self) --[Your code here]-- end
- noblescene:finish()
-
Implement this in your scene if you have code to run when a transition to another scene
is complete, such as resetting variables.
Usage
function YourSceneName:finish() YourSceneName.super.finish(self) --[Your code here]-- end
- noblescene:pause()
-
pause()
/resume()
Implement one or both of these in your scene if you want something to happen when the game is paused/unpaused by the system. The Playdate SDK does not require you to write pause logic, but these are useful if you want a custom menu image (see Playdate SDK for more details), want to obscure game elements to prevent players from cheating in a time-sensitive game, want to count the number of times the player pauses the game, etc.
Usage
function YourSceneName:pause() YourSceneName.super.pause(self) --[Your code here]-- end
- noblescene:resume()
-
Usage
function YourSceneName:resume() YourSceneName.super.resume(self) --[Your code here]-- end