Astrath:createImage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
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, and custom styles. 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.


'''Syntax:'''
parent (element) – Parent DX element to attach this image to (optional).
<pre>
local image = DxImage:new(path, posX, posY, width, height, parent, relative)
</pre>


'''Parameters:'''
relative (boolean) – Position relative to parent (optional).
<pre>
path      - string - Path to the image file (must exist)
posX      - float  - X position on screen
posY      - float  - Y position on screen
width    - float  - Width of the image
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
 
image:setVisible(boolean) - Sets the visibility
! Method !! Description
image:setEnabled(boolean) - Enables or disables the element
Ath:destroy()
image:setAlpha(int)       - Sets transparency (0–255)
-
image:setPath(string)     - Changes the image file path (must exist)
Ath:setVisible(boolean)
image:draw()               - Draws the image using its defined style
-
</pre>
Ath:setEnabled(boolean)
-
Ath:setAlpha(int)
-
Ath:setPath(string)
-
Ath:draw()
}


'''Example:'''
'''Example:'''
<pre>
<syntaxhighlight lang="lua">
local img = DxImage:new("images/logo.png", 100, 100, 200, 150)
-- Create an image at position 100x100 with size 200x150
img:setAlpha(200)
local myImage = DxImage:new("images/logo.png", 100, 100, 200, 150)
img:setVisible(true)
 
img:setPath("images/new_logo.png")
-- Show the image and set transparency
img:draw()
myImage:setVisible(true)
</pre>
myImage:setAlpha(200)
 
-- Change the image path
myImage:setPath("images/new_logo.png")
 
-- Draw the image
myImage:draw()
</syntaxhighlight>
 
'''See also:'''
 
[[Astrath]] – Main library page
 
[[DxWindow:new]] – Page for window element reference
 
[[DxLabel:new]] – Page for label element reference


'''See Also:'''
[[onClientRender]] – Event used to render DX elements
DxWindow:new, DxLabel:new, DxButton:new

Revision as of 20:03, 22 October 2025

DxImage:new

Template:FuncDef

Description: Creates a new DX-based image element. Images can be attached to parent elements, support transparency, and custom styles. 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() - Ath:setVisible(boolean) - Ath:setEnabled(boolean) - Ath:setAlpha(int) - Ath:setPath(string) - Ath:draw() }

Example:

-- Create an image at position 100x100 with size 200x150
local myImage = DxImage:new("images/logo.png", 100, 100, 200, 150)

-- Show the image and set transparency
myImage:setVisible(true)
myImage:setAlpha(200)

-- Change the image path
myImage:setPath("images/new_logo.png")

-- Draw the image
myImage:draw()

See also:

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