Node Class Reference

Node is the base class for all scenegraph nodes. More...

Inheritance diagram for Node:
Label Particles Plane3D RawSpriteTileList Scene SpriteBase SpriteList TransitionScene SpriteTile SpriteUV TransitionFadeBase TransitionCrossFade TransitionDirectionalFade TransitionSolidFade

List of all members.

Public Member Functions

void Rotate (float angle)
 Rotate the object by an angle 'angle'.
void Rotate (Vector2 rotation)
 Rotate the object by an angle, the angle is given as a unit vector 'rotation' This lets you precompute the cos,sin needed during rotation.
delegate void DDraw ()
 The delegate type used by AdHocDraw property.
 Node ()
 Node constructor.
virtual void PushTransform ()
 This is called before drawing the node and its children.
virtual void PopTransform ()
 This is called after drawing the node and its children.
virtual void OnEnter ()
 This function gets called when the scene is started by the Director.Instance.
delegate void DOnExitEvent ()
 Delegate for OnExit() events.
virtual void OnExit ()
 This function gets called when we exit the Scene or when a child is explicitely removed with RemoveChild() or RemoveAllChildren().
void RegisterDisposeOnExitRecursive ()
 Recurse through all the subtree (including this node) and register Dispose() functions for all the disposable objects.
void RegisterDisposeOnExit (System.IDisposable disposable)
 Register a call to Dispose() in the OnExit() function of this node.
void AddChild (Node child, int order)
 Add a child with draw priority.
void AddChild (Node child)
 Add a child to this node, using its current order.
void RemoveChild (Node child, bool do_cleanup)
 Remove a child from this node.
void RemoveAllChildren (bool do_cleanup)
 This is equivalent to calling RemoveChild( dispose_flags ) for all children.
delegate bool DVisitor (Node node, int depth)
 Function type to pass to the .Traverse method.
virtual void Traverse (DVisitor visitor, int depth)
 Call the 'visitor' function for this node and all its children, recursively.
virtual void DrawHierarchy ()
 This called by Director only, but PushTransform, Draw, and PopTransform can be overriden.
virtual void Draw ()
 Renders what's *inside* the PushTransform / PopTransform.
virtual void Update (float dt)
 The update function.
virtual void DebugDrawContentLocalBounds ()
 Draw bounds of local content and pivot, in Node local space.
void DebugDrawTransform ()
 Draw the local coordinate system, as arrows, in Parent Node's local space.
void RunAction (ActionBase action)
 Start an action on this node.
void StopAllActions ()
 Stop all actions on this node.
void StopAction (ActionBase action)
 Stop an action on this node.
void StopActionByTag (int tag)
 Search for the first action acting on this node with tag value 'tag' and stop/remove it.
ActionBase GetActionByTag (int tag, int ith=0)
 Return the 'ith' action with tag 'tag' acting on this node.
int NumRunningActions ()
 Get the number of action acting on this node.
virtual void Cleanup ()
 Recursively stop all actions and scheduled functions on this node.
void ScheduleUpdate (int priority=Scheduler.DefaultPriority)
 Register this node's update function to the scheduler, it will get called everyframe.
void UnscheduleUpdate ()
 Remove the update function from the scheduler.
void Schedule (DSchedulerFunc func, int priority=Scheduler.DefaultPriority)
 Schedule node function 'func', it will get called everyframe.
void ScheduleInterval (DSchedulerFunc func, float interval, int priority=Scheduler.DefaultPriority)
 Schedule node function 'func' so it gets called every 'interval' seconds.
void Unschedule (DSchedulerFunc func)
 Unschedule node function 'func'.
void UnscheduleAll ()
 Unschedule all functions related to this node.
void ResumeSchedulerAndActions ()
 Sets SchedulerPaused and ActionsPaused to true.
void PauseSchedulerAndActions ()
 Sets SchedulerPaused and ActionsPaused to false.
Matrix3 GetTransform ()
 Return the transform matrix of this node, expressed in its parent space.
Matrix3 GetTransformInverse ()
 Get the inverse of this node 's transform matrix.
Matrix3 GetWorldTransform ()
 Return the transform matrix of this node, expressed in its world/parent Scene space.
Matrix3 CalcWorldTransformInverse ()
 Get the inverse of this node's world transform matrix.
Vector2 LocalToWorld (Vector2 local_point)
 LocalToWorld Should return the same as ( GetWorldTransform() * local_point.Xy1 ).Xy.
Vector2 WorldToLocal (Vector2 world_point)
 Should return the same as ( CalcWorldTransformInverse() * world_point.Xy1 ).Xy.
virtual bool GetlContentLocalBounds (ref Bounds2 bounds)
 Get the bounds for the content/geometry of this node (only), in node space (no recursion).
virtual bool GetContentWorldBounds (ref Bounds2 bounds)
 Get the bounds for the content of this node (only), in world space (no recursion).
bool IsWorldPointInsideContentLocalBounds (Vector2 world_position)
 Return true if 'world_position' is inside the content oriented bounding box.
virtual void FindParentPlane (ref Matrix4 mat)
 Follow parent hierarchy until we find a Plane3D node, and set 'mat' to the Plane3D's plane matrix.
Vector2 GetTouchPos (int nth=0, bool prev=false)
 Like Director.Instance.CurrentScene.Camera.GetTouchPos, but deals with the case when there is a Plane3D among ancestors in the scenegraph.

Public Attributes

float VertexZ
 VertexZ is the value set as the z coordinate during drawing.
bool Visible
 If Visible is false, this node and its children are not drawn.
ICamera Camera = null
 You can use Node.Camera as a workaround to the fact there is normally only one camera in the scene.
string Name
 Identifier for user.

Static Public Attributes

static float DebugDrawTransformScale = 1.0f
 A scale factor used by DebugDrawTransform to draw arrows.

Properties

Vector2 Position [get, set]
 See GetTransform() for details about how the transform matrix is constructed.
Vector2 Rotation [get, set]
 Rotation is directly stored as a (cos,sin) unit vector.
Vector2 RotationNormalize [get, set]
 RotationNormalize is like Rotation, but it normalizes on set, to prevent the unit vector from drifting because of accumulated numerical imprecision.
float Angle [get, set]
 This property lets you set/get rotation as a angle.
Vector2 Scale [get, set]
 See GetTransform() for details about how the transform matrix is constructed.
Vector2 Skew [get, set]
 See GetTransform() for details about how the transform matrix is constructed.
Vector2 Pivot [get, set]
 Pivot is the pivot used for scale and rotation, and is expressed in this Node's local 'normalized' space.
Node Parent [get]
 The parent node in the scenegraph.
List< NodeChildren [get]
 The list of children nodes.
Camera2D Camera2D [get]
 Shortcut to get the camera as a Camera2D.
Camera3D Camera3D [get]
 Shortcut to get the camera as a Camera3D.
bool IsRunning [get]
 This property is true when this node is between its OnEnter()/OnExit() calls.
int Order [get]
 The draw order value that was set in ReorderChild() or AddChild().
bool ActionsPaused [get, set]
 All actions related to this node can be paused on and off with this flag.
bool SchedulerPaused [get, set]
 All scheduled functions related to this node can be paused on and off with this flag.

Events

DDraw AdHocDraw
 If set, AdHocDraw gets called in the base Draw function.
DOnExitEvent OnExitEvents
 List of events to perform when OnExit gets called.

Detailed Description

Node is the base class for all scenegraph nodes.

It holds a standard 2D transform, a list of children and a handle to its parent (a node can have at most 1 parent).


Member Function Documentation

void AddChild ( Node  child,
int  order 
)

Add a child with draw priority.

Parameters:
childThe child to add.
orderThe added node's draw priority. Draw order follows order numerical order, negative priorities mean this child node will be drawn before its parent, and children with positive priorities get drawn after their parent.
virtual void DebugDrawContentLocalBounds ( ) [virtual]

Draw bounds of local content and pivot, in Node local space.

Normally you don't have to override this function, you just override GetlContentLocalBounds() and this function shows it when DebugFlags.DrawContentLocalBounds is set for example.

virtual bool GetContentWorldBounds ( ref Bounds2  bounds) [virtual]

Get the bounds for the content of this node (only), in world space (no recursion).

Nodes that don't have any content just return false and don't touch bounds.

virtual bool GetlContentLocalBounds ( ref Bounds2  bounds) [virtual]

Get the bounds for the content/geometry of this node (only), in node space (no recursion).

Nodes that don't have any content just return false.

Reimplemented in Label, and SpriteBase.

Matrix3 GetTransform ( )

Return the transform matrix of this node, expressed in its parent space.

The node transform matrix is formed using the data accessed with the Position, Scale, Skew, Rotation/Angle/RotationNormalize, Pivot properties. The transform matrix is equivalent to:

Matrix3.Translation( Position ) Matrix3.Translation( Pivot ) Matrix3.Rotation( Rotation ) Matrix3.Scale( Scale ) Matrix3.Skew( Skew ) Matrix3.Translation( -Pivot )

Node that the transform matrix returned is a pure 2D transform. VertexZ is applied separately in the PushTransform function.

void RegisterDisposeOnExit ( System.IDisposable  disposable)

Register a call to Dispose() in the OnExit() function of this node.

For example, when you want to Dispose() of several objects (TextureInfo, FontMap, etc) when you exit a Scene node.

void RegisterDisposeOnExitRecursive ( )

Recurse through all the subtree (including this node) and register Dispose() functions for all the disposable objects.

Cleanup is called first to make sure we don't Dispose() of running objects.

void RemoveChild ( Node  child,
bool  do_cleanup 
)

Remove a child from this node.

Parameters:
childThe child to remove.
do_cleanupDo we call Cleanup for the removed node.
void Rotate ( Vector2  rotation)

Rotate the object by an angle, the angle is given as a unit vector 'rotation' This lets you precompute the cos,sin needed during rotation.

Note that this function simply affects the the Rotation/Angle property (it simply "increments" the angle, regardless of Pivot and Position; and all those are combined in GetTransform().) See GetTransform() for details about how the transform matrix is constructed.

void Rotate ( float  angle)

Rotate the object by an angle 'angle'.

Note that this function simply affects the the Rotation/Angle property (it simply "increments" the angle, regardless of Pivot and Position; and all those are combined in GetTransform().) See GetTransform() for details about how the transform matrix is constructed.

virtual void Traverse ( DVisitor  visitor,
int  depth 
) [virtual]

Call the 'visitor' function for this node and all its children, recursively.

Interrupt traversing if visitor returns false.

virtual void Update ( float  dt) [virtual]

The update function.

The Director decides how many times a frame this function should be called, and with which delta time. At the moment, Update functions are called once using the frame delta time as it is.

Parameters:
dtDelta time in seconds.

Reimplemented in Particles.

Vector2 WorldToLocal ( Vector2  world_point)

Should return the same as ( CalcWorldTransformInverse() * world_point.Xy1 ).Xy.

The local space of the node is the space in which its geometry is defined, i.e one level below GetWorldTransform().


Member Data Documentation

ICamera Camera = null

You can use Node.Camera as a workaround to the fact there is normally only one camera in the scene.

If Node.Camera is set, all transforms up to this node are ignored, and Node.Camera is push/pop everytime we draw this node.

float DebugDrawTransformScale = 1.0f [static]

A scale factor used by DebugDrawTransform to draw arrows.

By default this is 1.0f, which means that unit length arrows are of length 1 on screen. he game world showed on screen is too big, arrows of length one might be less then 1 pixel, and you won't be able to see them even through they are being drawn. In that case you can scale them with DebugDrawTransform.

float VertexZ

VertexZ is the value set as the z coordinate during drawing.

Note that by default ortho view only shows the [-1,1] Z range, just set Camera.Znear and Camera.Zfar if you want more.


Property Documentation

float Angle [get, set]

This property lets you set/get rotation as a angle.

This is expensive and brings the usual angle discontinuity problems. The angle is always stored and returned in the the range -pi,pi. See GetTransform() for details about how the transform matrix is constructed.

Node Parent [get]

The parent node in the scenegraph.

A node can only be the child of at most one parent node.

Vector2 Pivot [get, set]

Pivot is the pivot used for scale and rotation, and is expressed in this Node's local 'normalized' space.

Which means that (0.5,0.5) is always the center of the object, regardless of the Scale for example. See GetTransform() for details about how the transform matrix is constructed.

Vector2 Rotation [get, set]

Rotation is directly stored as a (cos,sin) unit vector.

This the code to be potentially cos,sin calls free, and as a side effect we get the direction vector for free, and also avoid all the usual angle wrapping problems. See GetTransform() for details about how the transform matrix is constructed.

Vector2 RotationNormalize [get, set]

RotationNormalize is like Rotation, but it normalizes on set, to prevent the unit vector from drifting because of accumulated numerical imprecision.

See GetTransform() for details about how the transform matrix is constructed.


Event Documentation

DDraw AdHocDraw

If set, AdHocDraw gets called in the base Draw function.

This is used mostly so we can setup simple scenes without always having to derive just so we can define a Draw function.

DOnExitEvent OnExitEvents

List of events to perform when OnExit gets called.

The list gets cleared after it is executed.