relativeTo(...)

relativeTo(val : Node) : this;

relativeTo(val : Node[]) : this;

Sets the node(s) that this node's location is relative to.

By default a node's location is relative to its parent's location. A node with a non-empty relativeTo will be displayed in a location (i.e. position, scale and rotation) relative to the nodes specified. All other attributes (color, visible, etc) remain relative to the parent.

If multiple nodes are specified then this node's location will be interpolated between the locations of the specified nodes. The relativeToProp(...) function specifies the ratio of the contribution each of the specified nodes' locations have.

A number of global nodes are available and may be used as an argument to relativeTo:

  • Z.screen

    Orthographic projection with the center of the screen at [0, 0, 0]. The top center of the screen is at [0, 1, 0] and the bottom center is at [0, -1, 0]. The space is oriented in landscape.

  • Z.screenLeft

    Orthographic projection with [0, 0, 0] at the center left side of the screen. The top left of the screen is at [0, 1, 0] and the bottom left is at [0, -1, 0]. The space is oriented in landscape.

  • Z.screenRight

    Orthographic projection with [0, 0, 0] at the center right side of the screen. The top right of the screen is at [0, 1, 0] and the bottom right is at [0, -1, 0]. The space is oriented in landscape.

  • Z.camera

    Perspective projection with [0, 0, 0] at the center of the device's camera. The x-coordinate points right, the y-coordinate points up and the z-coodinate points towards the user out of the screen. Position objects with a negative z-coordinate for them to be visible. The space is oriented in landscape.

For more information see Coordinate Systems.

Parameters

Parameter Type Description
val Node, Node[] or null The node(s) that this node's location should be relative to. If val is null or an empty array then this node will be located relative to its parent.

Returns

this

Example

myobject.relativeTo(Z.screenRight);
// myobject is now located relative to the right of the screen
zapcode branded_zapcode i