SpotLight
Package: Libraries.Game.Graphics · Inherits from: Libraries.Game.Graphics.Light, Libraries.Interface.Item3D, Libraries.Interface.Item, Libraries.Language.Object
A SpotLight lights a 3D scene from one point, in a cone, the way a torch, a car's headlight or a stage light does. Inside its inner angle the light is at full strength; between the inner and outer angles it fades; outside the outer angle it gives no light. Like a point light, it gets dimmer the farther it travels, and it gives no light past its range. A spotlight is an Item3D, so it can be placed with SetPosition, and added to another item, such as a car, so that it moves and turns with it. Its direction is given in its own space: when the item it belongs to turns, the cone turns with it. Under Vulkan, spotlights cast shadows, as point lights do. Under OpenGL they are not drawn yet.
Example Code
use Libraries.Game.Game
use Libraries.Game.Graphics.SpotLight
use Libraries.Game.Graphics.Model
use Libraries.Game.Graphics.Color
class Main is Game
action Main
StartGame()
end
action CreateGame
Color color
Model floor
floor:LoadBox(20, 0.2, 20, color:White())
Add(floor)
// A lamp above the floor, shining straight down.
SpotLight lamp
lamp:SetPosition(0, 6, 0)
lamp:SetDirection(0, -1, 0)
lamp:SetConeAngles(20, 30)
lamp:SetIntensity(40)
lamp:SetRange(15)
Add(lamp)
end
end
Actions
Copy()
This action makes a copy of this light: color, position, offsets, direction, cone angles, intensity and range.
Returns
Libraries.Game.Graphics.SpotLight: The copy.
GetDirection()
This action returns the direction the cone points, in the light's own space. Change it with SetDirection, not by changing the vector.
Returns
Libraries.Compute.Vector3: The direction, of length 1.
GetInnerAngle()
This action returns the angle of full strength, in degrees.
Returns
number: The inner half-angle.
GetIntensity()
This action returns how bright the light is.
Returns
number: The light's intensity.
GetOuterAngle()
This action returns the angle where the light ends, in degrees.
Returns
number: The outer half-angle.
GetRange()
This action returns how far the light reaches: the range set with SetRange, or, if none was set, the distance at which its brightest color, at its intensity, falls below MINIMUM_ILLUMINATION_THRESHOLD.
Returns
number: How far the light reaches, in world units.
GetRangeSetting()
This action returns the range as set with SetRange: 0 if the range is worked out from the intensity and color. A scene saves this, so a light whose range was never set keeps working it out.
Returns
number: The range set, in world units, or 0.
Hide()
This action turns the light off without changing its intensity or color, so Show turns it back on as it was. A hidden light lights nothing and draws no shadows.
Example
use Libraries.Game.Game
use Libraries.Game.Graphics.SpotLight
class Main is Game
SpotLight lamp
action Main
StartGame()
end
action CreateGame
lamp:SetIntensity(5)
Add(lamp)
lamp:Hide()
end
end
SetConeAngles(number inner, number outer)
This action sets the cone's half-angles, in degrees, measured from the direction the light points. Inside the inner angle the light is at full strength; it fades between the two, and gives no light past the outer angle. The outer angle is kept between 1 and 89 degrees, and the inner angle between 0 and the outer angle.
Parameters
innernumber: The angle of full strength, in degrees.outernumber: The angle where the light ends, in degrees.
SetDirection(number x, number y, number z)
This action sets the direction the cone points, in the light's own space. It is made length 1. A direction of zero length is ignored.
Parameters
xnumber: The direction along x.ynumber: The direction along y.znumber: The direction along z.
SetDirection(Libraries.Compute.Vector3 newDirection)
This action sets the direction the cone points, in the light's own space. It is made length 1.
Parameters
newDirectionLibraries.Compute.Vector3: The direction.
SetIntensity(number newIntensity)
This action sets how bright the light is.
Parameters
newIntensitynumber: The light's intensity.
SetLight(Libraries.Game.Graphics.Color newColor, Libraries.Compute.Vector3 newPosition, Libraries.Compute.Vector3 newDirection, number newIntensity, number newOuterAngle)
This action sets the color, position, direction, intensity and outer angle of the light at once. The inner angle becomes two thirds of the outer one.
Parameters
newColorLibraries.Game.Graphics.Color: The color, or undefined to keep it.newPositionLibraries.Compute.Vector3: The position.newDirectionLibraries.Compute.Vector3: The direction, in the light's own space.newIntensitynumber: The intensity.newOuterAnglenumber: The angle where the light ends, in degrees.
SetRange(number newRange)
This action sets how far the light reaches. It fades smoothly to nothing at this distance. A range of 0 works the range out from the intensity and color instead (see GetRange).
Parameters
newRangenumber: How far the light reaches, in world units, or 0.
Show()
This action turns a hidden light back on, as bright as it was.
Inherited Actions
9 actions from Libraries.Game.Graphics.Light
- CastsShadows()
- GetColor()
- GetEnvironment()
- GetShadowData(integer index)
- SetCastsShadows(boolean casts)
- SetColor(Libraries.Game.Graphics.Color newColor)
- SetColor(number red, number green, number blue, number alpha)
- SetEnvironment(Libraries.Game.Graphics.Environment environment)
- SetShadowData(integer index, Libraries.Game.Graphics.CascadeShadowData data)
62 actions from Libraries.Interface.Item
- AddBehavior(Libraries.Interface.Behaviors.Behavior behavior)
- AddFocusListener(Libraries.Interface.Events.FocusListener listener)
- AddGestureListener(Libraries.Interface.Events.GestureListener listener)
- AddMouseListener(Libraries.Interface.Events.MouseListener listener)
- AddMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener)
- AddMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener)
- AddTouchListener(Libraries.Interface.Events.TouchListener listener)
- BeginCollision(Libraries.Interface.Item item)
- CancelBehaviors()
- Dispose()
- DisposeAll()
- DisposeChildren()
- EmptyAll()
- EmptyChildren()
- FinishCollision(Libraries.Interface.Item item)
- Focus()
- GainedFocus(Libraries.Interface.Events.FocusEvent event)
- GetAccessibilityCode()
- GetAccessibilityRoleDescription()
- GetAccessibilityType()
- GetActiveDescendant()
- GetDescription()
- GetFocusListeners()
- GetGestureListeners()
- GetInputGroup()
- GetInputTable()
- GetMouseListeners()
- GetMouseMovementListeners()
- GetMouseWheelListeners()
- GetName()
- GetNextFocus()
- GetPreviousFocus()
- GetPropertiesSize()
- GetProperty(text key)
- GetPropertyKeyIterator()
- GetTouchListeners()
- HasProperties()
- HasProperty(text key)
- IsAcceptingMouseInput()
- IsAccessibleParent()
- IsFocusable()
- IsFocused()
- IsShowing()
- LostFocus(Libraries.Interface.Events.FocusEvent event)
- RemoveFocusListener(Libraries.Interface.Events.FocusListener listener)
- RemoveGestureListener(Libraries.Interface.Events.GestureListener listener)
- RemoveMouseListener(Libraries.Interface.Events.MouseListener listener)
- RemoveMouseMovementListener(Libraries.Interface.Events.MouseMovementListener listener)
- RemoveMouseWheelListener(Libraries.Interface.Events.MouseWheelListener listener)
- RemoveTouchListener(Libraries.Interface.Events.TouchListener listener)
- SetAcceptsMouseInput(boolean accepts)
- SetAccessibilityCode(integer newAccessibilityCode)
- SetAccessibilityRoleDescription(text newRoleDescription)
- SetDescription(text newDescription)
- SetFocusable(boolean focus)
- SetInputGroup(text group)
- SetName(text newName)
- SetNextFocus(Libraries.Interface.Item next)
- SetPreviousFocus(Libraries.Interface.Item previous)
- SetProperty(text key, Libraries.Data.Formats.JavaScriptObjectNotation value)
- Update(number secondsSinceUpdate)
- UpdateAll(number secondsSinceUpdate)
216 actions from Libraries.Interface.Item3D
- Add(Libraries.Interface.Item3D newItem)
- Add(integer index, Libraries.Interface.Item3D newItem)
- AddShadowLight(integer bit, integer frame)
- ApplyAngularImpulse(Libraries.Compute.Vector3 impulse)
- ApplyDamping(number seconds)
- ApplyForce(Libraries.Compute.Vector3 force, Libraries.Compute.Vector3 point)
- ApplyForceToCenter(Libraries.Compute.Vector3 force)
- ApplyImpulse(Libraries.Compute.Vector3 impulse, Libraries.Compute.Vector3 localPositionToApply)
- ApplyLinearImpulse(Libraries.Compute.Vector3 impulse, Libraries.Compute.Vector3 point)
- ApplyLinearImpulseToCenter(Libraries.Compute.Vector3 impulse)
- ApplyTorque(Libraries.Compute.Vector3 torque)
- ApplyTorqueImpulse(Libraries.Compute.Vector3 torque)
- CanRotate(boolean flag)
- CollideWithChildren()
- ComputeAngularImpulseDenominator(Libraries.Compute.Vector3 axis)
- ComputeImpulseDenominator(Libraries.Compute.Vector3 position, Libraries.Compute.Vector3 normal)
- CreateNodes(Libraries.Game.Collision.BroadphaseCollision3D broadphase, Libraries.Game.Collision.PhysicsPosition3D transform)
- DestroyNodes(Libraries.Game.Collision.BroadphaseCollision3D broadphase)
- Draw(Libraries.Game.Graphics.Painter3D painter)
- Empty()
- EnablePhysics(boolean flag)
- FastMoving(boolean flag)
- GetAccessibilityCursor()
- GetAccessibleParent()
- GetAngularDamping()
- GetAngularFactor()
- GetAngularVelocity()
- GetBoundingBox(integer childIndex)
- GetCenterOfMassPosition()
- GetCenterOfMassTransform()
- GetCollisionGroupFlag()
- GetCollisionGroupIndex()
- GetCollisionList()
- GetCollisionTransform()
- GetCollisionTransform0()
- GetDepth()
- GetDimensions()
- GetDrawnTransform()
- GetForce()
- GetFriction()
- GetGlobalPosition()
- GetGlobalX()
- GetGlobalY()
- GetGlobalZ()
- GetHeight()
- GetInterpolatedAngularVelocity()
- GetInterpolatedLinearVelocity()
- GetInterpolationTransform()
- GetInterpolationWorldTransform()
- GetInverseInertiaLocal()
- GetInverseInertiaWorld()
- GetInverseMass()
- GetItem(integer index)
- GetItemCount()
- GetItems()
- GetJointList()
- GetLayer()
- GetLights(Libraries.Containers.Array<Libraries.Game.Graphics.Light> array)
- GetLights()
- GetLinearDamping()
- GetLinearVelocity()
- GetLinearVelocityAtLocalPoint(Libraries.Compute.Vector3 relativePosition)
- GetMass()
- GetNode(integer index)
- GetNodeCount()
- GetNodes()
- GetOffsetX()
- GetOffsetY()
- GetOffsetZ()
- GetOrientation()
- GetParent()
- GetPhysicsProperties()
- GetPitch()
- GetPosition()
- GetPushVelocity()
- GetRenderBounds(Libraries.Game.BoundingBox local)
- GetResponsiveness()
- GetRestitution()
- GetRoll()
- GetRotationTransform()
- GetScaleX()
- GetScaleY()
- GetScaleZ()
- GetScreenBounds()
- GetScreenBoundsOfBox(Libraries.Game.BoundingBox box)
- GetScreenX()
- GetScreenY()
- GetShadowLightMask(integer frame)
- GetShape()
- GetShapeOffset()
- GetShapeTransform()
- GetShapeType()
- GetSleepTime()
- GetTimeOfImpact()
- GetTorque()
- GetTransform()
- GetTurnVelocity()
- GetWidth()
- GetX()
- GetY()
- GetYaw()
- GetZ()
- HasMoved()
- HasReportedMove()
- HasShapeOffset()
- IntegrateVelocities(number seconds)
- InternalApplyImpulse(Libraries.Compute.Vector3 linearComponent, Libraries.Compute.Vector3 angularComponent, number impulseMagnitude)
- IsCollidable()
- IsEmpty()
- IsFastMoving()
- IsNonResponsive()
- IsOnLayer()
- IsPhysicsEnabled()
- IsResponsive()
- IsRotationAllowed()
- IsSimulated()
- IsSimulationRequired()
- IsUnmovable()
- Move(Libraries.Compute.Vector3 vector)
- Move(number xAmount, number yAmount, number zAmount)
- MoveX(number xAmount)
- MoveY(number yAmount)
- MoveZ(number zAmount)
- NotifyMoved()
- PredictIntegratedTransform(number seconds, Libraries.Game.Collision.PhysicsPosition3D predictedTransform)
- ProceedToTransform(Libraries.Game.Collision.PhysicsPosition3D transform)
- ProcessGestureEvent(Libraries.Interface.Events.GestureEvent event)
- ProcessMouseEvent(Libraries.Interface.Events.MouseEvent event)
- ProcessTouchEvent(Libraries.Interface.Events.TouchEvent event)
- Remove(integer index)
- Remove(Libraries.Interface.Item3D removed)
- RequireSimulation(boolean flag)
- ResetMass()
- Rotate(Libraries.Compute.Vector3 vector, number degrees, boolean rotateChildren)
- Rotate(Libraries.Compute.Vector3 vector, number degrees)
- Rotate(number rotateX, number rotateY, number rotateZ, number degrees)
- Rotate(number rotateX, number rotateY, number rotateZ, number degrees, boolean rotateChildren)
- RotateAround(Libraries.Compute.Vector3 point, Libraries.Compute.Vector3 axis, number degrees)
- RotateAround(Libraries.Compute.Vector3 point, Libraries.Compute.Vector3 axis, number degrees, boolean rotateChildren)
- RotateChildren(number rotateX, number rotateY, number rotateZ, number degrees)
- RotateChildren(Libraries.Compute.Vector3 vector, number degrees)
- SaveKinematicState(number time)
- Scale(Libraries.Compute.Vector3 vector)
- Scale(Libraries.Compute.Vector3 vector, boolean scaleChildren)
- Scale(number scaleX, number scaleY, number scaleZ, boolean scaleChildren)
- Scale(number scaleX, number scaleY, number scaleZ)
- SetAngularDamping(number angularDamping)
- SetAngularVelocity(Libraries.Compute.Vector3 angularVelocity)
- SetCenterOfMassTransform(Libraries.Game.Collision.PhysicsPosition3D transform)
- SetCollidable(boolean flag)
- SetCollideWithChildren(boolean flag)
- SetCollisionGroupFlag(boolean flag)
- SetCollisionGroupIndex(integer index)
- SetCollisionList(Libraries.Game.Collision.CollisionEdge3D list)
- SetCollisionTransform(Libraries.Game.Collision.PhysicsPosition3D transform)
- SetCollisionTransform0(Libraries.Game.Collision.PhysicsPosition3D transform)
- SetDepth(number setDepth)
- SetDimensions(number setWidth, number setHeight, number setDepth)
- SetDimensions(Libraries.Compute.Vector3 vector)
- SetDrawnTransform(Libraries.Game.Collision.PhysicsPosition3D transform)
- SetForce(Libraries.Compute.Vector3 force)
- SetFriction(number friction)
- SetHasMoved(boolean flag)
- SetHeight(number setHeight)
- SetInterpolatedAngularVelocity(Libraries.Compute.Vector3 velocity)
- SetInterpolatedLinearVelocity(Libraries.Compute.Vector3 velocity)
- SetInterpolationTransform(Libraries.Game.Collision.PhysicsPosition3D transform)
- SetItem(integer index, Libraries.Interface.Item3D newItem)
- SetJointList(Libraries.Game.Physics.Joints.JointEdge3D list)
- SetLayer(Libraries.Game.Layer3D parentLayer)
- SetLinearDamping(number linearDamping)
- SetLinearVelocity(Libraries.Compute.Vector3 linearVelocity)
- SetLinearVelocityX(number linearVelocityX)
- SetLinearVelocityY(number linearVelocityY)
- SetLinearVelocityZ(number linearVelocityZ)
- SetMass(number mass)
- SetNonResponsive()
- SetOffset(Libraries.Compute.Vector3 vector)
- SetOffset(number xAmount, number yAmount, number zAmount)
- SetOffsetX(number xAmount)
- SetOffsetY(number yAmount)
- SetOffsetZ(number zAmount)
- SetParent(Libraries.Interface.Item3D newItem)
- SetPhysicsProperties(Libraries.Game.Physics.PhysicsProperties3D properties)
- SetPosition(Libraries.Compute.Vector3 vector)
- SetPosition(number setX, number setY, number setZ)
- SetReportedMove(boolean value)
- SetResponsive()
- SetResponsiveness(integer type)
- SetRestitution(number restitution)
- SetRotationTransform(Libraries.Compute.Matrix4 source)
- SetScale(number scaleX, number scaleY, number scaleZ)
- SetScale(number scaleX, number scaleY, number scaleZ, boolean scaleChildren)
- SetScaleX(number scale)
- SetScaleX(number scale, boolean scaleChildren)
- SetScaleY(number scale, boolean scaleChildren)
- SetScaleY(number scale)
- SetScaleZ(number scale, boolean scaleChildren)
- SetScaleZ(number scale)
- SetScreenPositionFromPhysicsPosition()
- SetShape(Libraries.Game.Collision.Shapes.CollisionShape3D shape)
- SetShapeOffset(number x, number y, number z)
- SetSleepTime(number time)
- SetTimeOfImpact(number timeOfImpact)
- SetTorque(Libraries.Compute.Vector3 torque)
- SetUnmovable()
- SetWidth(number setWidth)
- SetX(number setX)
- SetY(number setY)
- SetYawPitchRoll(number yaw, number pitch, number roll)
- SetZ(number setZ)
- ShouldCollide(Libraries.Interface.Item3D otherItem)
- Simulate(boolean flag)
- SimulationChanged()
- SynchronizeNodes()
- UpdateInertia()