-
Notifications
You must be signed in to change notification settings - Fork 26
Callbacks
Alessandro Febretti edited this page Feb 7, 2014
·
5 revisions
These functions specify callbacks to be executed during frame updates and when events are received.
Sets a callback functionto to be called for each frame. The function will take three parameters:
- frame number
- time since application start (in seconds)
- time since last frame (in seconds) Example:
def onUpdate(frame, time, dt):
print("frame number: " + frame)
setUpdateFunction(onUpdate)
Sets a callback function to be called every time an event is received. Example:
def onEvent():
e = getEvent()
# prints the event type
print(e.getType())
setEventFunction(onUpdate)
(experimental) Sets a callback functionto to be called for each frame during 2d drawing. The function will take four parameters:
- the total display size (as a Vector2)
- the current tile size (as a Vector2)
- a
Camera
object - a
DrawInterface
object that can be used to draw 2d elements Example:
white = Color("white")
black = Color("black")
def onDraw(displaySize, tileSize, camera, painter):
global white
global black
# Get the default font
font = painter.getDefaultFont()
# Set some text and compute its width and height in pixels (given the font we cant to use)
text = "Hello World From Python!"
textSize = font.computeSize(text)
# Draw a white box and put the text inside it
painter.drawRect(Vector2(10, 10), textSize + Vector2(10, 10), white)
painter.drawText(text, font, Vector2(15, 15), TextAlign.HALeft | TextAlign.VATop, black)
setDrawFunction(onDraw)
Unregisters all the update, draw and event functions added so far.
Attaches a command to be executed whenever the node selection state changes
Example:
node = SceneNode.create('node')
getScene().addChild(node)
# Change the node size when the selection state changes
addSelectionListener(node, 'node.setScale(Vector3f(1.5, 1.5, 1.5))')
# Force a selection state change. This will invoke the listener code
node.setSelected(True)
Attaches a command to be executed whenever the node visibility changes
Example:
node = SceneNode.create('node')
getScene().addChild(node)
# Print a message on visibility changes
addVisibilityListener(node, 'print("node " + node.getName() + " visible changed"')
# Change node visibility.
node.setVisible(False)