Skip to content
Kiminaze edited this page Jun 9, 2021 · 2 revisions

Working with Rect in the ContextMenu

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).

Creating a new Rect

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 variables

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 the Rect on the screen

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)

Clone this wiki locally