Fork me on GitHub
View source

package haxepunk

class Scene


extends Tweener
extended by Console

Updated by Engine, main game container that holds all currently active Entities. Useful for organization, eg. "Menu", "Level1", etc.

Constructor

View source

new () : Void

Constructor.

Variables

assetCache : AssetCache

Scene-scoped asset cache. These assets will be destroyed when the scene ends.

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

bgColor : Null<Color>

Background color of this Scene. If null, will use HXP.stage.color.


Available since:

2.6.0

camera : Camera

Point used to determine drawing offset in the render loop.

read only count : Int

How many Entities are in the Scene.

read only farthest : Entity

The Entity that will be rendered first by the Scene.

read only first : Entity

The first Entity in the Scene.

height : Null<Int>

read only layerFarthest : Int

The layer that will be rendered first by the Scene.

read only layerNearest : Int

The layer that will be rendered last by the Scene.

read only layers : Int

How many Entity layers the Scene has.

read only mouseX : Int

X position of the mouse in the Scene.

read only mouseY : Int

Y position of the mouse in the scene.

read only nearest : Entity

The Entity that will be rendered last by the scene.

onInputPressed : Signals

Invoked when input is received while this Scene is active.

onInputReleased : Signals

Invoked when input is received while this Scene is active.

onResize : Signal0

Invoked after this Scene is resized.

postRender : Signal0

Invoked after rendering this Scene completes.

postUpdate : Signal0

Invoked after this Scene's update cycle.

preRender : Signal0

Invoked before rendering begins for this Scene each frame.

preUpdate : Signal0

Invoked before this Scene's update cycle begins each frame.

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

trackDrawCalls : Bool

Whether or not to track draw calls for this scene


Available since:

4.0.0

read only uniqueTypes : Int

How many different types have been added to the Scene.

visible : Bool

If the render() loop is performed.

width : Null<Int>

x : Int

y : Int

Functions

View source

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.

View source

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.

View source

addList<E> (list : Iterable<E>) : Void

Adds multiple Entities to the scene.


Parameters:
...list   

Several Entities (as arguments) or an Array/Vector of Entities.

View source

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.

View source

begin () : Void

Override this; called when Scene is switch to, and set to the currently active scene.

View source

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.

View source

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.

View source

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.

View source

classFirst<E> (c : Class<E>) : E

The first Entity of the Class.


Parameters:
c   

The Class type to check.


Returns:

The Entity.

View source

clearRecycled<E> (classType : Class<E>) : Void

Clears stored reycled Entities of the Class type.


Parameters:
classType   

The Class type to clear.

View source

clearRecycledAll () : Void

Clears stored recycled Entities of all Class types.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

end () : Void

Override this; called when Scene is changed, and the active scene is no longer this.

View source

entitiesForType (type : String) : List<Entity>

A list of Entity objects of the type.


Parameters:
type   

The type to check.


Returns:

The Entity list.

View source

focusGained () : Void

Override this, called when game gains focus

View source

focusLost () : Void

Override this, called when game loses focus

View source

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.

View source

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.

View source

getInstance (name : String) : Null<Entity>

Returns the Entity with the instance name, or null if none exists


Parameters:
name   

Returns:

The Entity.

View source

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.

View source

getTexture (id : String) : Texture

View source

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.

View source

isAtBack (e : Entity) : Bool

If the Entity as at the back of its layer.


Parameters:
e   

The Entity to check.


Returns:

True or false.

View source

isAtFront (e : Entity) : Bool

If the Entity as at the front of its layer.


Parameters:
e   

The Entity to check.


Returns:

True or false.

View source

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.

View source

layerFirst (layer : Int) : Entity

The first Entity on the Layer.


Parameters:
layer   

The layer to check.


Returns:

The Entity.

View source

layerLast (layer : Int) : Entity

The last Entity on the Layer.


Parameters:
layer   

The layer to check.


Returns:

The Entity.

View source

layerVisible (layer : Int) : Bool

Checks if a layer is visible or not

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

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.

View source

removeAll () : Void

Removes all Entities from the Scene at the end of the frame.

View source

removeList<E> (list : Iterable<E>) : Void

Removes multiple Entities from the scene.


Parameters:
...list   

Several Entities (as arguments) or an Array/Vector of Entities.

View source

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.

View source

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.

View source

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.

View source

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)

View source

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.

View source

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.

View source

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.