Skip to content
Alessandro Febretti edited this page Feb 7, 2014 · 5 revisions

module omega

These functions specify callbacks to be executed during frame updates and when events are received.

setUpdateFunction(func)

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)

setEventFunction(func)

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)

setDrawFunction(func)

(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)

unregisterFrameCallbacks() (v5.1.1)

Unregisters all the update, draw and event functions added so far.

addSelectionListener(node, cmd)

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)

addVisibilityListener(node, cmd)

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)
Clone this wiki locally