DxAddRenderFunction

From Multi Theft Auto: Wiki
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, 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