From 85156f2b0442eafcbe062b26a38c9c3be1ea1836 Mon Sep 17 00:00:00 2001 From: Hugo H Date: Thu, 25 Dec 2025 20:19:43 +0000 Subject: [PATCH] Add Callback functions --- Callback-functions.md | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Callback-functions.md diff --git a/Callback-functions.md b/Callback-functions.md new file mode 100644 index 0000000..06d09f4 --- /dev/null +++ b/Callback-functions.md @@ -0,0 +1,53 @@ +You can pass the following functions to s.start() in a dictionary: +|Name|Arguments passed to function|Timing| +|---|---|---| +|"init"|None|Once when the engine starts| +|"update"|None|60 times per second| +|"draw"|None|60 times per second, after update| +|"resized"|width, height|Whenever the canvas changes size| +|"tap"|x, y, id|When a click or touch begins| +|"untap"|x, y, id|When a click is released or a touch ends| +|"tapping"|x, y, id|Every frame while a pointer is held down and moving| +|"tapped"|x, y, id|Triggered when a quick click or tap is completed| + +## Example: +```python +import screen as s + +def init(): + pass + +def update(): + pass + +def draw(): + pass + +def resized(w, h): + pass + +def tap(x, y, id): + pass + +def untap(x, y, id): + pass + +def tapping(x, y, id): + pass + +def tapped(x, y, id): + pass + +s.start({ + "loop": { + "init": init, + "update": update, + "draw": draw, + "resized": resized, + "tap": tap, + "untap": untap, + "tapping": tapping, + "tapped": tapped + } +}) +``` \ No newline at end of file