class Scene
package h2d
extends Layers › Object
implements InteractiveScene, IDrawable
extended by LoadingScene
The root class for a 2D scene. All root objects are added to it before being drawn on screen.
Constructor
Variables
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.
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
.
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.
Methods
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.
getInteractive(x:Float, y:Float):Interactive
Returns the topmost visible Interactive at the specified coordinates.
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
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 |
---|---|
onCancel | An optional callback that is invoked when |
refEvent | For touch events, when defined, only capture events that match the reference |
syncOnly(et:Float):Void
Synchronize the scene without rendering, updating all objects and animations by the given amount of time, in seconds.