Astrath:createImage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== DxImage:new ==
= DxImage:new =
 
{{Client function}}
{{FuncDef|element DxImage:new ( string path, float posX, float posY, float width, float height, element parent, boolean relative )}}
 
'''Description:'''
'''Description:'''
Creates a new DxImage element, which displays a static image on the screen. Uses table-based syntax with metatable.
Creates a new DX-based image element. Images can be attached to parent elements, support transparency, custom styles, and optional parent-relative positioning. Each image instance is automatically registered in the DX library.
 
'''Syntax:'''
<pre>
local image = DxImage:new(path, posX, posY, width, height, parent, relative)
</pre>


'''Parameters:'''
'''Parameters:'''
<pre>
* path (string) – Path to the image file. Must exist.
path     - string - Path to the image file (must exist)
* posX, posY (float) – Position on screen.
posX     - float  - X position on screen
* width, height (float) – Size of the image.
posY     - float - Y position on screen
* parent (element) Parent DX element to attach this image to (optional).
width     - float  - Width of the image
* relative (boolean) – Position relative to parent (optional).
height   - float - Height of the image
parent   - element (optional) - Parent DX element
relative - boolean (optional) - Whether position is relative to parent
</pre>


'''Return Value:'''
'''Returns:'''
<pre>
: Returns the newly created DxImage element.
element - table - The newly created DxImage element
</pre>


'''Methods:'''
'''Methods:'''
<pre>
{| class="wikitable" style="width:100%; border:none;"
image:destroy()           - Destroys the element and all its children
! Method !! Description
image:setVisible(boolean) - Sets the visibility
|-
image:setEnabled(boolean) - Enables or disables the element
| Ath:destroy() || Destroys the image element and all its child elements.
image:setAlpha(int)       - Sets transparency (0–255)
|-
image:setPath(string)      - Changes the image file path (must exist)
| Ath:setVisible(boolean) || Shows or hides the image.
image:draw()              - Draws the image using its defined style
|-
</pre>
| Ath:setEnabled(boolean) || Enables or disables the image for interaction.
|-
| Ath:setAlpha(number) || Sets the image transparency (0–255).
|}


'''Example:'''
'''Example:'''
<pre>
<syntaxhighlight lang="lua">
local img = DxImage:new("images/logo.png", 100, 100, 200, 150)
local myImage = DxImage:new("images/logo.png", 100, 100, 200, 150)
img:setAlpha(200)
 
img:setVisible(true)
myImage:setVisible(true)
img:setPath("images/new_logo.png")
myImage:setAlpha(200)
img:draw()
myImage:setPath("images/new_logo.png")
</pre>
myImage:draw()
</syntaxhighlight>


'''See Also:'''
'''See also:'''
DxWindow:new, DxLabel:new, DxButton:new
* [[Astrath]] – Main library page
* [[DxWindow:new]] – Page for window element reference
* [[DxLabel:new]] – Page for label element reference
* [[onClientRender]] – Event used to render DX elements

Latest revision as of 20:10, 22 October 2025

DxImage:new

Template:FuncDef

Description: Creates a new DX-based image element. Images can be attached to parent elements, support transparency, custom styles, and optional parent-relative positioning. Each image instance is automatically registered in the DX library.

Parameters:

  • path (string) – Path to the image file. Must exist.
  • posX, posY (float) – Position on screen.
  • width, height (float) – Size of the image.
  • parent (element) – Parent DX element to attach this image to (optional).
  • relative (boolean) – Position relative to parent (optional).

Returns:

Returns the newly created DxImage element.

Methods:

Method Description
Ath:destroy() Destroys the image element and all its child elements.
Ath:setVisible(boolean) Shows or hides the image.
Ath:setEnabled(boolean) Enables or disables the image for interaction.
Ath:setAlpha(number) Sets the image transparency (0–255).

Example:

local myImage = DxImage:new("images/logo.png", 100, 100, 200, 150)

myImage:setVisible(true)
myImage:setAlpha(200)
myImage:setPath("images/new_logo.png")
myImage:draw()

See also: