Last active
February 14, 2025 09:59
-
-
Save cie/50051d74d5e61162f988fe6b4cc0ae79 to your computer and use it in GitHub Desktop.
p5play scene manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function setup(level) { | |
let text = new Sprite(); | |
text.color = "transparent"; | |
text.stroke = "transparent"; | |
text.text = `Level ${level}`; | |
text.textSize = 50; | |
text.textColor = "white"; | |
text.life = 60; | |
} | |
export function update() { | |
if (mouse.presses()) { | |
loadScene("welcome"); | |
} | |
} | |
export function drawFrame() { | |
background("black"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() { | |
// global setup - add your global setup here | |
new Canvas(800, 600); | |
displayMode("maxed", "pixelated"); | |
loadScene("welcome"); | |
} | |
let currentScene; | |
async function loadScene(name, ...setupArgs) { | |
currentScene = await import(`./${name}.js`); | |
// clear everything - add your cleanup here | |
allSprites.remove(); | |
world.gravity = new Vector(0, 0); | |
await currentScene.setup?.(...setupArgs); | |
} | |
function update() { | |
currentScene?.update?.(); | |
} | |
function drawFrame() { | |
currentScene?.drawFrame?.(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function setup() { | |
let text = new Sprite(); | |
text.color = "transparent"; | |
text.stroke = "transparent"; | |
text.text = "Click to start"; | |
text.textSize = 50; | |
text.textColor = "white"; | |
} | |
export function update() { | |
if (mouse.presses()) { | |
loadScene("level", 1); | |
} | |
} | |
export function drawFrame() { | |
background("purple"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment