Layer3D

Package: Libraries.Game · Inherits from: Libraries.Language.Object, Libraries.Game.Layer

The Layer3D class is used to manage a number of 3D objects, as well as manage input. The Layer2D effectively consists of a 3D "world", where all objects added to it exist in the same space and can interact with each other. The layer only draws what the camera can see, and, in Vulkan, what could cast a shadow into view. It finds these with a render tree, which holds a box around each item added to the layer (see Item3D:GetRenderBounds). An item's children are drawn with it, so a child is not drawn when its parent's box is out of view, even if the child itself would be in view.

Example Code

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

action Main
    StartGame()
end

action CreateGame
    Color color

    Model box
    box:LoadBox(2, 2, 2, color:Maroon())
    box:SetPosition(-2, 0, 2)

    Model sphere
    sphere:LoadSphere(2, 2, 2, color:Teal())
    sphere:SetPosition(2, 0, 2)

    Layer3D layer
    layer:Add(box)
    layer:Add(sphere)
    AddLayer(layer)
end

action Update(number seconds)
end
end

Variables

  • integer MAXIMUM_SHADOW_BITS: bit: one integer's bits, less the sign.

Actions

Add(Libraries.Game.Graphics.DirectionalLight light)

This action will add the given light to the Layer3D. It will be used during lighting of all objects on the layer.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Add(Libraries.Game.Physics.PhysicsBehavior3D behavior)

This action adds a PhysicsBehavior3D to the layer. A behavior takes part in the layer's physics without being an item. Joints, which connect two items, are behaviors, and so are vehicles. While it is in the layer, the layer calls the behavior during each physics step and each frame, as described in PhysicsBehavior3D.

Parameters

Add(Libraries.Game.Graphics.PointLight light)

This action will add a PointLight to the Layer3D. The Layer3D will treat it as an Item3D (respecting its position and updating it each frame) as well as using it to light up the scene.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetPosition(6, 3, 0)
        light:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

Add(Libraries.Interface.Item3D item)

This action will add an Item3D 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 Item3D). The layer keeps its items in a tree, so they have no order.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Item3D objects aren't visible, but can still be used for game logic.
        Item3D area
        area:SetWidth(5)
        area:SetHeight(5)
        area:SetDepth(5)
        area:SetPosition(0, 10, 0)

        // Models inherit from Item3D, so they can be added too.
        Model cylinder
        Color color
        cylinder:LoadCylinder(2, 4, 2, color:Orange())
        cylinder:SetPosition(0, 0, 3)

        Layer3D layer
        layer:Add(area)
        layer:Add(cylinder)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

AddCollisionListener(Libraries.Interface.Events.CollisionListener3D 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

AddGestureListener(Libraries.Interface.Events.GestureListener listener)

This action will add a GestureListener to the layer. When the layer receives a gesture event, it will first try to find the topmost item which can handle the event. If the event is not handled, then all GestureListeners in the layer will receive the event.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.GestureListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from GestureListener.
    GestureListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddGestureListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

AddJoint(Libraries.Game.Physics.Joints.Joint3D joint)

This action adds a joint to the layer. It does the same thing as Add, which works for every kind of PhysicsBehavior3D and should be used instead.

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseMovementListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseWheelListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddTouchListener(myListener)
        AddLayer(layer)
    end

    action Update(number seconds)
    end

end

ApplyGravity()

This action works out where a body is drawn and gives it to the body with SetDrawnTransform. It never moves the body in the physics. Like Bullet's default (latency interpolation), the body is drawn the leftover time before its latest step, which is at most one step behind it, so it is never drawn past where the physics has actually been, such as inside the ground. With variable steps (no fixed step), it is drawn where it is.

ApplySafeRegion()

This action draws the scene in the content region (see Layer:GetContentRegion): the viewport becomes the region, and the camera's width and height match it, so its view fits. A 3D layer has no layout, so this is how it avoids camera cutouts and system bars. It only changes a viewport this layer chose (the whole display, or the last safe region), never one the program set.

ArePointShadowCastersMarked()

This action returns true if this frame's shadow casters were marked with the point lights that found them, so each point light can draw only its own. It is false if the layer's render tree doesn't find point lights' casters.

Returns

boolean: True if point lights' casters were marked.

AutomaticallyClearForces()

This action gets the list of items on this layer that are colliding and returns it as an array.

Returns

boolean

ClearForces()

This action will remove all ambient lighting from the Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        layer:RemoveAmbientLight()
    end

    action Update(number seconds)
    end
end

DisableItemLighting(Libraries.Interface.Item3D item)

This action will disable lighting for the given Item3D (if it is a light) and any of its children (if they are lights). This action is called automatically by the Layer when adding or removing items. Most users will never need to use this action directly.

Parameters

Draw()

This action draws the items in this layer that the camera can see, if the layer is showing. In Vulkan, it also draws the items that are out of view but could cast a shadow into it, so their shadows still show. Transparent models are drawn last, from farthest to nearest, so each blends over what is behind it. 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

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color

        Model box
        box:LoadBox(2, 2, 2, color:Red())
        box:SetPosition(0, 0, 2)

        Layer3D layer
        layer:Add(box)
        AddLayer(layer)

        layer:Empty()
    end

    action Update(number seconds)
    end
end

EnableItemLighting(Libraries.Interface.Item3D item)

This action will enable lighting for the given Item3D (if it is a light) and any of its children (if they are lights). This action is called automatically by the Layer when adding or removing items. Most users will never need to use this action directly.

Parameters

EnablePhysics(boolean flag)

This action sets the Skybox that should be used by this Layer3D. The given Skybox will be rendered behind all other items in the layer. If the given parameter is undefined, the Layer will not render a skybox. By default, the skybox is undefined.

Parameters

  • flag boolean

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Skybox

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Assuming we have 6 image files, "Sky-Right.png", "Sky-Left.png", etc.
        Skybox skybox
        skybox:Load("Sky-Right.png", "Sky-Left.png", "Sky-Up.png", "Sky-Down.png", "Sky-Forward.png", "Sky-Back.png")

        Layer3D layer = GetCurrentLayer3D()
        layer:SetSkybox(skybox)

        Skybox layerBox = layer:GetSkybox()
    end
end

GetAmbientLight()

This action will return the AmbientLight being used on this Layer3D. If the scene doesn't have any ambient lighting, then this action will return undefined.

Returns

Libraries.Game.Graphics.AmbientLight: The AmbientLight used in the Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        AmbientLight returnedLight = layer:GetAmbientLight()
    end

    action Update(number seconds)
    end
end

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.

Returns

Libraries.Game.Graphics.Camera: The camera currently being used by this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Camera

class Main is Game

    Camera layerCamera = undefined

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layerCamera = layer:GetCamera()
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

GetCollisionList()

This action gets the list of items on this layer that are colliding and returns it as an array.

Returns

Libraries.Interface.Events.CollisionEvent3D

GetCollisionManager()

This action gets the collision manager for this object which is responsible for managing the collisions between all colliding items on this layer.

Returns

Libraries.Game.Collision.CollisionManager3D

GetCullPercentage()

This action returns the percent of items that were culled in the frustrum on the last frame of animation. The number returned is between 0 (no culling) and 1 (Everything is culled).

Returns

number: The percent of items culled in the last frame of animation.

GetDirectionalLight(integer index)

This action will return a directional light stored at the given index in the Layer's array of directional lights. Each type of light stored in the Layer is kept in a separate array from other types. If there are no directional lights added to this layer, or if the index is out of bounds, this action will produce an error.

Parameters

  • index integer: The index to retrieve from the DirectionalLight array in the Layer.

Returns

Libraries.Game.Graphics.DirectionalLight: The DirectionalLight stored at the given index in this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light1
        light1:SetColor(0.8, 0.8, 0.8, 1)
        light1:SetDirection(1, 0, 1.1)

        DirectionalLight light2
        light2:SetColor(0.8, 0.8, 0.8, 1)
        light2:SetDirection(0, -1, 0)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light1)
        layer:Add(light2)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        // This will retrieve light1, because it was added to the Layer first.
        DirectionalLight returnedLight = layer:GetDirectionalLight(0)
    end

    action Update(number seconds)
    end
end

GetDirectionalLights()

This action will get an iterator containing all of the DirectionalLights stored inside this layer.

Returns

Libraries.Containers.Iterator<Libraries.Game.Graphics.DirectionalLight>: An iterator containing each of the DirectionalLights added to this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight
use Libraries.Containers.Iterator

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        Iterator<DirectionalLight> lights = layer:GetDirectionalLights()
    end

    action Update(number seconds)
    end
end

GetEnvironment()

Returns

Libraries.Game.Graphics.Environment

GetGravity()

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.

Returns

Libraries.Compute.Vector3

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

Returns

Libraries.Interface.Item

GetIterator()

This action will return an iterator of all the Item3D's stored inside this layer. The items come in the order of the layer's tree, which is not the order they were added in, and can change as they move.

Returns

Libraries.Containers.Iterator<Libraries.Interface.Item3D>: An iterator containing all Item3D's stored in this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D
use Libraries.Containers.Iterator

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Item3D item1
        Item3D item2
        Item3D item3

        Layer3D layer
        layer:Add(item1)
        layer:Add(item2)
        layer:Add(item3)
        AddLayer(layer)

        Iterator<Item3D> itemIterator = layer:GetIterator()
    end

    action Update(number seconds)
    end
end

GetMaxSubSteps()

This action will add the given light to the Layer3D. It will be used during lighting of all objects on the layer.

Returns

integer

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

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.

Returns

Libraries.Game.Graphics.Painter3D

GetPhysicsBehavior(integer index)

This action returns one of the PhysicsBehavior3D objects in this layer. Indexes start at 0.

Parameters

  • index integer: The index of the behavior.

Returns

Libraries.Game.Physics.PhysicsBehavior3D: The behavior at that index.

GetPhysicsBehaviorsSize()

This action returns how many PhysicsBehavior3D objects are in this layer.

Returns

integer: The number of behaviors in the layer.

GetPointLight(integer index)

This action will return a point light stored at the given index in the Layer's array of point lights. Each type of light stored in the Layer is kept in a separate array from other types. If there are no directional lights added to this layer, or if the index is out of bounds, this action will produce an error.

Parameters

  • index integer: The index to retrieve from the PointLight array in the Layer.

Returns

Libraries.Game.Graphics.PointLight: The PointLight stored at the given index in this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light1
        light1:SetColor(0.8, 0.8, 0.8, 1)
        light1:SetPosition(6, 3, 0)
        light1:SetIntensity(8)

        PointLight light2
        light2:SetColor(0.8, 0.8, 0.8, 1)
        light2:SetPosition(2, 3, 0)
        light2:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light1)
        layer:Add(light2)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        // This will retrieve light1, because it was added to the Layer first.
        PointLight returnedLight = layer:GetPointLight(0)
    end

    action Update(number seconds)
    end
end

GetPointLights()

This action will get an iterator containing all of the PointLights stored inside this layer.

Returns

Libraries.Containers.Iterator<Libraries.Game.Graphics.PointLight>: An Iterator containing each of the PointLights that have been added to this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight
use Libraries.Containers.Iterator

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetPosition(6, 3, 0)
        light:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        Iterator<PointLight> lights = layer:GetPointLights()
    end

    action Update(number seconds)
    end
end

GetRenderTree()

This action returns the render tree the layer uses to find what to draw. It holds every item added to the layer.

Returns

Libraries.Game.Graphics.Trees.RenderTree3D: The layer's render tree.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Trees.RenderTree3D

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer = GetCurrentLayer3D()
        RenderTree3D tree = layer:GetRenderTree()
        output tree:GetSize()
    end
end

GetShadowFrame()

This action returns the frame number this layer marks shadow casters with. An item's Item3D:GetShadowLightMask with it says which point lights' searches found the item this frame.

Returns

integer: The layer's frame number.

GetSize()

This action will return the number of items that have been added to this layer.

Returns

integer: The number of items stored in this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Item3D item1
        Item3D item2
        Item3D item3

        Layer3D 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

GetSkybox()

This action sets the Skybox that should be used by this Layer3D. The given Skybox will be rendered behind all other items in the layer. If the given parameter is undefined, the Layer will not render a skybox. By default, the skybox is undefined.

Returns

Libraries.Game.Graphics.Skybox

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Skybox

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Assuming we have 6 image files, "Sky-Right.png", "Sky-Left.png", etc.
        Skybox skybox
        skybox:Load("Sky-Right.png", "Sky-Left.png", "Sky-Up.png", "Sky-Down.png", "Sky-Forward.png", "Sky-Back.png")

        Layer3D layer = GetCurrentLayer3D()
        layer:SetSkybox(skybox)

        Skybox layerBox = layer:GetSkybox()
    end
end

GetSubStepping()

This action adds a joint to the layer. It does the same thing as Add, which works for every kind of PhysicsBehavior3D and should be used instead.

Returns

boolean

Has(Libraries.Interface.Item3D item)

This action returns true if the given item was added to this layer. It does not look for children of the layer's items.

Parameters

Returns

boolean: True if the item was added to this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        Item3D item
        Layer3D layer = GetCurrentLayer3D()
        output layer:Has(item)
        layer:Add(item)
        output layer:Has(item)
    end
end

HasMouseWheelListeners()

This action returns whether the layer has any MouseWheelListeners. A layer with listeners uses every mouse wheel turn over it that no item takes.

Returns

boolean: True if at least one MouseWheelListener was added.

IntegrateTransforms(number timeStep)

through a contact or a joint with an awake one, which wakes it.

Parameters

  • timeStep number

IsColliding()

This allows us to know if collisions are on or off for the layer.

Returns

boolean

IsContinuousPhysics()

This action will return a directional light stored at the given index in the Layer's array of directional lights. Each type of light stored in the Layer is kept in a separate array from other types. If there are no directional lights added to this layer, or if the index is out of bounds, this action will produce an error.

Returns

boolean: The DirectionalLight stored at the given index in this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light1
        light1:SetColor(0.8, 0.8, 0.8, 1)
        light1:SetDirection(1, 0, 1.1)

        DirectionalLight light2
        light2:SetColor(0.8, 0.8, 0.8, 1)
        light2:SetDirection(0, -1, 0)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light1)
        layer:Add(light2)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        // This will retrieve light1, because it was added to the Layer first.
        DirectionalLight returnedLight = layer:GetDirectionalLight(0)
    end

    action Update(number seconds)
    end
end

IsEmpty()

This action will return false if there are items stored in this layer, or true if there are none.

Returns

boolean: Whether or not any items are stored in this layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Item3D

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Item3D item1
        Item3D item2
        Item3D item3

        Layer3D 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

IsSimulationRequired()

This action will get an iterator containing all of the DirectionalLights stored inside this layer.

Returns

boolean: An iterator containing each of the DirectionalLights added to this Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight
use Libraries.Containers.Iterator

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        Iterator<DirectionalLight> lights = layer:GetDirectionalLights()
    end

    action Update(number seconds)
    end
end

IsSubStepping()

This action will return the AmbientLight being used on this Layer3D. If the scene doesn't have any ambient lighting, then this action will return undefined.

Returns

boolean: The AmbientLight used in the Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        AmbientLight returnedLight = layer:GetAmbientLight()
    end

    action Update(number seconds)
    end
end

IsWarmStarting()

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.

Returns

boolean

ItemMoved(Libraries.Interface.Item3D item)

This action is called by an item on this layer, or one of its children, the first time it moves, turns or changes scale after its move report was cleared. The layer keeps it until collisions are next found, so its collision box can be brought up to date. Then it tells the rendering tree the item moved, and clears its report.

Parameters

ItemPhysicsChanged(Libraries.Interface.Item3D item)

This action is called by an item on this layer when its physics is turned on or off. An item added to the layer is put in, or taken out of, the trees physics uses.

Parameters

ItemResized(Libraries.Interface.Item3D item)

This action is called by an item on this layer, or one of its children, when its width, height or depth changes, such as when a model finishes loading. An item added to the layer is placed in the rendering tree again, with its new bounds. A child is left alone, since only the items added to the layer are in the tree.

Parameters

ItemSimulationChanged(Libraries.Interface.Item3D item)

This action is called by an item on this layer when physics starts or stops simulating it, that is, when it wakes or falls asleep. The item is moved to the matching physics tree once no walk of the trees is under way.

Parameters

PhysicsEnabled()

This action sets the Skybox that should be used by this Layer3D. The given Skybox will be rendered behind all other items in the layer. If the given parameter is undefined, the Layer will not render a skybox. By default, the skybox is undefined.

Returns

boolean

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Skybox

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Assuming we have 6 image files, "Sky-Right.png", "Sky-Left.png", etc.
        Skybox skybox
        skybox:Load("Sky-Right.png", "Sky-Left.png", "Sky-Up.png", "Sky-Down.png", "Sky-Forward.png", "Sky-Back.png")

        Layer3D layer = GetCurrentLayer3D()
        layer:SetSkybox(skybox)
    end
end

ProcessGestureEvent(Libraries.Interface.Events.GestureEvent event)

This action will notify gesture listeners that are a part of this layer of the given gesture event. This is called automatically by the Game engine as needed. Most users will never need to use this action directly.

Parameters

Returns

Libraries.Interface.Item

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

Returns

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

Returns

Libraries.Interface.Item

RayCastPhysics(Libraries.Compute.Vector3 from, Libraries.Compute.Vector3 to, Libraries.Interface.Item3D ignore, Libraries.Game.Collision.RayCastResult3D result)

This action checks which item in this layer a straight line segment, called a ray, touches first, skipping one item. The ray starts at "from" and ends at "to," both in world space. Skipping an item is useful when the ray starts on or inside something that should not count. For example, a vehicle skips its own body when it checks the ground under its wheels. This is a physics query that tests collision shapes. See the other RayCast action in this class for what the result holds.

Parameters

Returns

boolean: true if the ray hit an item, and false otherwise.

RayCastPhysics(Libraries.Compute.Vector3 from, Libraries.Compute.Vector3 to, Libraries.Game.Collision.RayCastResult3D result)

This action checks which item in this layer a straight line segment, called a ray, touches first. The ray starts at "from" and ends at "to," both in world space. Every collidable item in the layer can be hit. This is a physics query. It tests each item's collision shape, not its drawn model, so it agrees with what the physics system considers solid. It is different from the mouse picking this layer uses to find which item is under the pointer. The result is reset before the search begins. If the ray hits anything, the result holds the item that was hit, the fraction of the way along the ray where the hit happened (0 is "from" and 1 is "to"), the hit point in world space, and the surface normal at that point.

Parameters

Returns

boolean: true if the ray hit an item, and false otherwise.

Example

use Libraries.Game.Game
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Collision.RayCastResult3D
use Libraries.Compute.Vector3

class Main is Game
    Model ground

    action Main
        StartGame()
    end

    action CreateGame
        EnablePhysics3D(true)
        Color color
        // A flat ground whose top surface is at y = 0.
        ground:LoadBox(10, 1, 10, color:Gray())
        ground:SetPosition(0, -0.5, 0)
        ground:EnablePhysics(true)
        ground:SetMass(0)
        Add(ground)
    end

    action Update(number seconds)
        // A ray straight down from 10 units above the ground.
        Vector3 from
        from:Set(0, 10, 0)
        Vector3 to
        to:Set(0, -10, 0)
        RayCastResult3D result
        if GetCurrentLayer3D():RayCastPhysics(from, to, result)
            // The ray reaches the top of the ground halfway down,
            // so this outputs a fraction of about 0.5.
            output "Hit at fraction " + result:GetFraction()
        end
    end
end

Remove(Libraries.Game.Graphics.PointLight light)

This action will remove the given PointLight from the Layer3D. It will no longer be part of the item hierarchy of this Layer, and will no longer provide lighting in the scene.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetPosition(6, 3, 0)
        light:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        layer:Remove(light)
    end

    action Update(number seconds)
    end
end

Remove(Libraries.Game.Graphics.DirectionalLight light)

This action will remove the given DirectionalLight from the Layer3D.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        layer:Remove(light)
    end

    action Update(number seconds)
    end
end

Remove(Libraries.Interface.Item3D item)

This action will remove an Item3D from this layer. If the item was not a part of this layer, this action will have no effect.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Orange())
        box:SetPosition(0, 0, 2)

        Layer3D layer
        layer:Add(box)
        AddLayer(layer)

        layer:Remove(box)
    end

    action Update(number seconds)
    end
end

Remove(Libraries.Game.Physics.PhysicsBehavior3D behavior)

This action removes a PhysicsBehavior3D from the layer. The layer stops calling the behavior, and any items it connected, such as the two items of a joint, are no longer held together.

Parameters

RemoveAmbientLight()

This action will remove all ambient lighting from the Layer.

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        layer:RemoveAmbientLight()
    end

    action Update(number seconds)
    end
end

RemoveBehaviorsUsing(Libraries.Interface.Item3D item)

Removes every physics behavior that uses the given item, as reported by the behavior's GetItemsSize and GetItem actions.

Parameters

RemoveCollisionListener(Libraries.Interface.Events.CollisionListener3D 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

RemoveGestureListener(Libraries.Interface.Events.GestureListener listener)

This action will remove a GestureListener from the layer. The listener will no longer receive events from the layer. If the given GestureListener is not on the layer before calling this action, then this action will have no effect.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.GestureListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from GestureListener.
    GestureListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddGestureListener(myListener)
        AddLayer(layer)

        layer:RemoveGestureListener(myListener)
    end

    action Update(number seconds)
    end

end

RemoveJoint(Libraries.Game.Physics.Joints.Joint3D joint)

This action removes a joint from the layer. It does the same thing as Remove, which works for every kind of PhysicsBehavior3D and should be used instead.

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseListener(myListener)
        AddLayer(layer)

        layer:RemoveMouseListener(listener)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseMovementListener(myListener)
        AddLayer(layer)

        layer:RemoveMouseMovementListener(listener)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddMouseWheelListener(myListener)
        AddLayer(layer)

        layer:RemoveMouseWheelListener(listener)
    end

    action Update(number seconds)
    end

end

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
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
        Layer3D layer
        layer:AddTouchListener(myListener)
        AddLayer(layer)

        layer:RemoveTouchListener(listener)
    end

    action Update(number seconds)
    end

end

RequireSimulation(boolean flag)

This action will get an iterator containing all of the PointLights stored inside this layer.

Parameters

  • flag boolean

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight
use Libraries.Containers.Iterator

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetPosition(6, 3, 0)
        light:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        Iterator<PointLight> lights = layer:GetPointLights()
    end

    action Update(number seconds)
    end
end

Resize(Libraries.Interface.Events.ResizeEvent event)

This action removes a joint from the layer. It does the same thing as Remove, which works for every kind of PhysicsBehavior3D and should be used instead.

Parameters

SaveKinematicState(number timeStep)

This action works out where each awake body is drawn, between its last two physics steps. SetScreenPositionsFromPhysicsPositions does this for every awake body once a frame, so this is only needed by code that wants the drawn transforms brought up to date at another time.

Parameters

  • timeStep number

SetAmbientLight(Libraries.Game.Graphics.AmbientLight light)

This action will set the ambient lighting present in this Layer. If the layer already had ambient lighting, it will be overwritten.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

SetAutomaticallyClearForces(boolean flag)

This action gets the collision manager for this object which is responsible for managing the collisions between all colliding items on this layer.

Parameters

  • flag boolean

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.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.PerspectiveCamera

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        PerspectiveCamera camera
        Layer3D layer
        layer:SetCamera(camera)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

SetColliding(boolean collide)

This allows us to turn collisions on or off for the layer.

Parameters

  • collide boolean

SetContinuousPhysics(boolean flag)

This action will return a point light stored at the given index in the Layer's array of point lights. Each type of light stored in the Layer is kept in a separate array from other types. If there are no directional lights added to this layer, or if the index is out of bounds, this action will produce an error.

Parameters

  • flag boolean

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.PointLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        PointLight light1
        light1:SetColor(0.8, 0.8, 0.8, 1)
        light1:SetPosition(6, 3, 0)
        light1:SetIntensity(8)

        PointLight light2
        light2:SetColor(0.8, 0.8, 0.8, 1)
        light2:SetPosition(2, 3, 0)
        light2:SetIntensity(8)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light1)
        layer:Add(light2)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        // This will retrieve light1, because it was added to the Layer first.
        PointLight returnedLight = layer:GetPointLight(0)
    end

    action Update(number seconds)
    end
end

SetGravity(Libraries.Compute.Vector3 gravity)

date.

Parameters

SetGravity(number x, number y, number z)

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

  • x number
  • y number
  • z number

SetMaxSubSteps(integer maxSubSteps)

This action will remove a GestureListener from the layer. The listener will no longer receive events from the layer. If the given GestureListener is not on the layer before calling this action, then this action will have no effect.

Parameters

  • maxSubSteps integer

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Interface.Events.GestureListener

class Main is Game

    // For most programs, this should be replaced with 
    // a custom class inheriting from GestureListener.
    GestureListener myListener

    action Main
        StartGame()
    end

    action CreateGame
        Layer3D layer
        layer:AddGestureListener(myListener)
        AddLayer(layer)

        layer:RemoveGestureListener(myListener)
    end

    action Update(number seconds)
    end

end

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

  • flag boolean

SetPainter(Libraries.Game.Graphics.Painter3D painter)

This action draws the scene in the content region (see Layer:GetContentRegion): the viewport becomes the region, and the camera's width and height match it, so its view fits. A 3D layer has no layout, so this is how it avoids camera cutouts and system bars. It only changes a viewport this layer chose (the whole display, or the last safe region), never one the program set.

Parameters

SetRenderTree(Libraries.Game.Graphics.Trees.RenderTree3D tree)

This action changes the kind of render tree the layer uses to find what to draw, such as to a QuadTree3D or an Octree3D, which can be faster for a large, flat world. Every item on the layer is moved into the new tree, and the old tree is emptied. The new tree should be empty to begin with.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Trees.QuadTree3D

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        QuadTree3D tree
        tree:SetRegion(-100, -10, -100, 100, 50, 100)
        Layer3D layer = GetCurrentLayer3D()
        layer:SetRenderTree(tree)
    end
end

SetScreenPositionsFromPhysicsPositions()

flagged, so only they are cleared.

SetSkybox(Libraries.Game.Graphics.Skybox box)

This action sets the Skybox that should be used by this Layer3D. The given Skybox will be rendered behind all other items in the layer. If the given parameter is undefined, the Layer will not render a skybox. By default, the skybox is undefined.

Parameters

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Skybox

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        // Assuming we have 6 image files, "Sky-Right.png", "Sky-Left.png", etc.
        Skybox skybox
        skybox:Load("Sky-Right.png", "Sky-Left.png", "Sky-Up.png", "Sky-Down.png", "Sky-Forward.png", "Sky-Back.png")

        Layer3D layer = GetCurrentLayer3D()
        layer:SetSkybox(skybox)
    end
end

SetSubStepping(boolean flag)

Parameters

  • flag boolean

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

  • x integer
  • y integer
  • width integer
  • height integer

SetWarmStarting(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

  • flag boolean

SolvePhysics(number seconds)

This action will remove the given DirectionalLight from the Layer3D.

Parameters

  • seconds number

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)

        layer:Remove(light)
    end

    action Update(number seconds)
    end
end

StepPhysics(number seconds)

This action will set the ambient lighting present in this Layer. If the layer already had ambient lighting, it will be overwritten.

Parameters

  • seconds number

Example

use Libraries.Game.Game
use Libraries.Game.Layer3D
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
use Libraries.Game.Graphics.DirectionalLight
use Libraries.Game.Graphics.AmbientLight

class Main is Game

    action Main
        StartGame()
    end

    action CreateGame
        Color color
        Model box
        box:LoadBox(2, 2, 2, color:Green())
        box:SetPosition(4, 0, 2)

        DirectionalLight light
        light:SetColor(0.8, 0.8, 0.8, 1)
        light:SetDirection(-1, -0.5, 1)

        AmbientLight ambient
        ambient:SetColor(0.4, 0.4, 0.4, 1)

        Layer3D layer
        layer:Add(box)
        layer:Add(light)
        layer:SetAmbientLight(ambient)
        AddLayer(layer)
    end

    action Update(number seconds)
    end
end

SynchronizeTransforms()

This action works out where each awake body is drawn, between its last two physics steps. SetScreenPositionsFromPhysicsPositions does this for every awake body once a frame, so this is only needed by code that wants the drawn transforms brought up to date at another time.

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

  • seconds number

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

  • seconds number

Inherited Actions

16 actions from Libraries.Game.Layer
3 actions from Libraries.Language.Object