Updated by Engine
, main game container that holds all currently active Entities.
Useful for organization, eg. "Menu", "Level1", etc.
Constructor
Variables
batch : DrawCommandBatch
bgAlpha : Float
Background opacity. If less than 1, Scenes behind this Scene in the stack will be rendered underneath.
Available since:
2.6.0
height : Null<Int>
shaders : Null<Array<SceneShader>>
Array of shaders which will be used to process the final result of rendering this scene. GL targets (desktop, mobile, HTML5) only.
Available since:
4.0.0
width : Null<Int>
x : Int
y : Int
Functions
add<E> (e : E) : E
Adds the Entity to the Scene at the end of the frame.
Parameters:
e | Entity object you want to add. |
Returns:
The added Entity object.
addGraphic (graphic : Graphic, layer : Int = 0, x : Float = 0, y : Float = 0) : Entity
Adds an Entity to the Scene with the Graphic object.
Parameters:
graphic | Graphic to assign the Entity. | |
x | X position of the Entity. | |
y | Y position of the Entity. | |
layer | Layer of the Entity. |
Returns:
The Entity that was added.
addList<E> (list : Iterable<E>) : Void
Adds multiple Entities to the scene.
Parameters:
...list | Several Entities (as arguments) or an Array/Vector of Entities. |
addMask (mask : Mask, type : String, x : Int = 0, y : Int = 0) : Entity
Adds an Entity to the Scene with the Mask object.
Parameters:
mask | Mask to assign the Entity. | |
type | Collision type of the Entity. | |
x | X position of the Entity. | |
y | Y position of the Entity. |
Returns:
The Entity that was added.
begin () : Void
Override this; called when Scene is switch to, and set to the currently active scene.
bringForward (e : Entity) : Bool
Shifts the Entity one place towards the front of its contained layer.
Parameters:
e | The Entity to shift. |
Returns:
If the Entity changed position.
bringToFront (e : Entity) : Bool
Brings the Entity to the front of its contained layer.
Parameters:
e | The Entity to shift. |
Returns:
If the Entity changed position.
classCount (c : String) : Int
Returns the amount of Entities of the Class are in the Scene.
Parameters:
c | The Class type to count. |
Returns:
How many Entities of Class exist in the Scene.
classFirst<E> (c : Class<E>) : E
The first Entity of the Class.
Parameters:
c | The Class type to check. |
Returns:
The Entity.
clearRecycled<E> (classType : Class<E>) : Void
Clears stored reycled Entities of the Class type.
Parameters:
classType | The Class type to clear. |
collideCircleInto<E> (type : String, circleX : Float, circleY : Float, radius : Float, into : Array<E>) : Void
Populates an array with all Entities that collide with the circle. This function does not empty the array, that responsibility is left to the user.
Parameters:
type | The Entity type to check for. | |
circleX | X position of the circle. | |
circleY | Y position of the circle. | |
radius | The radius of the circle. | |
into | The Array or Vector to populate with collided Entities. |
collideLine (type : String, fromX : Int, fromY : Int, toX : Int, toY : Int, precision : Int = 1, ?p : Vector2) : Entity
Returns the first Entity found that collides with the line.
Parameters:
type | The Entity type to check for. | |
fromX | Start x of the line. | |
fromY | Start y of the line. | |
toX | End x of the line. | |
toY | End y of the line. | |
precision | Distance between consecutive tests. Higher values are faster but increase the chance of missing collisions. | |
p | If non-null, will have its x and y values set to the point of collision. |
Returns:
The first Entity to collide, or null if none collide.
collidePoint (type : String, pX : Float, pY : Float) : Entity
Returns the first Entity found that collides with the position.
Parameters:
type | The Entity type to check for. | |
pX | X position. | |
pY | Y position. |
Returns:
The collided Entity, or null if none collide.
collidePointInto<E> (type : String, pX : Float, pY : Float, into : Array<E>, cameraAdjust : Bool = false) : Void
Populates an array with all Entities that collide with the position. This function does not empty the array, that responsibility is left to the user.
Parameters:
type | The Entity type to check for. | |
pX | X position. | |
pY | Y position. | |
into | The Array or Vector to populate with collided Entities. |
collideRect (type : String, rX : Float, rY : Float, rWidth : Float, rHeight : Float) : Entity
Returns the first Entity that collides with the rectangular area.
Parameters:
type | The Entity type to check for. | |
rX | X position of the rectangle. | |
rY | Y position of the rectangle. | |
rWidth | Width of the rectangle. | |
rHeight | Height of the rectangle. |
Returns:
The first Entity to collide, or null if none collide.
collideRectInto<E> (type : String, rX : Float, rY : Float, rWidth : Float, rHeight : Float, into : Array<E>) : Void
Populates an array with all Entities that collide with the rectangle. This function does not empty the array, that responsibility is left to the user.
Parameters:
type | The Entity type to check for. | |
rX | X position of the rectangle. | |
rY | Y position of the rectangle. | |
rWidth | Width of the rectangle. | |
rHeight | Height of the rectangle. | |
into | The Array or Vector to populate with collided Entities. |
create<E> (classType : Class<E>, addToScene : Bool = true, constructorsArgs : Array<Dynamic>) : E
Returns a new Entity, or a stored recycled Entity if one exists.
Note: The constructor is only called when creating a new entity, when using a recycled one the constructor (with constructorsArgs) isn't called. Instead use a function to initialize your entities.
Parameters:
classType | The Class of the Entity you want to add. | |
addToScene | Add it to the Scene immediately. | |
constructorsArgs | List of the entity constructor arguments (optional). |
Returns:
The new Entity object.
end () : Void
Override this; called when Scene is changed, and the active scene is no longer this.
entitiesForType (type : String) : List<Entity>
A list of Entity objects of the type.
Parameters:
type | The type to check. |
Returns:
The Entity list.
getAll<E> (into : Array<E>) : Void
Pushes all Entities in the Scene into the array. This function does not empty the array, that responsibility is left to the user.
Parameters:
into | The Array or Vector to populate. |
getClass<T, E> (c : Class<T>, into : Array<E>) : Void
Pushes all Entities in the Scene of the Class into the Array or Vector. This function does not empty the array, that responsibility is left to the user.
Parameters:
c | The Class type to check. | |
into | The Array or Vector to populate. |
getInstance (name : String) : Null<Entity>
Returns the Entity with the instance name, or null if none exists
Parameters:
name |
Returns:
The Entity.
getLayer<E> (layer : Int, into : Array<E>) : Void
Pushes all Entities in the Scene on the layer into the Array or Vector. This function does not empty the array, that responsibility is left to the user.
Parameters:
layer | The layer to check. | |
into | The Array or Vector to populate. |
getType<E> (type : String, into : Array<E>) : Void
Pushes all Entities in the Scene of the type into the Array or Vector. This function does not empty the array, that responsibility is left to the user.
Parameters:
type | The type to check. | |
into | The Array or Vector to populate. |
If the Entity as at the back of its layer.
Parameters:
e | The Entity to check. |
Returns:
True or false.
If the Entity as at the front of its layer.
Parameters:
e | The Entity to check. |
Returns:
True or false.
layerCount (layer : Int) : Int
Returns the amount of Entities are on the layer in the Scene.
Parameters:
layer | The layer to count Entities on. |
Returns:
How many Entities are on the layer.
layerFirst (layer : Int) : Entity
The first Entity on the Layer.
Parameters:
layer | The layer to check. |
Returns:
The Entity.
layerLast (layer : Int) : Entity
The last Entity on the Layer.
Parameters:
layer | The layer to check. |
Returns:
The Entity.
nearestToClass<T> (type : String, e : Entity, classType : Class<T>, useHitboxes : Bool = false) : Entity
Finds the Entity nearest to another.
Parameters:
type | The Entity type to check for. | |
e | The Entity to find the nearest to. | |
classType | The Entity class to check for. | |
useHitboxes | If the Entities' hitboxes should be used to determine the distance. If false, their x/y coordinates are used. |
Returns:
The nearest Entity to e.
nearestToEntity (type : String, e : Entity, useHitboxes : Bool = false) : Entity
Finds the Entity nearest to another.
Parameters:
type | The Entity type to check for. | |
e | The Entity to find the nearest to. | |
useHitboxes | If the Entities' hitboxes should be used to determine the distance. If false, their x/y coordinates are used. |
Returns:
The nearest Entity to e.
nearestToPoint (type : String, x : Float, y : Float, useHitboxes : Bool = false) : Entity
Finds the Entity nearest to the position.
Parameters:
type | The Entity type to check for. | |
x | X position. | |
y | Y position. | |
useHitboxes | If the Entities' hitboxes should be used to determine the distance. If false, their x/y coordinates are used. |
Returns:
The nearest Entity to the position.
nearestToRect (type : String, x : Float, y : Float, width : Float, height : Float) : Entity
Finds the Entity nearest to the rectangle.
Parameters:
type | The Entity type to check for. | |
x | X position of the rectangle. | |
y | Y position of the rectangle. | |
width | Width of the rectangle. | |
height | Height of the rectangle. |
Returns:
The nearest Entity to the rectangle.
recycle<E> (e : E) : E
Removes the Entity from the Scene at the end of the frame and recycles it. The recycled Entity can then be fetched again by calling the create() function.
Parameters:
e | The Entity to recycle. |
Returns:
The recycled Entity.
remove<E> (e : E) : E
Removes the Entity from the Scene at the end of the frame.
Parameters:
e | Entity object you want to remove. |
Returns:
The removed Entity object.
removeList<E> (list : Iterable<E>) : Void
Removes multiple Entities from the scene.
Parameters:
...list | Several Entities (as arguments) or an Array/Vector of Entities. |
render () : Void
Performed by the game loop, renders all contained Entities. If you override this to give your Scene render code, remember to call super.render() or your Entities will not be rendered.
sendBackward (e : Entity) : Bool
Shifts the Entity one place towards the back of its contained layer.
Parameters:
e | The Entity to shift. |
Returns:
If the Entity changed position.
sendToBack (e : Entity) : Bool
Sends the Entity to the back of its contained layer.
Parameters:
e | The Entity to shift. |
Returns:
If the Entity changed position.
showLayer (layer : Int, show : Bool = true) : Void
Toggles the visibility of a layer
Parameters:
layer | the layer to show/hide | |
show | whether to show the layer (default: true) |
typeCount (type : String) : Int
Returns the amount of Entities of the type are in the Scene.
Parameters:
type | The type (or Class type) to count. |
Returns:
How many Entities of type exist in the Scene.
update () : Void
Performed by the game loop, updates all contained Entities. If you override this to give your Scene update code, remember to call super.update() or your Entities will not be updated.
updateLists (shouldAdd : Bool = true) : Void
Updates the add/remove lists at the end of the frame.
Parameters:
shouldAdd | If new Entities should be added to the scene. |