Camera

Controls what part of the world is currently on the screen, and at what zoom level.

About

This is a global object that can always be accessed.

Usage

GetCamera:Reset();

Changing Map

Use MapManager::SetActiveMapByName to change which map the Camera is showing.

Position And Scale

SetPos

nil SetPos(Vector2 vPos)

Parameters

vPosA Vector2 object containing the new position of the Camera in world coordinates.  This point will be the upper-left of the screen.

GetPos

Vector2 SetPos()

Returns

A Vector2 with the world coordinates of where the upper-left of the screen is located.

SetPosCentered

nil SetPosCentered(Vector2 vPos)

Like SetPos but automatically centers the camera on it, taking into account the current screen size.

Parameters

vPosA Vector2 object containing the new position that the Camera should center on in world coordinates.

GetPosCentered

Vector2 GetPosCentered()

Returns

The world coordinates of the exact middle of the screen.

SetScale

nil SetScale(Vector2 vPos)

Scale determines how “zoomed in/zoomed out” the Camera is.  A scale of 1,1 means exactly the size of the pixels.  (normally what you want)

Note

If the X/Y scale that are sent are not the same, this creates a “stretched” effect on the whole screen, could be a useful effect for something.

Parameters

vPosA Vector2 object containing the new magnification.  Will be clipped to the valid range of 40,40 (zoomed waaay in) to 0.01,0.01 (zoomed waaay out).

GetScale

Vector2 GetScale()

Returns

The current scale magnification level.

Tracking And Control

SetEntityTrackingByID

nil SetEntityTrackingByID(number entityID)

This tells the camera to follow around an Entity.  It attempts to keep the Entity in the middle of the screen, by lerping to its position.

Use SetMoveLerp to make the camera more or less snappy/responsive.

This always overrides SetPosTarget.

Note

The Camera is smart enough to follow entities through doors/warps even if they move to a new Map.

Parameters

entityIDThe ID of an Entity you’d like the Camera to follow around.  Send <C_ENTITY_NONE> to disable entity tracking.

GetEntityTrackingByID

number GetEntityTrackingByID()

Returns

The entityID of the Entity we’re tracking or <C_ENTITY_NONE> if none.

SetEntityTrackingOffset

nil SetEntityTrackingOffset(Vector2 vOffset)

When you’ve set SetEntityTrackingByID you may wish to fine tune what the camera focuses on.  By default, this is set to 0,40.  In other words, it looks above the feet by 40 units, so when we zoom in we don’t see a close-up of the feet in the treeworld example.

If your game is top view, you probably should set this to Vector2(0,0) so the true center of the entity (as determined by its collision usually) is used.

Note

This value is automatically scaled by the cameras current scale/zoom.

Parameters

vOffseta Vector2 object containing the offset the camera should use.

GetEntityTrackingByID

number GetEntityTrackingByID()

Returns

The entityID of the Entity we’re tracking or <C_ENTITY_NONE> if none.

SetLimitToMapArea

nil SetLimitToMapArea(boolean bLimitToMapArea)

If your player is standing on the bottom of a map, but it annoys you that he’s still centered in the camera, this function is for you.

If enabled, it will automatically scan each map at load time and figure out its dimensions.  To manually set the viewable area, use <Map:SetWorldRect> or <Map:ComputeWorldRect> to re-scan if the map size changes.

Parameters

bLimitToMapAreaif true, the camera will attempt to limit the view to the active areas of the map

GetLimitToMapArea

boolean GetLimitToMapArea()

Returns

True if the camera is currently limiting its view to the active map area.

SetPosTarget

nil SetPosTarget(Vector2 vPos)

This is like SetPos except instead of being instantaneous, the Camera smoothly moves to the new position.

Parameters

vPosA Vector2 object containing the target position.

SetPosCenteredTarget

nil GetPosCenteredTarget(Vector2 vPos)

This is like SetPosCentered except instead of being instantaneous, the Camera smoothly moves to the new position.

Parameters

vPosA Vector2 object containing the target position.

SetScaleTarget

nil SetScaleTarget(Vector2 vPos)

This is like SetScale except instead of being instantaneous, the Camera smoothly scales up/down to the new scale.

Parameters

vPosA Vector2 object containing the new X and Y scale.

Interpolation Settings

SetMoveLerp

nil SetMoveLerp(number lerpSpeed)

This controls how fast the Camera moves when SetPosTarget or SetEntityTrackingByID is used.

Parameters

lerpSpeed1 for instant, 0.01 for slow.  Default is 0.3.

SetScaleLerp

nil SetScaleLerp(number lerpSpeed)

This controls how fast the Camera scales in and out when SetScaleTarget is used.

Parameters

lerpSpeed1 for instant, 0.01 for slow.  Default is 0.3.

Miscellaneous

Reset

nil Reset()

Resets everything to the default Camera settings and moves the position to 0,0.

InstantUpdate

nil InstantUpdate()

Makes the camera “catch up” with any tracking/targeting that is active, without waiting for the lerping to happen.

SetCameraSettings

nil SetCameraSettings(CameraSettings camSettings)

Set’s the Camera to specific state, that was previously remembered with GetCameraSettings.

Parameters

camSettingsA CameraSettings object.

GetCameraSettings

CameraSettings GetCameraSettings()

If you’d like to save the state information about the camera so you can quickly return to that view, this is an easy way to do it.

Returns

A CameraSettings object.

Controls what part of the world is currently on the screen, and at what zoom level.
The Vector2 object.
The Entity object.
A map is a single area that can be any size and contain any amount of tiles, including Entities and TilePic’s.
A simple data object that contains state information for the camera.