Class: Obj

World.Obj(parent, name)

This class is the root of the inheritance used for the nodes of the scene graph. Obj is an node only consisting of a Transform for saving its position and the nodes children (an array of Objs) It has no direct drawing behaviour. If you are looking for drawable node types see: Sprite, Model, Text

Constructor

new Obj(parent, name)

Constructs a new Obj with an optional parent and display name. When the parent is set the Obj will be automatically added as a child of the parent.
Parameters:
Name Type Description
parent World.Obj The parent of the newly created scene graph node
name string The name of the Obj (helpful for debugging)

Members

children :Array.<World.Obj>

The children of this node.

engine :Apate

The engine in wich context the Obj is executed. Could be undefined if the node is not in an active scene graph or the Obj#on_scene_enter event is not propagated.

layer

The number of the layer it gets drawn to. Used to handle the order of drawing.
Default Value:
  • 1 - meaning it gets drawn after the background (layer 0) but before ui (layer 2)

name :string

The name of the Object. Suitable for debugging purposes.

parent :World.Obj

The parent node in the scene graph.

transform :Core.Transform

The transform object of the node. It stores the transformations of a node in relation to the parent.
Example
// move this node by 10 units and rotate it by 180 deg
this.transform.postion.x += 10;
this.transform.rotation.z += Math.PI;

Methods

absolut() :Core.Transform

Calculates the absolute position of this node within the scene
Returns:
the transformations object

add(…children)

Adds children to this node.
Parameters:
Name Type Attributes Description
children Array.<World.Obj> <repeatable>
The children to add

draw(context)

Override to define draw behaviour. After this method was executed all children will be drawn (recursively).
Parameters:
Name Type Description
context Context The context of the draw operations
Example
// could be inside draw() {...}
// draw a tile with the current context
const tile = Tile.fromColor(Vec.fromHex(0xFF00FFFF)); // create magenta tile
const material = new Materials.SpriteMaterial(); // create a sprite material
// ...
context.drawTile(this.transform, tile, material);

drawAfter(context)

Override to define behaviour after drawing. Could be used to clean up cameras, targets or simply to draw own Obj after the children
Parameters:
Name Type Description
context Context The context of the draw operations

(protected) drawRec(context, layer)

This method is used to propagate the draw through all children of this node.
Parameters:
Name Type Description
context Context The context of the draw operations
layer number The current layer which should be drawn

on_scene_enter(engine)

An event wich gets called when this node enters the scene graph. When injecting own code, make sure to call `super.on_scene_enter(engine)` to ensure the World.Obj#engine is set.
Parameters:
Name Type Description
engine Apate The engine of the active scene graph

on_scene_exit(engine)

An event wich gets called when this node is removed from the scene graph. When injecting own code, make sure to call `super.on_scene_exit(engine)` to ensure the World.Obj#engine property is set to undefined.
Parameters:
Name Type Description
engine Apate The engine where the scene graph was active

recCall(name, …params)

Recursively calls a function of this Obj given by a name and arguments. Used for traversing the graph, and propagating events.
Parameters:
Name Type Attributes Description
name string The name of the function
params Array.<any> <repeatable>
The parameters of the function

remove()

Remove this node from the scene graph. The nodes parent will have one children less when the node was removed.

render(context)

Parameters:
Name Type Description
context Context The context of the draw instructions
Deprecated:
  • use Obj#draw instead. Used for engine internal drawing.

root() :World.Obj

Gets the root node of the graph
Returns:
the obj wich acts as root node