Libraries.Game.Layer Documentation

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
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.
AddTouchListener(Libraries.Interface.Events.TouchListener listener)This action will add a TouchListener to the layer.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Draw()This action will draw all items in this Layer on the screen (if they can be drawn and they aren't hidden).
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
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.
GetHashCode()This action gets the hash code for an object.
Hide()This action will hide the Layer.
IsShowing()This action will return if the current layer is currently visible or not.
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.
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.
Resize(Libraries.Interface.Events.ResizeEvent event)This action will resize the Layer to match the dimensions of the provided ResizeEvent.
SetAutomaticResizing(boolean resizing)This action sets if the Layer should automatically respond to ResizeEvents.
SetCamera(Libraries.Game.Graphics.Camera camera)This action will set the camera being used by this Layer.
Show()This action will show the Layer.
Update(number seconds)This action will update all of the items contained within this Layer.

Actions Documentation

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

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

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

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

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: 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.

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

Return

boolean: True if the hash codes are equal and false if they are not equal.

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.

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.

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

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:

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

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

Return

Libraries.Interface.Item:

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(listener)
        end

        action Update(number seconds)
        end

    end

Parameters

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(listener)
        end

        action Update(number seconds)
        end

    end

Parameters

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(listener)
        end

        action Update(number seconds)
        end

    end

Parameters

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(listener)
        end

        action Update(number seconds)
        end

    end

Parameters

Resize(Libraries.Interface.Events.ResizeEvent event)

This action will resize the Layer to match the dimensions of the provided ResizeEvent. This action is called automatically by the Game engine if the GetAutomaticResizing() value returns true. Users should not typically need to call this action directly.

Parameters

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

SetCamera(Libraries.Game.Graphics.Camera camera)

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

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

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.

Parameters