Add Callback functions

2025-12-25 20:19:43 +00:00
parent e4db842bea
commit 85156f2b04

53
Callback-functions.md Normal file

@@ -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
}
})
```