Libraries.Game.Layer2D Documentation
The Layer2D class is used to manage a number of 2D objects, as well as manage input. The Layer2D effectively consists of a 2D "world", where all objects added to it exist in the same space and can interact with each other.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable box
box:LoadFilledRectangle(50, 50)
box:SetPosition(100, 100)
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(box)
layer:Add(circle)
AddLayer(layer)
end
action Update(number seconds)
end
end
Inherits from: Libraries.Language.Object, Libraries.Game.Layer
Summary
Actions Summary Table
Actions | Description |
---|---|
Add(integer index, Libraries.Interface.Item2D item) | This action will add an Item2D to this Layer's array of items at the index location. |
Add(Libraries.Interface.Item2D item) | This action will add an Item2D to this Layer. |
AddCollisionListener(Libraries.Interface.Events.CollisionListener2D listener) | AddCollisionListener will add a collision listener to this layer. |
AddJoint(Libraries.Game.Physics.Joints.Joint2D joint) | This action will add an Item2D to this Layer. |
AddMouseListener(Libraries.Interface.Events.MouseListener listener) | This action will add a MouseListener to the layer. |
AddMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener) | This action will add a MouseMovementListener to the layer. |
AddMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener) | This action will add a MouseWheelListener to the layer. |
AddToFront(Libraries.Interface.Item2D item) | This action will add an Item2D to this layer's array of items at index 0. |
AddTouchListener(Libraries.Interface.Events.TouchListener listener) | This action will add a TouchListener to the layer. |
AutomaticallyClearForces() | This action will add a MouseWheelListener to the layer. |
ClearForces() | This action will remove all TouchListeners from the layer. |
Compare(Libraries.Language.Object object) | This action compares two object hash codes and returns an integer. |
Draw() | This action will draw all items in this Layer on the screen (if they can be drawn and they aren't hidden). |
Empty() | This action will clear all the items in this layer. |
EmptyMouseListeners() | This action will remove all MouseListeners from the layer. |
EmptyMouseMovementListeners() | This action will remove all MouseMovementListeners from the layer. |
EmptyMouseWheelListeners() | This action will remove all MouseWheelListeners from the layer. |
EmptyTouchListeners() | This action will remove all TouchListeners from the layer. |
EnablePhysics(boolean flag) | This action will remove an Item2D from this layer. |
Equals(Libraries.Language.Object object) | This action determines if two objects are equal based on their hash code values. |
Get(integer index) | This action will get an Item2D stored in the layer at the given index in the layer's internal array of items. |
GetAutomaticResizing() | This action returns whether or not the Layer will automatically respond to ResizeEvents. |
GetCamera() | This action will return the camera being used by this Layer. |
GetCollisionList() | This action gets the list of items on this layer that are colliding and returns it as an array. |
GetCollisionManager() | This action gets the collision manager for this object which is responsible for managing the collisions between all colliding items on this layer. |
GetFromEnd() | This action will return the item stored at the end of the layer's array of items. |
GetFromFront() | This action will return the Item2D at the front of the layer's array of items. |
GetGravity() | This action will remove a MouseListener from the layer. |
GetHashCode() | This action gets the hash code for an object. |
GetInterfaceScale() | |
GetItemWithInput(number x, number y, Libraries.Containers.Array<Libraries.Game.InputSet> inputValues) | This action finds an Item on this layer which is present at the given coordinates and will respond to at least one of the given InputSets. |
GetIterator() | This action will return an iterator of all the Item2D's stored inside this layer's array of items. |
GetLayout() | |
GetName() | This action returns the name of the Layer. |
GetPainter() | This actions sets the viewport that will be used by this Layer, and adjusts the Layer's camera to match the dimensions of the viewport. |
GetSimulationThreshold() | Call this action if you want to manually tell the layer to turn off depth buffer sorting. |
GetSize() | This action will return the number of items that have been added to this layer. |
GetViewportHeight() | This action will hide the Layer. |
GetViewportWidth() | This action will show the Layer. |
GetViewportX() | This action sets the viewport that will be used by this Layer. |
GetViewportY() | This action will return if the current layer is currently visible or not. |
Hide() | This action will hide the Layer. |
IsColliding() | This allows us to know if collisions are on or off for the layer. |
IsContinuousPhysics() | This action will remove a TouchListener from the layer. |
IsDepthBufferSorting() | Call this action if you want to learn if depth buffer sorting is on. |
IsEmpty() | This action will return false if there are items stored in this layer's array of items, or true if there are none. |
IsShowing() | This action will return if the current layer is currently visible or not. |
IsSimulationRequired() | This action gets the list of items on this layer that are colliding and returns it as an array. |
IsSubStepping() | AddCollisionListener will add a collision listener to this layer. |
IsWarmStarting() | This action will remove all MouseMovementListeners from the layer. |
PhysicsEnabled() | This action will clear all the items in this layer. |
ProcessMouseEvent(Libraries.Interface.Events.MouseEvent event) | This action will notify mouse listeners that are a part of this layer of the given mouse event. |
ProcessTouchEvent(Libraries.Interface.Events.TouchEvent event) | This action will notify touch listeners that are a part of this layer of the given touch event. |
Remove(Libraries.Interface.Item2D item) | This action will remove an Item2D from this layer. |
RemoveAt(integer index) | This action will remove an Item2D at the index location from this layer's array of items, and return the item that was removed. |
RemoveCollisionListener(Libraries.Interface.Events.CollisionListener2D listener) | RemoveCollisionListener removes a collision listener to this layer. |
RemoveFromEnd() | This action will remove an Item2D from the end of the array of items in the layer, and return the item that was removed. |
RemoveFromFront() | This action will remove an Item2D from the front of the array of items in this layer, and return the item that was removed. |
RemoveJoint(Libraries.Game.Physics.Joints.Joint2D joint) | This allows us to turn collisions on or off for the layer. |
RemoveMouseListener(Libraries.Interface.Events.MouseListener listener) | This action will remove a MouseListener from the layer. |
RemoveMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener) | This action will remove a MouseMovementListener from the layer. |
RemoveMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener) | This action will remove a MouseWheelListener from the layer. |
RemoveTouchListener(Libraries.Interface.Events.TouchListener listener) | This action will remove a TouchListener from the layer. |
RequireSimulation(boolean flag) | This action indicates that the layer has received a new item that it must manage during collision detection. |
Resize(Libraries.Interface.Events.ResizeEvent event) | Call this action if you want to learn if depth buffer sorting is on. |
Set(integer index, Libraries.Interface.Item2D item) | This action will set the value of the given index in the layer's array of items to be the given Item2D. |
SetAutomaticResizing(boolean resizing) | This action sets if the Layer should automatically respond to ResizeEvents. |
SetAutomaticallyClearForces(boolean flag) | This action will add a TouchListener to the layer. |
SetCamera(Libraries.Game.Graphics.Camera cam) | This action will set the camera being used by this Layer. |
SetColliding(boolean collide) | This allows us to turn collisions on or off for the layer. |
SetColorFilter(Libraries.Game.Graphics.Color color) | Using SetColorFilter will tint all drawn objects on the layer that do not have their own custom color tint. |
SetColorFilter(number red, number green, number blue, number alpha) | SetColorFilter can be called using four number parameters instead of a color object. |
SetContinuousPhysics(boolean flag) | This action will remove all MouseListeners from the layer. |
SetDepthBufferSorting(boolean sort) | Call this action if you want to manually tell the layer to turn off depth buffer sorting. |
SetGravity(Libraries.Compute.Vector2 gravity) | This action will remove a MouseWheelListener from the layer. |
SetGravity(number gravityX, number gravityY) | This action will remove a MouseMovementListener from the layer. |
SetInterfaceScale(number scale) | |
SetLayout(Libraries.Interface.Layouts.Layout layout) | |
SetName(text name) | This action sets the name of the Layer. |
SetNewItemAdded(boolean flag) | This action indicates that the layer has received a new item that it must manage during collision detection. |
SetPainter(Libraries.Game.Graphics.Painter2D painter) | |
SetSimulationThreshold(number threshold) | This allows us to know if collisions are on or off for the layer. |
SetSubStepping(boolean flag) | RemoveCollisionListener removes a collision listener to this layer. |
SetViewport(integer x, integer y, integer width, integer height) | This action sets the viewport that will be used by this Layer. |
SetViewportAndCamera(integer x, integer y, integer width, integer height) | This actions sets the viewport that will be used by this Layer, and adjusts the Layer's camera to match the dimensions of the viewport. |
SetWarmStarting(boolean flag) | This action will remove all MouseWheelListeners from the layer. |
Show() | This action will show the Layer. |
TestForCollisions(number seconds) | This action triggers collision detection for this layer during a frame in the Game engine. |
Update(number seconds) | This action will update all of the items contained within this Layer. |
Actions Documentation
Add(integer index, Libraries.Interface.Item2D item)
This action will add an Item2D to this Layer's array of items at the index location. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item2D).
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
// Item2D objects aren't visible, but can still be used for game logic.
Item2D area
area:SetSize(50, 50)
area:SetPosition(100, 100)
// Drawables inherit from Item2D, so they can be added too.
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(0, area)
layer:Add(1, circle)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- integer index: The index to store the item at in the layer's array of items.
- Libraries.Interface.Item2D: The Item2D to be added to this layer.
Add(Libraries.Interface.Item2D item)
This action will add an Item2D to this Layer. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item2D). The Item2D will be added to the back of the layer's internal array of items.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
// Item2D objects aren't visible, but can still be used for game logic.
Item2D area
area:SetSize(50, 50)
area:SetPosition(100, 100)
// Drawables inherit from Item2D, so they can be added too.
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(area)
layer:Add(circle)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Item2D: The Item2D to be added to the layer.
AddCollisionListener(Libraries.Interface.Events.CollisionListener2D listener)
AddCollisionListener will add a collision listener to this layer. The collision listener will be notified of collisions occuring on this layer, and is responsible for managing the collision events.
Parameters
AddJoint(Libraries.Game.Physics.Joints.Joint2D joint)
This action will add an Item2D to this Layer. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item2D). The Item2D will be added to the back of the layer's internal array of items.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
// Item2D objects aren't visible, but can still be used for game logic.
Item2D area
area:SetSize(50, 50)
area:SetPosition(100, 100)
// Drawables inherit from Item2D, so they can be added too.
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(area)
layer:Add(circle)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
AddMouseListener(Libraries.Interface.Events.MouseListener listener)
This action will add a MouseListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseListener.
MouseListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseListener: The MouseListener to add to this layer.
AddMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener)
This action will add a MouseMovementListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseMovementListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseMovementListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseMovementListener.
MouseMovementListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseMovementListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseMovementListener: The MouseMovementListener to add to this layer.
AddMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener)
This action will add a MouseWheelListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseWheelListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseWheelListener: The MouseWheelListener to add to this layer.
AddToFront(Libraries.Interface.Item2D item)
This action will add an Item2D to this layer's array of items at index 0. It will be updated along with the rest of the layer, and will be drawn on the screen (if it is visible and possible to draw the given Item2D). Adding an item to the front will cause it to be drawn and updated before other items in the layer, and other drawn items will appear to be on top of it.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
// Item2D objects aren't visible, but can still be used for game logic.
Item2D area
area:SetSize(50, 50)
area:SetPosition(100, 100)
// Drawables inherit from Item2D, so they can be added too.
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:AddToFront(area)
layer:AddToFront(circle)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Item2D: The item to add to the front of the layer's item array.
AddTouchListener(Libraries.Interface.Events.TouchListener listener)
This action will add a TouchListener to the layer. When the layer receives a touch event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all TouchListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.TouchListener: The TouchListener to add to this layer.
AutomaticallyClearForces()
This action will add a MouseWheelListener to the layer. When the layer receives a mouse event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all MouseWheelListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Return
boolean:
ClearForces()
This action will remove all TouchListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
layer:EmptyTouchListeners()
end
action Update(number seconds)
end
end
Compare(Libraries.Language.Object object)
This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.
Example Code
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Draw()
This action will draw all items in this Layer on the screen (if they can be drawn and they aren't hidden). If the Layer is currently hidden, then this action will do nothing. This is automatically called by the Game class as needed. Most users will never need to use this action directly.
Empty()
This action will clear all the items in this layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
layer:Empty()
end
action Update(number seconds)
end
end
EmptyMouseListeners()
This action will remove all MouseListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseListener.
MouseListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseListener(myListener)
AddLayer(layer)
layer:EmptyMouseListeners()
end
action Update(number seconds)
end
end
EmptyMouseMovementListeners()
This action will remove all MouseMovementListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseMovementListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseMovementListener.
MouseMovementListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseMovementListener(myListener)
AddLayer(layer)
layer:EmptyMouseMovementListeners()
end
action Update(number seconds)
end
end
EmptyMouseWheelListeners()
This action will remove all MouseWheelListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
layer:EmptyMouseWheelListeners()
end
action Update(number seconds)
end
end
EmptyTouchListeners()
This action will remove all TouchListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
layer:EmptyTouchListeners()
end
action Update(number seconds)
end
end
EnablePhysics(boolean flag)
This action will remove an Item2D from this layer. If the item was not a part of this layer, this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
layer:Remove(circle)
end
action Update(number seconds)
end
end
Parameters
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Example Code
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Get(integer index)
This action will get an Item2D stored in the layer at the given index in the layer's internal array of items.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:Get(0)
end
action Update(number seconds)
end
end
Parameters
- integer index: The index to retrieve an item from in the layer's array of items.
Return
Libraries.Interface.Item2D: The Item2D stored at the index in the array.
GetAutomaticResizing()
This action returns whether or not the Layer will automatically respond to ResizeEvents. If this value is true, then the Layer will automatically adjust the camera and resize Items on the Layer when a ResizeEvent occurs.
Return
boolean:
GetCamera()
This action will return the camera being used by this Layer. The camera is used to determine what will be drawn on the screen. Objects will be drawn on the screen as they are seen by the Layer's set camera.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Camera
class Main is Game
Camera layerCamera = undefined
action Main
StartGame()
end
action CreateGame
Layer2D layer
layerCamera = layer:GetCamera()
AddLayer(layer)
end
action Update(number seconds)
end
end
Return
Libraries.Game.Graphics.Camera: The camera currently being used by this layer.
GetCollisionList()
This action gets the list of items on this layer that are colliding and returns it as an array.
Return
Libraries.Interface.Events.CollisionEvent2D:
GetCollisionManager()
This action gets the collision manager for this object which is responsible for managing the collisions between all colliding items on this layer.
Return
Libraries.Game.Collision.CollisionManager2D:
GetFromEnd()
This action will return the item stored at the end of the layer's array of items.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:GetFromEnd()
end
action Update(number seconds)
end
end
Return
Libraries.Interface.Item2D: The last item in the layer's array of items.
GetFromFront()
This action will return the Item2D at the front of the layer's array of items. This is functionally the same as calling "Get(0)".
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:GetFromFront()
end
action Update(number seconds)
end
end
Return
Libraries.Interface.Item2D: The first item in the layer's array of items.
GetGravity()
This action will remove a MouseListener from the layer. The listener will no longer receive events from the layer. If the given MouseListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseListener.
MouseListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseListener(myListener)
AddLayer(layer)
layer:RemoveMouseListener(myListener)
end
action Update(number seconds)
end
end
Return
GetHashCode()
This action gets the hash code for an object.
Example Code
Object o
integer hash = o:GetHashCode()
Return
integer: The integer hash code of the object.
GetInterfaceScale()
Return
number
GetItemWithInput(number x, number y, Libraries.Containers.Array<Libraries.Game.InputSet> inputValues)
This action finds an Item on this layer which is present at the given coordinates and will respond to at least one of the given InputSets.
Parameters
Return
GetIterator()
This action will return an iterator of all the Item2D's stored inside this layer's array of items.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Containers.Iterator
class Main is Game
action Main
StartGame()
end
action CreateGame
Item2D item1
Item2D item2
Item2D item3
Layer2D layer
layer:Add(item1)
layer:Add(item2)
layer:Add(item3)
AddLayer(layer)
Iterator<Item2D> itemIterator = layer:GetIterator()
end
action Update(number seconds)
end
end
Return
Libraries.Containers.Iterator: An iterator containing all Item2D's stored in this layer.
GetLayout()
Return
Libraries.Interface.Layouts.Layout:
GetName()
This action returns the name of the Layer. This is used to identify the layer, especially in the Scene system.
Return
text:
GetPainter()
This actions sets the viewport that will be used by this Layer, and adjusts the Layer's camera to match the dimensions of the viewport.
Return
Libraries.Game.Graphics.Painter2D:
GetSimulationThreshold()
Call this action if you want to manually tell the layer to turn off depth buffer sorting. This can be appropriate if all items in the layer are at the same level of depth. By default, depth buffer sorting is on.
Return
number:
GetSize()
This action will return the number of items that have been added to this layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
class Main is Game
action Main
StartGame()
end
action CreateGame
Item2D item1
Item2D item2
Item2D item3
Layer2D layer
layer:Add(item1)
layer:Add(item2)
layer:Add(item3)
AddLayer(layer)
integer size = layer:GetSize()
output "There are " + size + " items stored in the layer."
end
action Update(number seconds)
end
end
Return
integer: The number of items stored in this layer's array of items.
GetViewportHeight()
This action will hide the Layer. This will prevent the Layer from appearing when asked to draw.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
layer:Hide()
end
action Update(number seconds)
end
end
Return
integer:
GetViewportWidth()
This action will show the Layer. When Draw is called on a Layer which is showing, its items will appear on the screen. Layers begin showing by default.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
layer:Hide()
// Since layers are visible by default, it's only necessary to Show
// them after they've been hidden.
layer:Show()
end
action Update(number seconds)
end
end
Return
integer:
GetViewportX()
This action sets the viewport that will be used by this Layer. Anything drawn on this Layer will appear in a rectangle that begins x pixels from the left side of the screen, y pixels from the bottom, and has the given width and height in pixels.
Return
integer:
GetViewportY()
This action will return if the current layer is currently visible or not. Layers which are showing will be drawn on the screen automatically by the Game class. Layers begin showing by default.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
boolean showing = layer:IsShowing()
output "layer:IsShowing() returned " + showing
layer:Hide()
showing = layer:IsShowing()
output "After calling Hide(), IsShowing() returned " + showing
end
action Update(number seconds)
end
end
Return
integer:
Hide()
This action will hide the Layer. This will prevent the Layer from appearing when asked to draw.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
layer:Hide()
end
action Update(number seconds)
end
end
IsColliding()
This allows us to know if collisions are on or off for the layer.
Return
boolean:
IsContinuousPhysics()
This action will remove a TouchListener from the layer. The listener will no longer receive events from the layer. If the given TouchListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
layer:RemoveTouchListener(myListener)
end
action Update(number seconds)
end
end
Return
boolean:
IsDepthBufferSorting()
Call this action if you want to learn if depth buffer sorting is on. By default, depth buffer sorting is on.
Return
boolean:
IsEmpty()
This action will return false if there are items stored in this layer's array of items, or true if there are none.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
class Main is Game
action Main
StartGame()
end
action CreateGame
Item2D item1
Item2D item2
Item2D item3
Layer2D layer
boolean empty = layer:IsEmpty()
output "IsEmpty() returned " + empty
layer:Add(item1)
layer:Add(item2)
layer:Add(item3)
empty = layer:IsEmpty()
output "After adding items, IsEmpty() returns " + empty
AddLayer(layer)
end
action Update(number seconds)
end
end
Return
boolean: Whether or not any items are stored in this layer.
IsShowing()
This action will return if the current layer is currently visible or not. Layers which are showing will be drawn on the screen automatically by the Game class. Layers begin showing by default.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
boolean showing = layer:IsShowing()
output "layer:IsShowing() returned " + showing
layer:Hide()
showing = layer:IsShowing()
output "After calling Hide(), IsShowing() returned " + showing
end
action Update(number seconds)
end
end
Return
boolean:
IsSimulationRequired()
This action gets the list of items on this layer that are colliding and returns it as an array.
Return
boolean:
IsSubStepping()
AddCollisionListener will add a collision listener to this layer. The collision listener will be notified of collisions occuring on this layer, and is responsible for managing the collision events.
Return
boolean:
IsWarmStarting()
This action will remove all MouseMovementListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseMovementListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseMovementListener.
MouseMovementListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseMovementListener(myListener)
AddLayer(layer)
layer:EmptyMouseMovementListeners()
end
action Update(number seconds)
end
end
Return
boolean:
PhysicsEnabled()
This action will clear all the items in this layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
layer:Empty()
end
action Update(number seconds)
end
end
Return
boolean:
ProcessMouseEvent(Libraries.Interface.Events.MouseEvent event)
This action will notify mouse listeners that are a part of this layer of the given mouse event. This is called automatically by the Game engine as needed. Most users will never need to use this action directly.
Parameters
- Libraries.Interface.Events.MouseEvent: The MouseEvent to send to the MouseListeners.
Return
Libraries.Interface.Item: The Item which intercepted the event, or undefined if no Item received the event.
ProcessTouchEvent(Libraries.Interface.Events.TouchEvent event)
This action will notify touch listeners that are a part of this layer of the given touch event. This is called automatically by the Game engine as needed. Most users will never need to use this action directly.
Parameters
- Libraries.Interface.Events.TouchEvent: The TouchEvent to send to the TouchListeners.
Return
Remove(Libraries.Interface.Item2D item)
This action will remove an Item2D from this layer. If the item was not a part of this layer, this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
layer:Remove(circle)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Item2D: The item to remove from this layer.
Return
boolean: Whether or not the item was found and removed from the layer.
RemoveAt(integer index)
This action will remove an Item2D at the index location from this layer's array of items, and return the item that was removed.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:RemoveAt(0)
end
action Update(number seconds)
end
end
Parameters
- integer index: The index to remove an item from in this layer's array of items.
Return
Libraries.Interface.Item2D: The item that was removed from the item array in the layer.
RemoveCollisionListener(Libraries.Interface.Events.CollisionListener2D listener)
RemoveCollisionListener removes a collision listener to this layer. The collision listener will no longer be notified of collision events occurring on this layer. If the given listener is not a part of this layer, then this action will have no effect.
Parameters
RemoveFromEnd()
This action will remove an Item2D from the end of the array of items in the layer, and return the item that was removed.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:RemoveFromEnd()
end
action Update(number seconds)
end
end
Return
Libraries.Interface.Item2D: The item that was removed from this layer.
RemoveFromFront()
This action will remove an Item2D from the front of the array of items in this layer, and return the item that was removed. This is functionally the same as calling "RemoveAt(0)".
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable circle
circle:LoadFilledCircle(25)
circle:SetPosition(300, 100)
Layer2D layer
layer:Add(circle)
AddLayer(layer)
Item2D item = layer:RemoveFromFront()
end
action Update(number seconds)
end
end
Return
Libraries.Interface.Item2D: The item that was removed from the front of the layer's item array.
RemoveJoint(Libraries.Game.Physics.Joints.Joint2D joint)
This allows us to turn collisions on or off for the layer.
Parameters
RemoveMouseListener(Libraries.Interface.Events.MouseListener listener)
This action will remove a MouseListener from the layer. The listener will no longer receive events from the layer. If the given MouseListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseListener.
MouseListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseListener(myListener)
AddLayer(layer)
layer:RemoveMouseListener(myListener)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseListener: The MouseListener to remove from this layer.
RemoveMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener)
This action will remove a MouseMovementListener from the layer. The listener will no longer receive events from the layer. If the given MouseMovementListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseMovementListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseMovementListener.
MouseMovementListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseMovementListener(myListener)
AddLayer(layer)
layer:RemoveMouseMovementListener(myListener)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseMovementListener: The MouseMovementListener to remove from this layer.
RemoveMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener)
This action will remove a MouseWheelListener from the layer. The listener will no longer receive events from the layer. If the given MouseWheelListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
layer:RemoveMouseWheelListener(myListener)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.MouseWheelListener: The MouseWheelListener to remove from this layer.
RemoveTouchListener(Libraries.Interface.Events.TouchListener listener)
This action will remove a TouchListener from the layer. The listener will no longer receive events from the layer. If the given TouchListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
layer:RemoveTouchListener(myListener)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Interface.Events.TouchListener: The TouchListener to remove from this layer.
RequireSimulation(boolean flag)
This action indicates that the layer has received a new item that it must manage during collision detection. This is automatically called by the Game engine as necessary, and most users should never need to use this action directly.
Parameters
Resize(Libraries.Interface.Events.ResizeEvent event)
Call this action if you want to learn if depth buffer sorting is on. By default, depth buffer sorting is on.
Parameters
Set(integer index, Libraries.Interface.Item2D item)
This action will set the value of the given index in the layer's array of items to be the given Item2D. The previous value will be overwritten. If the index does not exist in the array (e.g., the given index is larger than the number of items stored in this layer), an error will be thrown.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Item2D
class Main is Game
action Main
StartGame()
end
action CreateGame
Item2D item1
Item2D item2
Item2D item3
Layer2D layer
layer:Add(item1)
layer:Add(item2)
layer:Set(1, item3)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- integer index: What index to set inside the layer's array of items.
- Libraries.Interface.Item2D: The item to store at the given index in the array.
SetAutomaticResizing(boolean resizing)
This action sets if the Layer should automatically respond to ResizeEvents. If this value is true, then the Layer will automatically adjust the camera and resize Items on the Layer when a ResizeEvent occurs.
Parameters
SetAutomaticallyClearForces(boolean flag)
This action will add a TouchListener to the layer. When the layer receives a touch event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all TouchListeners in the layer will receive the event.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.TouchListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from TouchListener.
TouchListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddTouchListener(myListener)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
SetCamera(Libraries.Game.Graphics.Camera cam)
This action will set the camera being used by this Layer. The camera is used to determine what will be drawn on the screen. Objects will be drawn on the screen as they are seen by the Layer's set camera.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.OrthographicCamera
class Main is Game
action Main
StartGame()
end
action CreateGame
OrthographicCamera camera
Layer2D layer
layer:SetCamera(camera)
AddLayer(layer)
end
action Update(number seconds)
end
end
Parameters
- Libraries.Game.Graphics.Camera: The camera that this layer should use.
SetColliding(boolean collide)
This allows us to turn collisions on or off for the layer.
Parameters
SetColorFilter(Libraries.Game.Graphics.Color color)
Using SetColorFilter will tint all drawn objects on the layer that do not have their own custom color tint. For example, using a red color filter will make all objects drawn on the layer to appear to be more red.
Parameters
SetColorFilter(number red, number green, number blue, number alpha)
SetColorFilter can be called using four number parameters instead of a color object. The four parameters are the red, green, blue, and opacity of the filter, respectively. All four of the parameters should be between 0 and 1, representing between 0% and 100% of that color component. For example, a value of 0 for red means that the tinting color will have no red, while a value of 1 will have all red components. An opacity of 0 is totally transparent, while an opacity of 1 will be totally visible.
Parameters
SetContinuousPhysics(boolean flag)
This action will remove all MouseListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseListener.
MouseListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseListener(myListener)
AddLayer(layer)
layer:EmptyMouseListeners()
end
action Update(number seconds)
end
end
Parameters
SetDepthBufferSorting(boolean sort)
Call this action if you want to manually tell the layer to turn off depth buffer sorting. This can be appropriate if all items in the layer are at the same level of depth. By default, depth buffer sorting is on.
Parameters
SetGravity(Libraries.Compute.Vector2 gravity)
This action will remove a MouseWheelListener from the layer. The listener will no longer receive events from the layer. If the given MouseWheelListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
layer:RemoveMouseWheelListener(myListener)
end
action Update(number seconds)
end
end
Parameters
SetGravity(number gravityX, number gravityY)
This action will remove a MouseMovementListener from the layer. The listener will no longer receive events from the layer. If the given MouseMovementListener is not on the layer before calling this action, then this action will have no effect.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseMovementListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseMovementListener.
MouseMovementListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseMovementListener(myListener)
AddLayer(layer)
layer:RemoveMouseMovementListener(myListener)
end
action Update(number seconds)
end
end
Parameters
SetInterfaceScale(number scale)
Parameters
SetLayout(Libraries.Interface.Layouts.Layout layout)
Parameters
SetName(text name)
This action sets the name of the Layer. This is used to identify the layer, especially in the Scene system.
Parameters
SetNewItemAdded(boolean flag)
This action indicates that the layer has received a new item that it must manage during collision detection. This is automatically called by the Game engine as necessary, and most users should never need to use this action directly.
Parameters
SetPainter(Libraries.Game.Graphics.Painter2D painter)
Parameters
SetSimulationThreshold(number threshold)
This allows us to know if collisions are on or off for the layer.
Parameters
SetSubStepping(boolean flag)
RemoveCollisionListener removes a collision listener to this layer. The collision listener will no longer be notified of collision events occurring on this layer. If the given listener is not a part of this layer, then this action will have no effect.
Parameters
SetViewport(integer x, integer y, integer width, integer height)
This action sets the viewport that will be used by this Layer. Anything drawn on this Layer will appear in a rectangle that begins x pixels from the left side of the screen, y pixels from the bottom, and has the given width and height in pixels.
Parameters
SetViewportAndCamera(integer x, integer y, integer width, integer height)
This actions sets the viewport that will be used by this Layer, and adjusts the Layer's camera to match the dimensions of the viewport.
Parameters
SetWarmStarting(boolean flag)
This action will remove all MouseWheelListeners from the layer.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Interface.Events.MouseWheelListener
class Main is Game
// For most programs, this should be replaced with
// a custom class inheriting from MouseWheelListener.
MouseWheelListener myListener
action Main
StartGame()
end
action CreateGame
Layer2D layer
layer:AddMouseWheelListener(myListener)
AddLayer(layer)
layer:EmptyMouseWheelListeners()
end
action Update(number seconds)
end
end
Parameters
Show()
This action will show the Layer. When Draw is called on a Layer which is showing, its items will appear on the screen. Layers begin showing by default.
Example Code
use Libraries.Game.Game
use Libraries.Game.Layer2D
use Libraries.Game.Graphics.Drawable
class Main is Game
action Main
StartGame()
end
action CreateGame
Drawable square
square:LoadFilledRectangle(200, 200)
Layer2D layer
layer:Add(square)
AddLayer(layer)
layer:Hide()
// Since layers are visible by default, it's only necessary to Show
// them after they've been hidden.
layer:Show()
end
action Update(number seconds)
end
end
TestForCollisions(number seconds)
This action triggers collision detection for this layer during a frame in the Game engine. This action will automatically be called by the Game class as necessary. Most users should never need to use this action directly.
Parameters
Update(number seconds)
This action will update all of the items contained within this Layer. The given number of seconds will be passed to each updated item. This is automatically called by the Game class as needed. Most users will never need to use this action directly.