Skip to main content
Version: bleeding-edge ๐Ÿฉธ

๐Ÿ“บ Viewport

Work with screen properties and effects

๐Ÿ—ฟStatic ClassClient Only๐Ÿง‘โ€๐Ÿ’ปAPI Source

๐Ÿ—ฟ Static Functionsโ€‹

DeprojectScreenToWorld: tableTransforms a 2D screen coordinates into 3D world-space location
GetMousePosition: Vector2DGets the current mouse screen location
GetViewportScale: floatGets the scale of viewport
GetViewportSize: Vector2DGets the size of viewport
ProjectWorldToScreen: Vector2DTransforms a 3D world-space vector into 2D screen coordinates
SetBloodScreenEnabledEnables/Disables the Blood Screen effect
SetBloodScreenIntensityManually sets the Blood Screen intensity
SetBrandingBarSettingsSets the Branding Bar settings (the bar with 'nanos world - closed alpha ver...')
SetCrosshairEnabledEnables/Disables the Crosshair
SetHardwareCursorLoads and sets a hardware cursor in the game from a PNG image
SetInteractionToolTipEnabledEnables/Disables the Interaction ToolTip
SetMousePositionSets the mouse position
Subscribe: functionSubscribes to an Event
UnsubscribeUnsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

DeprojectScreenToWorldModerateโ€‹

Transforms a 2D screen coordinates into 3D world-space location

local ret = Viewport.DeprojectScreenToWorld(screen_position)
Parameters
NameTypeDescription
screen_positionVector2DScreen position
Returns
TypeDescription
tableTable with the world <code>Position</code> and the <code>Direction</code> the screen point looks at
Table keys
NameTypeDescription
PositionVectorNo description provided
DirectionVectorNo description provided

GetMousePositionOptimalโ€‹

Gets the current mouse screen location

local ret = Viewport.GetMousePosition()
Returns
TypeDescription
Vector2DThe current mouse screen location

See also SetMousePosition.

GetViewportScaleOptimalโ€‹

Gets the scale of viewport

local ret = Viewport.GetViewportScale()
Returns
TypeDescription
floatThe scale of viewport

GetViewportSizeOptimalโ€‹

Gets the size of viewport

local ret = Viewport.GetViewportSize()
Returns
TypeDescription
Vector2DThe size of viewport

ProjectWorldToScreenModerateโ€‹

Transforms a 3D world-space vector into 2D screen coordinates

local ret = Viewport.ProjectWorldToScreen(world_position)
Parameters
NameTypeDescription
world_positionVectorWorld 3D position
Returns
TypeDescription
Vector2DThe screen position, in pixels

SetBloodScreenEnabledOptimalโ€‹

Enables/Disables the Blood Screen effect

Viewport.SetBloodScreenEnabled(is_enabled)
Parameters
NameTypeDescription
is_enabledbooleanWhether to enable the Blood Screen effect

SetBloodScreenIntensityOptimalโ€‹

Manually sets the Blood Screen intensity

If you don't want the Blood Screen to be overridden by the default damage effect, disable it first with Viewport.SetBloodScreenEnabled(false)

Viewport.SetBloodScreenIntensity(intensity)
Parameters
NameTypeDescription
intensityfloatFrom 0.0 to 1.0

SetBrandingBarSettingsOptimalโ€‹

Sets the Branding Bar settings (the bar with 'nanos world - closed alpha ver...')

Viewport.SetBrandingBarSettings(horizontal_alignment, vertical_alignment, is_lean?)
Parameters
NameTypeDescription
horizontal_alignmentWidgetHorizontalAlignmentLeft, Center and Right supported
vertical_alignmentWidgetVerticalAlignmentBottom and Top supported
is_lean?booleanWhether to show less information Default false

SetCrosshairEnabledOptimalโ€‹

Enables/Disables the Crosshair

Viewport.SetCrosshairEnabled(is_enabled)
Parameters
NameTypeDescription
is_enabledbooleanWhether to enable the Crosshair

SetHardwareCursorSlowโ€‹

Loads and sets a hardware cursor in the game from a PNG image

Note: due an engine limitation modifying an already set cursor image will not change the cursor until the game is restarted

Viewport.SetHardwareCursor(cursor_shape, cursor_path, hotspot?)
Parameters
NameTypeDescription
cursor_shapeCursorTypeWhich cursor shape to replace
cursor_pathImage Patha PNG image relative to Assets/
hotspot?Vector2DClick point of the cursor image, in pixels Default Vector(0, 0)

SetInteractionToolTipEnabledOptimalโ€‹

Enables/Disables the Interaction ToolTip

Viewport.SetInteractionToolTipEnabled(is_enabled)
Parameters
NameTypeDescription
is_enabledbooleanWhether to enable the Interaction ToolTip

SetMousePositionOptimalโ€‹

Sets the mouse position

Viewport.SetMousePosition(new_position)
Parameters
NameTypeDescription
new_positionVector2DThe new mouse position

See also GetMousePosition.

SubscribeOptimalโ€‹

Subscribes to an Event

local ret = Viewport.Subscribe(event_name, callback)
Parameters
NameTypeDescription
event_namestringEvent to subscribe to
callbackfunctionCallback to run on the event occurring
Returns
TypeDescription
functionThe function callback

UnsubscribeOptimalโ€‹

Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback

Viewport.Unsubscribe(event_name, callback?)
Parameters
NameTypeDescription
event_namestringEvent to unsubscribe to
callback?functionOptional callback to specifically unsubscribe to Default nil

๐Ÿš€ Eventsโ€‹

ResizeCalled when the screen is resized

Resizeโ€‹

Called when the screen is resized

Viewport.Subscribe("Resize", function(new_size)
-- Resize was called
end)
Arguments
NameTypeDescription
new_sizeVector2DThe new screen size