-
Notifications
You must be signed in to change notification settings - Fork 14
Rect
Kiminaze edited this page Jun 9, 2021
·
2 revisions
All items in the ContextMenu use this Rect to display their background and four Rects are used to display the Border.
For the menu itself you normally never need to create this manually (unlike e.g. a new Color).
You can however use this class to draw additional Rects on the screen (e.g. for custom HUD elements).
To create a new Rect you can use the Rect(position, size) function. This will result in a new Rect being created.
local myRect = Rect(vector2(0.5, 0.5), vector2(0.02, 0.02))
-- it does not need any values initially
local myRect = Rect()Rect provides 4 distinct variables.
local myRect = Rect(vector2(0.5, 0.5), vector2(0.02, 0,02))
-- change the position on the screen
-- vector2(0.0, 0.0) is left top corner
-- vector2(1.0, 1.0) is right bottom corner
myRect.position = vector2(0.5, 0.5)
-- change the size of the Rect
myRect.size = vector2(0.1, 0.1)Drawing a Rect must be done every frame and can be achieved using the Draw(color) function of the Rect. Example:
Citizen.CreateThread(function()
local myRect = Rect(vector2(0.5, 0.5), vector2(0.02, 0.02))
while (true) do
Citizen.Wait(0)
myRect:Draw(Colors.Red)
end
end)