DxAddRenderFunction: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Client function}} __NOTOC__ This function allows you to bind a function to a DxElement's render handler. ==Syntax== <syntaxhighlight lang="lua"> bool dxAddRenderFunction (...")
 
No edit summary
 
Line 20: Line 20:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local screenWidth, screenHeight = guiGetScreenSize()
local screenWidth, screenHeight = guiGetScreenSize()
local window = DxWindow:new(0, 0, 100, 35, "My Window")
local window = DxWindow:new(0, 0, 300, 300, "My Window")


function myRenderFunction()
function myRenderFunction()

Latest revision as of 00:27, 23 March 2020

This function allows you to bind a function to a DxElement's render handler.

Syntax

bool dxAddRenderFunction ( DxElement dxElement, function handlerFunction )

OOP Syntax Help! I don't understand this!

Method: DxElement:addRenderFunction(...)


Required Arguments

  • dxElement: element you wish to bind a render function to
  • handlerFunction: the handler function you wish to bind

Returns

Returns true if the function was bound successfully, false otherwise.

Example

This example sets a DxWindow to a random position every time it is hovered over, using a render function.

local screenWidth, screenHeight = guiGetScreenSize()
local window = DxWindow:new(0, 0, 300, 300, "My Window")

function myRenderFunction()
    if(isMouseOverDxElement(window)) then
        dxSetPosition(window, math.random(screenWidth), math.random(screenHeight))
    end
end

dxAddRenderFunction(window, myRenderFunction)


Note: inside a bound render function, you can also use the predefined variable "self" (instead of "window", in this instance).

See Also