DxDrawImage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Added example.)
Line 6: Line 6:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool dxDrawImage ( float posX, float posY, float width, float height, string filename, [ float rotation, float rotationCenterOffsetX, float rotationCenterOffsetY, int color, bool postgui ] )
bool dxDrawImage ( float posX, float posY, float width, float height, string filename [, float rotation = 0, float rotationCenterOffsetX = 0, float rotationCenterOffsetY = 0, int color = white, bool postGUI = false ] )
</syntaxhighlight>
</syntaxhighlight>


Line 18: Line 18:
===Optional Arguments===
===Optional Arguments===
*'''rotation:''' the rotation, in degrees for the image.
*'''rotation:''' the rotation, in degrees for the image.
*'''rotationCenterOffsetX:''' the absolute X offset for which to rotate the image from.
*'''rotationCenterOffsetX:''' the absolute X offset from the image center for which to rotate the image from.
*'''rotationCenterOffsetY:''' the absolute Y offset for which to rotate the image from.
*'''rotationCenterOffsetY:''' the absolute Y offset from the image center for which to rotate the image from.
*'''color:''' the color of the text, a value produced by [[tocolor]].
*'''color:''' the color of the text, a value produced by [[tocolor]].
*'''postgui :''' A bool representing whether the image should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
*'''postgui :''' A bool representing whether the image should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
Line 28: Line 28:


==Example==  
==Example==  
<section name="Client" class="client" show="true">
Example of a pendulum swinging from the top of the screen, made using dxDrawImage.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--add an example here
local rootElement = getRootElement()
local screenWidth,screenHeight = guiGetScreenSize()  -- Get screen resolution.
 
 
function renderDisplay ( )
local seconds = getTickCount() / 1000
local angle = math.sin(seconds) * 80
-- This will draw the graphic file 'arrow.png' at the top middle of the screen
-- using the size of 100 pixels wide, and 240 pixels high.
-- The center of rotation is at the top of the image.
dxDrawImage ( screenWidth/2 - 50, 0, 100, 240, 'arrow.png', angle, 0, -120 )
end
 
 
function HandleTheRendering ( )
addEventHandler("onClientRender",rootElement, renderDisplay)  -- Keep everything visible with onClientRender.
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[Category:Needs_Example]]

Revision as of 23:25, 16 January 2009

Draws an image on the screen for a single frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender).

Syntax

bool dxDrawImage ( float posX, float posY, float width, float height, string filename [, float rotation = 0, float rotationCenterOffsetX = 0, float rotationCenterOffsetY = 0, int color = white, bool postGUI = false ] )

Required Arguments

  • posX: the absolute X coordinate of the top left corner of the image
  • posY: the absolute Y coordinate of the top left corner of the image
  • width: the absolute width of the image
  • height: the absolute height of the image
  • filename: the filename and path of the image which is going to be drawn.

Optional Arguments

  • rotation: the rotation, in degrees for the image.
  • rotationCenterOffsetX: the absolute X offset from the image center for which to rotate the image from.
  • rotationCenterOffsetY: the absolute Y offset from the image center for which to rotate the image from.
  • color: the color of the text, a value produced by tocolor.
  • postgui : A bool representing whether the image should be drawn on top of or behind any ingame GUI (rendered by CEGUI).


Returns

Returns true if successful, false otherwise.

Example

Click to collapse [-]
Client

Example of a pendulum swinging from the top of the screen, made using dxDrawImage.

local rootElement = getRootElement()
local screenWidth,screenHeight = guiGetScreenSize()  -- Get screen resolution.


function renderDisplay ( )
	local seconds = getTickCount() / 1000
	local angle = math.sin(seconds) * 80
	-- This will draw the graphic file 'arrow.png' at the top middle of the screen
	-- using the size of 100 pixels wide, and 240 pixels high.
	-- The center of rotation is at the top of the image.
	dxDrawImage ( screenWidth/2 - 50, 0, 100, 240, 'arrow.png', angle, 0, -120 )
end


function HandleTheRendering ( )
addEventHandler("onClientRender",rootElement, renderDisplay)  -- Keep everything visible with onClientRender.
end
addEventHandler("onClientResourceStart",rootElement, HandleTheRendering)

See Also