Controls what part of the world is currently on the screen, and at what zoom level.
This is a global object that can always be accessed.
GetCamera:Reset();
Use MapManager::SetActiveMapByName to change which map the Camera is showing.
Vector2 SetPos()
A Vector2 with the world coordinates of where the upper-left of the screen is located.
Vector2 GetPosCentered()
The world coordinates of the exact middle of the screen.
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)
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.
vPos | A 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). |
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.
The Camera is smart enough to follow entities through doors/warps even if they move to a new Map.
entityID | The ID of an Entity you’d like the Camera to follow around. Send <C_ENTITY_NONE> to disable entity tracking. |
number GetEntityTrackingByID()
The entityID of the Entity we’re tracking or <C_ENTITY_NONE> if none.
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.
This value is automatically scaled by the cameras current scale/zoom.
vOffset | a Vector2 object containing the offset the camera should use. |
number GetEntityTrackingByID()
The entityID of the Entity we’re tracking or <C_ENTITY_NONE> if none.
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.
bLimitToMapArea | if true, the camera will attempt to limit the view to the active areas of the map |
boolean GetLimitToMapArea()
True if the camera is currently limiting its view to the active map area.
nil GetPosCenteredTarget(Vector2 vPos)
This is like SetPosCentered except instead of being instantaneous, the Camera smoothly moves to the new position.
vPos | A Vector2 object containing the target position. |
nil SetMoveLerp(number lerpSpeed)
This controls how fast the Camera moves when SetPosTarget or SetEntityTrackingByID is used.
lerpSpeed | 1 for instant, 0.01 for slow. Default is 0.3. |
nil SetScaleLerp(number lerpSpeed)
This controls how fast the Camera scales in and out when SetScaleTarget is used.
lerpSpeed | 1 for instant, 0.01 for slow. Default is 0.3. |
nil Reset()
Resets everything to the default Camera settings and moves the position to 0,0.
nil InstantUpdate()
Makes the camera “catch up” with any tracking/targeting that is active, without waiting for the lerping to happen.
nil SetCameraSettings(CameraSettings camSettings)
Set’s the Camera to specific state, that was previously remembered with GetCameraSettings.
camSettings | A CameraSettings object. |
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.
A CameraSettings object.