DxAddRenderFunction

From Multi Theft Auto: Wiki
Revision as of 00:26, 23 March 2020 by LopSided (talk | contribs) (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 (...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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, 100, 35, "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