Cameras
Cameras determine what part of the world is visible on the screen. It is possible to have multiple cameras in a game, each with its own position, zoom level, and viewport on the screen. See Learn > Graphics > Cameras to learn more about how to use cameras in Easel.
Camera
this.Camera<Id = auto>([body], radius?=, freeRadius?, maxScreenSizePx?, stencil?, acquireRate?, panningRate?, transitionRate?, priority?, [audience?, owner?, camera?])
delete this.Camera<Id>
Determines the target position of the camera for a given audience.
-
this(Entity): Determines the lifespan of the camera. Whenthisdespawns, the camera will be deleted. -
Id: An optional discriminator to allow for multipleCameras on the same entity.
Position:
body(Entity or Vector): Determines the position. Ifbodyis an Entity, the camera will track the position of the entity's Body. Ifbodyis a Vector, the camera will be fixed at that position. Defaults tothis.
Zoom:
-
radius(Number or Vector): Controls the zoom level of the camera. The camera will zoom in or out to ensure this radius is visible. Provide a Number to set both the horizontal and vertical radius to the same value. Provide a Vector to separately define a different horizontal and vertical radius. Defaults to50. -
freeRadius(Number): When the camera is within this distance of thebodyit will stop moving, allowingbodyto freely move around within this radius without affecting the camera. Defaults to0.
Transition:
-
acquireRate(Number): When the camera is acquiring its target for the first time, this parameter controls the rate at which the camera finds its target position, where1is instant and0is never. A value of0.25means the camera will move 25% of the way to its target position each frame. Once the camera has acquired its target, it then switches to usingpanningRate. Defaults totransitionRate. -
panningRate(Number): After the camera has acquired its target already, this parameter controls the rate at which the camera finds its target position, where1is instant and0is never. A value of0.25means the camera will move 25% of the way to its target position each frame. Defaults totransitionRate. -
transitionRate(Number): Sets bothacquireRateandpanningRatewith one parameter, if they are not otherwise specified. Defaults to1(instant).
Stencil:
stencil(Boolean): Iftrue, the camera will only render inside the areas defined by any stencil components such as PolygonStencil. Iffalse, the camera will render everything, ignoring any stencils. If nullish, will default totrueif any stencil components are present for the camera, orfalseotherwise.
Viewer:
-
camera(Entity or Array of Entities): Determines which camera(s) will have its target position set. Defaults toWorld(the main camera). -
audience(Entity, Symbol or Flag): If provided, sets the camera position only for the specified audience. Defaults to the value ofowner. See Audience. -
owner(Entity): The player or team who owns the camera. Only used to interpret theaudienceparameter. -
priority(Number): Only theCamerawith the highest priority will be used. Must be an integer between-128and127. Defaults to0. -
maxScreenSizePx(Number): If specified, the camera will only be used when the screen width or height is less than or equal to this value, in pixels.
Deprecated parameters:
aspectRatio: This parameter has now been moved to Viewport. It will still be accepted here for legacy reasons, but may be removed in a future update.
CameraBoundary
this.CameraBoundary<Id = auto>(left?=, right?, top?, bottom?, priority?, [audience?, owner?, camera?])
delete this.CameraBoundary<Id>
Limits the viewable area of the camera for a given audience. The camera's position will be clamped to only show areas within the specified boundaries. If the camera's radius is too big, the camera will also be forced to zoom in order to fit within the boundaries.
-
this(Entity): Determines the lifespan of the camera. Whenthisdespawns, the camera will be deleted. -
Id: An optional discriminator to allow for multipleCameraBoundarys on the same entity. -
left(Number): If supplied, the leftmost boundary of the camera. -
right(Number): If supplied, the rightmost boundary of the camera. -
top(Number): If supplied, the topmost boundary of the camera. -
bottom(Number): If supplied, the bottommost boundary of the camera. -
audience(Entity, Symbol or Flag): If provided, sets the camera boundaries only for the specified audience. Defaults to the value ofowner. See Audience. -
owner(Entity): The player or team who owns the camera. Only used to interpret theaudienceparameter. -
priority(Number): Only theCameraBoundarywith the highest priority will be used. Must be an integer between-128and127. Defaults to0. -
camera(Entity or Array of Entities): Determines which camera(s) will have its boundaries set. Defaults toWorld(the main camera).
Subcamera
camera.Subcamera(parent?, radiusMultiplier?=, stencil?)
Makes camera a subcamera of a parent camera.
A subcamera's position and zoom is locked relative to its parent camera.
If the parent camera moves or zooms, the subcamera will follow.
This can be used to create parallax effects.
-
camera(Entity): Determines which camera to make into a subcamera. -
parent(Entity): Determines the parent camera from which to take the position and radius. Defaults toWorld(the main camera). -
radiusMultiplier(Number): The subcamera's radius will be the parent camera's radius multiplied this value. Defaults to1. -
stencil(Boolean): Iftrue, the camera will only render inside the areas defined by any stencil components such as PolygonStencil. Iffalse, the camera will render everything, ignoring any stencils. If nullish, will default totrueif any stencil components are present for the camera, orfalseotherwise.
Example:
pub const Camera:Main = World
pub const Camera:Background = Spawn camera {
Subcamera(Camera:Main, radiusMultiplier=2)
Viewport(order=-1) // Place behind the main camera
}
Viewport
this.Viewport<Id = auto>(order?=, scale?, aspectRatio?, width?, height?, anchor?, offset?, pointer?, priority?, [audience?, owner?, camera?])
delete this.Viewport<Id>
Determines where on the screen the camera's view will be rendered.
-
this(Entity): Determines the lifespan of the viewport. Whenthisdespawns, the viewport will be deleted. -
Id: An optional discriminator to allow for multipleViewports on the same entity.
Position:
-
anchor(Vector): Sets the anchor point of the viewport on the screen. A value of@(0,0)places the viewport in the middle of the screen. A value of@(-1,-1)places the viewport in the top-left corner, while a value of@(1,1)places it in the bottom-right corner. You will only notice the effect of this parameter when the viewport is smaller than the screen. -
offset(Vector): An additional offset to apply to the viewport's position on the screen, inemunits.
Size:
-
width(Number): Sets the width of the viewport inemunits. Defaults to the full width of the screen. -
height(Number): Sets the height of the viewport inemunits. Defaults to the full height of the screen. -
aspectRatio(Number): The desired aspect ratio (width divided by height) of the viewport. The viewport will be sized to be as large as possible within the specifiedwidthandheightwhile maintaining this aspect ratio. Defaults to the aspect ratio of the screen. -
scale(Number): The size of the viewport will be scaled by this factor. A value of0.5would halve both the width and height of the viewport. Defaults to1.0.
Z-order:
order(Number): Viewports with a higherordernumber will be rendered on top of viewports with a lower number. Must be an integer in the range-128to127. Defaults to0.
Pointer:
pointer(Boolean): Iftrue, the position of the Pointer will be transformed from screen space to world space using this viewport's camera. If multipleViewports havepointerset totrue, the one with the highestorderwill take precedence (i.e. the one on top). If noViewports havepointerset totrue, the main camera (World) will be used. Defaults tofalse.
Viewer:
-
audience(Entity, Symbol or Flag): If provided, sets the viewport only for the specified audience. Defaults to the value ofowner. See Audience. -
owner(Entity): The player or team who owns the viewport. Only used to interpret theaudienceparameter. -
priority(Number): Only theViewportwith the highest priority will be used for eachcamera. Must be an integer between-128and127. Defaults to0. -
camera(Entity or Array of Entities): The camera(s) to set the viewport for. Defaults toWorld(the main camera).