๐ผ๏ธ Canvas
Canvas is an entity which you can draw onto it
๐ Examplesโ
-- Spawns a Canvas
local my_canvas = Canvas(
true,
Color.TRANSPARENT,
0,
true
)
-- Subscribes for Update, we can only Draw inside this event
my_canvas:Subscribe("Update", function(self, width, height)
-- Draws a Text in the middle of the screen
self:DrawText("Hello World!", Vector2D(width / 2, height / 2))
-- Draws a red line Horizontally
self:DrawLine(Vector2D(0, height / 2), Vector2D(width, height / 2), 10, Color.RED)
end)
-- Forces the canvas to repaint, this will make it trigger the Update event
my_canvas:Repaint()
-- Applies the Canvas as the material of a (client side) StaticMesh
local my_mesh = StaticMesh(Vector(0, 0, 100), Rotator(), "nanos-world::SM_Cube")
my_mesh:SetMaterialFromCanvas(my_canvas)
You can use the output Texture from a Canvas with :SetMaterialFromCanvas() method!
๐ Constructorsโ
Default Constructorโ
No description provided
local my_canvas = Canvas(is_visible?, clear_color?, auto_repaint_rate?, should_clear_before_update?, auto_resize?, width?, height?, screen_position?)
Parameters
| Name | Type | Description |
|---|---|---|
is_visible? | boolean | Whether to draw it on screen Default true |
clear_color? | Color | Color to clear with (background color) Default Color.TRANSPARENT |
auto_repaint_rate? | float | Rate to auto repaint (call Update event), pass 0 for every frame, -1 to disable Default -1 |
should_clear_before_update? | boolean | Whether to clear with Clear Color before updates Default true |
auto_resize? | boolean | Auto resize with screen's size Default true |
width? | integer | If not using auto_resize Default 0 |
height? | integer | If not using auto_resize Default 0 |
screen_position? | Vector2D | If not using auto_resize, offset when drawing to screen Default Vector2D(0, 0) |
๐ฟ Static Functionsโ
This class doesn't have own static functions.
Inherited static functions
Subscribe, UnsubscribeSubscribeRemoteGetAll, GetByIndex, GetCount, GetPairs๐ฆ Functionsโ
| Drawing | ||
DrawBox | Draws an unfilled box on the Canvas | |
DrawLine | Draws a line on the Canvas | |
DrawMaterial | Draws a Material on the Canvas | |
DrawMaterialFromSceneCapture | Draws a SceneCapture on the Canvas | |
DrawMaterialFromWebUI | Draws a WebUI on the Canvas | |
DrawPolygon | Draws a N-Polygon on the Canvas | |
DrawRect | Draws a filled Rect on the Canvas | |
DrawText | Draws a Text on the Canvas | |
DrawTexture | Draws a Texture on the Canvas | |
| Layout | ||
GetSize: Vector2D | Gets the Canvas Size | |
Resize | Resizes the Canvas if not using auto_resize | |
SetAutoResize | Sets if the canvas should auto resize to screen size | |
SetScreenPosition | Sets the Canvas Screen Position offset | |
SetVisibility | Sets if it's visible on screen | |
| Rendering | ||
Clear | Clear the Canvas with a specific Color | |
Repaint | Forces the repaint | |
SetAutoRepaintRate | Sets the repaint rate | |
Inherited functions
GetAllValuesKeys, GetValue, SetValueSubscribe, UnsubscribeDestroy, FinishSpawn, IsBeingDestroyed, IsSpawned, IsValid, SetSpawnModeBroadcastRemoteEvent, BroadcastRemoteInRadiusEvent, CallRemoteEvent, CallRemoteEvent, CallRemotePlayersEvent, HasAuthority, SubscribeRemoteGetIDDrawingfunctionsโ

DrawBoxModerateโ
Draws an unfilled box on the Canvas
This method can only be called from inside Update event
my_canvas:DrawBox(screen_position, screen_size, thickness, render_color?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
thickness | float | Line thickness |
render_color? | Color | Color to tint the drawing with Default Color.WHITE |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawLineModerateโ
Draws a line on the Canvas
This method can only be called from inside Update event
my_canvas:DrawLine(screen_position_a, screen_position_b, thickness, render_color, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
screen_position_a | Vector2D | Start position of the line, in pixels |
screen_position_b | Vector2D | End position of the line, in pixels |
thickness | float | Line thickness |
render_color | Color | Color to tint the drawing with |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawMaterialModerateโ
Draws a Material on the Canvas
This method can only be called from inside Update event
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved
my_canvas:DrawMaterial(material_path, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
material_path | Material Reference | The Material asset to use |
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
coordinate_position | Vector2D | Top-left UV coordinate of the source to draw (0 to 1) |
coordinate_size? | Vector2D | UV size of the source to draw (0 to 1), use (1, 1) for the whole source Default Vector2D(1, 1) |
rotation? | float | Rotation in degrees Default 0 |
pivot_point? | Vector2D | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) Default Vector2D(0.5, 0.5) |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawMaterialFromSceneCaptureModerateโ
Draws a SceneCapture on the Canvas
This method can only be called from inside Update event
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved
my_canvas:DrawMaterialFromSceneCapture(scenecapture_entity, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
scenecapture_entity | SceneCapture | The SceneCapture to draw |
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
coordinate_position | Vector2D | Top-left UV coordinate of the source to draw (0 to 1) |
coordinate_size? | Vector2D | UV size of the source to draw (0 to 1), use (1, 1) for the whole source Default Vector2D(1, 1) |
rotation? | float | Rotation in degrees Default 0 |
pivot_point? | Vector2D | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) Default Vector2D(0.5, 0.5) |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawMaterialFromWebUIModerateโ
Draws a WebUI on the Canvas
This method can only be called from inside Update event
Note: Due how Unreal handles Render Targets, drawing material on Canvas result on a weird translucent effect. Hope in the future to be improved
my_canvas:DrawMaterialFromWebUI(webui_entity, screen_position, screen_size, coordinate_position, coordinate_size?, rotation?, pivot_point?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
webui_entity | WebUI | The WebUI to draw |
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
coordinate_position | Vector2D | Top-left UV coordinate of the source to draw (0 to 1) |
coordinate_size? | Vector2D | UV size of the source to draw (0 to 1), use (1, 1) for the whole source Default Vector2D(1, 1) |
rotation? | float | Rotation in degrees Default 0 |
pivot_point? | Vector2D | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) Default Vector2D(0.5, 0.5) |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawPolygonModerateโ
Draws a N-Polygon on the Canvas
This method can only be called from inside Update event
my_canvas:DrawPolygon(texture_path, screen_position, radius?, number_of_sides?, render_color?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
texture_path | Image Path | Pass empty to use default white Texture |
screen_position | Vector2D | Position on the Canvas, in pixels |
radius? | Vector2D | Radius of the polygon on each axis, in pixels Default Vector2D(1, 1) |
number_of_sides? | integer | How many sides the polygon has Default 3 |
render_color? | Color | Color to tint the drawing with Default Color.WHITE |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawRectModerateโ
Draws a filled Rect on the Canvas
Draws a fille Rect on the Canvas
This method can only be called from inside Update event
my_canvas:DrawRect(texture_path, screen_position, screen_size, render_color?, blend_mode?)
Parameters
| Name | Type | Description |
|---|---|---|
texture_path | Image Path | Pass empty to use default white Texture |
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
render_color? | Color | Color to tint the drawing with Default Color.WHITE |
blend_mode? | BlendMode | How it blends with what is already drawn Default BlendMode.Opaque |

DrawTextModerateโ
Draws a Text on the Canvas
This method can only be called from inside Update event
Shadow and Outline won't work properly with Transparent clear_color
my_canvas:DrawText(text, screen_position, font_type?, font_size?, text_color?, kerning?, center_x?, center_y?, shadow_color?, shadow_offset?, outlined?, outline_color?)
Parameters
| Name | Type | Description |
|---|---|---|
text | string | The text to draw |
screen_position | Vector2D | Position on the Canvas, in pixels |
font_type? | FontType | Font to use Default FontType.Roboto |
font_size? | integer | Font size Default 12 |
text_color? | Color | Color of the text Default Color.WHITE |
kerning? | float | Extra spacing between characters Default 0 |
center_x? | boolean | Whether to center the text horizontally on the position Default false |
center_y? | boolean | Whether to center the text vertically on the position Default false |
shadow_color? | Color | Color of the text shadow, transparent to disable it Default Color.TRANSPARENT |
shadow_offset? | Vector2D | Offset of the shadow, in pixels Default Vector2D(1, 1) |
outlined? | boolean | Whether to draw an outline around the text Default false |
outline_color? | Color | Color of the outline Default Color.BLACK |

DrawTextureModerateโ
Draws a Texture on the Canvas
This method can only be called from inside Update event
my_canvas:DrawTexture(texture_path, screen_position, screen_size, coordinate_position, coordinate_size?, render_color?, blend_mode?, rotation?, pivot_point?)
Parameters
| Name | Type | Description |
|---|---|---|
texture_path | Image Path | The image to draw |
screen_position | Vector2D | Position on the Canvas, in pixels |
screen_size | Vector2D | Size on the Canvas, in pixels |
coordinate_position | Vector2D | Top-left UV coordinate of the source to draw (0 to 1) |
coordinate_size? | Vector2D | UV size of the source to draw (0 to 1), use (1, 1) for the whole source Default Vector2D(1, 1) |
render_color? | Color | Color to tint the drawing with Default Color.WHITE |
blend_mode? | BlendMode | AlphaBlend is recommended for textures with transparency. Otherwise you may use Opaque Default BlendMode.AlphaBlend |
rotation? | float | Rotation in degrees Default 0 |
pivot_point? | Vector2D | Pivot of the rotation, relative to the drawing size (0.5, 0.5 is the center) Default Vector2D(0.5, 0.5) |
Layoutfunctionsโ

GetSizeOptimalโ
Gets the Canvas Size
local size = my_canvas:GetSize()
Returns
| Type | Description |
|---|---|
| Vector2D | the current size |

SetAutoResizeOptimalโ
Sets if the canvas should auto resize to screen size
my_canvas:SetAutoResize(auto_resize)
Parameters
| Name | Type | Description |
|---|---|---|
auto_resize | boolean | Whether the canvas should auto resize to screen size |

SetScreenPositionOptimalโ
Sets the Canvas Screen Position offset
my_canvas:SetScreenPosition(screen_position)
Parameters
| Name | Type | Description |
|---|---|---|
screen_position | Vector2D | The new Canvas Screen Position offset |

SetVisibilityOptimalโ
Sets if it's visible on screen
my_canvas:SetVisibility(visible)
Parameters
| Name | Type | Description |
|---|---|---|
visible | boolean | Whether it's visible on screen |
Renderingfunctionsโ

ClearOptimalโ
Clear the Canvas with a specific Color
my_canvas:Clear(clear_color)
Parameters
| Name | Type | Description |
|---|---|---|
clear_color | Color | The color to fill the Canvas with |

SetAutoRepaintRateOptimalโ
Sets the repaint rate
Sets it to -1 to stop auto repainting or 0 to repaint every frame
my_canvas:SetAutoRepaintRate(auto_repaint_rate)
Parameters
| Name | Type | Description |
|---|---|---|
auto_repaint_rate | float | Repaint interval in seconds, 0 to repaint every frame or -1 to stop auto repainting |
๐ Eventsโ
Update | Called when the Canvas needs to be painted You can only call :Draw...() methods from inside this event |
Inherited events
ClassRegister, Destroy, Spawn, ValueChange
Updateโ
Called when the Canvas needs to be painted
You can only call :Draw...() methods from inside this event
Canvas.Subscribe("Update", function(self, width, height)
-- Update was called
end)

