🖼️ Canvas
Canvas is an entity which you can draw onto it.
💂Authority
This class can only be spawned on 🟧 Client side.
🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
🎒 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 material into a Prop
any_prop:SetMaterialFromCanvas(my_canvas)
tip
You can use the output Texture from a Canvas with :SetMaterialFromCanvas() method!
🛠 Constructors
Default Constructor
local my_canvas = Canvas(is_visible?, clear_color?, auto_repaint_rate?, should_clear_before_update?, auto_resize?, width?, height?, screen_position?)
Type | Name | Default | Description |
---|---|---|---|
boolean | is_visible | true | Whether to draw it on screen |
Color | clear_color | Color.TRANSPARENT | Color to clear with (background color) |
float | auto_repaint_rate | -1 | Rate to auto repaint (call Update event), pass 0 for every frame, -1 to disable |
boolean | should_clear_before_update | true | Whether to clear with Clear Color before updates |
boolean | auto_resize | true | Auto resize with screen's size |
integer | width | 0 | If not using auto_resize |
integer | height | 0 | If not using auto_resize |
Vector2D | screen_position | Vector2D(0, 0) | If not using auto_resize, offset when drawing to screen |