Constructor

new(presentCooldown:Float)

Methods

Inherited Variables

Defined by Scene

read onlycamera:Camera

Alias to the first camera in the camera list: cameras[0]

read onlycameras:ReadOnlyArray<Camera>

List of all cameras attached to the Scene. Should contain at least one camera to render (created by default).

Override h2d.Camera.layerVisible method to filter out specific layers from camera rendering.

To add or remove cameras use Scene.addCamera and Scene.removeCamera methods.

defaultSmooth:Bool

Controls the default value for h2d.Drawable.smooth. Default: false

read onlyheight:Int

The current height (in pixels) of the scene. Can change if the screen gets resized or scaleMode changes.

interactiveCamera:Camera

Camera instance that handles the scene events.

Due to Heaps structure, only one Camera can work with the Interactives. Contrary to rendering, event handling does not check if layer is visible for the camera or not.

Should never be null. When set, if Camera does not belong to the Scene, it will be added with Scene.addCamera. Would cause an exception when trying to remove current interactive camera from the list.

read onlymouseX:Float

The current mouse X coordinates (in pixels) relative to the current Scene.interactiveCamera.

read onlymouseY:Float

The current mouse Y coordinates (in pixels) relative to the current Scene.interactiveCamera.

renderer:RenderContext

The current Scene renderer. Can be customized.

@:value(Resize)scaleMode:ScaleMode = Resize

Scene scaling mode.

Important thing to keep in mind - Scene does not clip rendering to it's scaled size and graphics can render outside of it. However RenderContext.drawTile (and consecutively Object.emitTile) does check for those bounds and will clip out tiles that are outside of the scene bounds.

read onlyviewportScaleX:Float

Horizontal scale of a scene when rendering to the screen.

Can change if the screen gets resized or scaleMode changes.

read onlyviewportScaleY:Float

Vertical scale of a scene when rendering to the screen.

Can change if the screen gets resized or scaleMode changes.

read onlywidth:Int

The current width (in pixels) of the scene. Can change if the screen gets resized or scaleMode changes.

Defined by Object

private@:dox(show)allocated:Bool

A flag that indicates whether the object was allocated or not.

When adding children to allocated objects, onAdd is being called immediately, otherwise it's delayed until the whole tree is added to a currently active Scene.

@:value(1.)alpha:Float = 1.

The amount of transparency of the Object.

@:value(Alpha)blendMode:BlendMode = Alpha

The blending mode of the object.

If there is no Object.filter active, only applies to the current object (not inherited by children). Otherwise tells how the filter is blended with background.

filter:Filter

The post process filter for this object.

When set, Object.alpha value affects both filter and object transparency (use Drawable.color.a to set transparency only for the object).

name:String

The name of the object. Can be used to retrieve an object within a tree by using Object.getObjectByName.

read onlynumChildren:Int

How many immediate children this object has.

read onlyparent:Object

The parent object in the scene tree.

private@:dox(show)parentContainer:Object

The parent container of this object. See Object.contentChanged for more details.

private@:dox(show)posChanged:Bool

A flag that indicates that the object transform was modified and absolute position recalculation is required.

Automatically cleared on Object.sync and can be manually synced with the Object.syncPos.

@:value(0)rotation:Float = 0

The rotation angle of this object, in radians.

@:value(1)scaleX:Float = 1

The amount of horizontal scaling of this object.

@:value(1)scaleY:Float = 1

The amount of vertical scaling of this object.

@:value(true)visible:Bool = true

Is the object and its children are displayed on screen.

@:value(0)x:Float = 0

The x position (in pixels) of the object relative to its parent.

@:value(0)y:Float = 0

The y position (in pixels) of the object relative to its parent.

Inherited Methods

Defined by Scene

addCamera(cam:Camera, ?pos:Int):Void

Adds a Camera to the Scene camera list with optional index at which it is added.

Parameters:

cam

The Camera instance to add.

pos

Optional index at which the camera will be inserted.

addEventListener(f:Event ‑> Void):Void

Add an event listener that will capture all events that were not caught by an h2d.Interactive

captureBitmap(?target:Tile):Bitmap

Capture the scene into a texture and returns the resulting h2d.Bitmap.

Parameters:

target

Optional Tile to render onto. If not set, new Texture with interval Scene viewport dimensions is allocated, otherwise Tile boundaries and Texture are used.

dispose():Void

Dispose the scene and all its children, freeing used GPU memory.

If Scene was allocated, causes Object.onRemove on all Scene objects.

getFocus():Interactive

Get the currently focused Interactive.

getInteractive(x:Float, y:Float):Interactive

Returns the topmost visible Interactive at the specified coordinates.

dynamicmark(name:String):Void

removeCamera(cam:Camera):Void

Removes the Camera from the Scene camera list. Attempting to remove current Scene.interactiveCamera would cause an exception.

removeEventListener(f:Event ‑> Void):Bool

Remove a previously added event listener, returns false it was not part of the event listeners.

setElapsedTime(v:Float):Void

Internal usage

Before Scene.render or Scene.sync are called, allows to set how much time has elapsed (in seconds) since the last frame in order to update scene animations. This is managed automatically by hxd.App.

startCapture(onEvent:Event ‑> Void, ?onCancel:() ‑> Void, ?touchId:Int):Void

Starts input events capture and redirects them to onEvent method until Scene.stopDrag is called.

While the method name may imply that only mouse events would be captured: This is not the case, as it will also capture all other input events, including keyboard events.

Parameters:

onEvent

A callback method that receives hxd.Event when input event happens. Unless onEvent sets Event.propagate to true, event won't be sent to other Interactives.

onCancel

An optional callback that is invoked when Scene.stopDrag is called.

refEvent

For touch events, when defined, only capture events that match the reference Event.touchId.

stopCapture():Void

Stops current input event capture.

syncOnly(et:Float):Void

Synchronize the scene without rendering, updating all objects and animations by the given amount of time, in seconds.

Defined by Layers

@:value({ index : -1, layer : -1 })add(s:Object, layer:Int = -1, index:Int = -1):Void

Adds a child object s at the end of the given layer.

Parameters:

s

An object to be added.

layer

An index of the layer the object should be added at with 0 being the bottom-most layer. Pass -1 to use topmost layer.

index

An optional index at which the object should be inserted inside the layer. Pass -1 to append to the end.

@:dox(show)addChild(s:Object):Void

Adds a child object s at the end of the topmost layer.

Parameters:

s

An object to be added.

@:dox(show)addChildAt(s:Object, index:Int):Void

Adds a child object s at specified index on the top topmost layer.

Warning: Previous behavior of Layers.addChildAt is no longer applicable and Layers.add should be used instead.

Parameters:

s

The object to be added.

index

The position of the object in the layer.

getChildAtLayer(n:Int, layer:Int):Object

Return the nth element among the immediate children list on the layer, or null if there is none.

Parameters:

layer

The layer children of which are used. Pass -1 to use the topmost layer.

getChildIndexInLayer(o:Object):Int

Return the index of the child within its respective layer.

Parameters:

o

The child to look up index of.

Returns:

-1 if object is not a child of Layers, index of the child within its current layer otherwise.

getChildLayer(s:Object):Int

Returns the layer on which the child s resides on.

Parameters:

s

An object to look up to.

Returns:

An index of the layer where the object resides on or -1 if s is not a child of the Layers.

getLayer(layer:Int):Iterator<Object>

Returns an Iterator with objects in a specified layer. Returns an empty iterator if no objects are present in the layer.

Objects added or removed from Layers during iteration do not affect the output of the Iterator.

Parameters:

layer

A layer index to iterate over.

over(s:Object):Void

Moves an object s to the top of its layer (rendered last, in front of other Objects in layer). Causes Object.onHierarchyMoved on the Object.

Parameters:

s

An object to be moved.

under(s:Object):Void

Moves an object s to the bottom of its layer (rendered first, behind the other Objects in the layer). Causes Object.onHierarchyMoved on the Object.

Parameters:

s

An object to be moved.

ysort(layer:Int):Void

Sorts specified layer based on Object.y value of it's children. Causes Object.onHierarchyChanged on moved children.

Parameters:

layer

An index of the layer to sort.

Defined by Object

private@:dox(show)addBounds(relativeTo:Object, out:Bounds, dx:Float, dy:Float, width:Float, height:Float):Void

Adds specified area in local coordinate space to the bounds. Expected to be used within Object.getBoundsRec.

Parameters:

relativeTo

An object relative to which the Object bounds coordinates should be. If not set, coordinates are in absolute coordinate space.

out

An output Bounds instance.

dx

The top-left X offset of the added bounds rectangle.

dy

The top-left Y offset of the added bounds rectangle.

width

The width of the added bounds rectangle.

height

The height of the added bounds rectangle.

private@:dox(show)calcAbsPos():Void

Internal usage Calculates the absolute object position transform. See `Object.syncPos` for a safe position sync method. This method does not ensure that object parents also have up-to-date transform nor does it clear the `Object.posChanged` flag.

private@:value({ scaleY : 1., scaleX : 1. })@:dox(show)clipBounds(ctx:RenderContext, bounds:Bounds, scaleX:Float = 1., scaleY:Float = 1.):Void

Internal usage Clip the local bounds with our global viewport. Used during filter rendering in order to clip out areas that are off-screen and should not be rendered.

h2d.Scene note: clipBounds will always output bounds equivalent to entire window. This is done in order for scene to never clip out cameras as they may render virtually any area of the Scene.

private@:dox(show)constraintSize(maxWidth:Float, maxHeight:Float):Void

Advanced usage This can be called by a parent container to constraint the size of its children. Negative value mean that constraint is to be disabled.

For example, Text constraints it's maximum width, causing word-wrap to occur within constrained area.

See also:

contains(o:Object):Bool

Tells if the object is contained into this object children, recursively.

private@:dox(show)contentChanged(s:Object):Void

Advanced usage Called by the children of a container object if they have `parentContainer` defined in them. Primary use-case is when the child size got changed, requiring content to reevaluate positioning such as `Flow` layouts, but also can be used for other purposes.

private@:dox(show)draw(ctx:RenderContext):Void

Override this method in order to add custom graphics rendering to your Object. draw is invoked before rendering of the object children.

drawTo(t:Texture):Void

Draw the object and all its children into the given Texture.

drawToTextures(texs:Array<Texture>, outputs:Array<Output>):Void

Draw the object and all its children into the given Textures.

private@:dox(show)emitTile(ctx:RenderContext, tile:Tile):Void

Draws single Tile instance with this Object transform.

find<T>(f:Object ‑> Null<T>):Null<T>

Find a single object in the tree by calling f on each and returning the first not-null value returned, or null if not found.

findAll<T>(f:Object ‑> Null<T>, ?arr:Array<T>):Array<T>

Find several objects in the tree by calling f on each and returning all the not-null values returned.

Parameters:

arr

An optional array instance to fill results with. Allocates a new array if not set.

inlinegetAbsPos():Matrix

Returns the updated absolute position matrix. See Object.getMatrix for current matrix values.

getBounds(?relativeTo:Object, ?out:Bounds):Bounds

Return the bounds of the object for its whole content, recursively.

Parameters:

relativeTo

An optional object relative to coordinates of which bounds are returned. Returns bounds in the absolute coordinates if not set.

out

An optional bounds instance to fill. Allocates new Bounds instance and returns it if not set.

private@:dox(show)getBoundsRec(relativeTo:Object, out:Bounds, forSize:Bool):Void

Override this method in order to expand the reported bounds of an object. Object.addBounds can be used to add bounds with respect to relativeTo. Do not remove the super call.

Parameters:

relativeTo

An object relative to which the Object bounds coordinates should be.

out

An output Bounds instance.

forSize

Whether it's being called for Object.getSize or Object.getBounds.

getChildAt(n:Int):Object

Return the nth element among the immediate children list of this object, or null if there is no Object at this position.

getChildIndex(o:Object):Int

Return the index of the object o within the immediate children list of this object, or -1 if it is not part of the children list.

private@:dox(show)getMatrix(m:Matrix):Void

Populates m with current absolute object transform values. See Object.getAbsPos for up-to-date values.

getObjectByName(name:String):Object

Search for an object recursively by name, return null if not found.

getObjectsCount():Int

Return the total number of children in the whole tree, recursively.

getScene():Scene

Returns an h2d.Scene down the hierarchy tree or null if object is not added to Scene.

finalgetSize(?out:Bounds):Bounds

Similar to getBounds(parent), but instead of the full content, it will return the size based on the alignment of the object. For instance for a text, Object.getBounds will return the full glyphs size whereas getSize will ignore the pixels under the baseline.

Parameters:

out

An optional bounds instance to fill. Allocates new Bounds instance and returns it if not set.

globalToLocal(pt:Point):Point

Convert an absolute screen position into a local position relative to the object origin, applying all the inherited transforms.

Parameters:

pt

A position to convert and return. Modifies the Point instance as is.

inlineiterator():ArrayIterator_h2d_Object

Return an iterator over this object immediate children

localToGlobal(?pt:Point):Point

Convert a local position (or [0,0] if pt is null) relative to the object origin into an absolute screen position, applying all the inherited transforms.

Parameters:

pt

An optional position to convert and return. Allocates new Point at 0,0 position if not set. Modifies the Point instance as is.

move(dx:Float, dy:Float):Void

Move the object by the specified amount along its current direction (Object.rotation angle).

private@:dox(show)onAdd():Void

Sent when object is being added to an allocated scene.

Do not remove the super call when overriding.

private@:dox(show)inlineonContentChanged():Void

Should be called when Object content was changed in order to notify parent container. See Object.contentChanged.

private@:dox(show)onHierarchyMoved(parentChanged:Bool):Void

Sent when object was already allocated and moved within scene object tree hierarchy.

Do not remove the super call when overriding.

Parameters:

parentChanged

Whether Object was moved withing same parent (through Layers.ysort for example) or relocated to a new one.

private@:dox(show)onRemove():Void

Sent when object is removed from the allocated scene.

Do not remove the super call when overriding.

inlineremove():Void

Same as parent.removeChild(this), but does nothing if parent is null.

removeChildren():Void

Remove all children from the immediate children list.

inlinerotate(v:Float):Void

Rotate the object by the given angle (in radians)

inlinescale(v:Float):Void

Scale uniformly the object by the given factor.

private@:dox(show)setParentContainer(c:Object):Void

Sets the parent container for this Object and it's children. See Object.contentChanged for more details.

inlinesetPosition(x:Float, y:Float):Void

Set the position of the object relative to its parent.

inlinesetScale(v:Float):Void

Set the uniform scale for the object.

private@:dox(show)sync(ctx:RenderContext):Void

Performs a sync of data for rendering (such as absolute position recalculation). While this method can be used as a substitute to an update loop, it's primary purpose it to prepare the Object to be rendered.

Do not remove the super call when overriding.

private@:dox(show)syncPos():Void

Ensures that object has an up-to-date position transform.