GuiMoveElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Replaced content with "TESTING")
Line 1: Line 1:
{{Useful Function}}
TESTING
<lowercasetitle/>
__NOTOC__
This function draws a number of 2D lines in order to achieve a circle shape on the screen - rendered for '''one''' frame.  This should be used in conjunction with [[onClientRender]] in order to display continuously.
 
==Syntax==
<syntaxhighlight lang="lua">bool dxDrawCircle ( int posX, int posY [, int radius = 50, int, width = 5, int angleAmount = 1, int startAngle = 0, int stopAngle = 360, int color = white, bool postGUI = false ] )</syntaxhighlight>
 
===Required Arguments===
[[Image:DxDrawCircle_example.png|thumb|An example of how dxDrawCircle function works in practice.]]
* '''posX''': An integer representing the '''absolute''' X position of the circle center, represented by pixels on the screen.
* '''posY''': An integer representing the '''absolute''' Y position of the circle center, represented by pixels on the screen.
 
===Optional Arguments===
{{OptionalArg}}
* '''radius''': An integer representing the radius scale of the circle that is being drawn.
* '''width''': An integer representing the width of the line that is being drawn.
* '''angleAmount''': An integer representing the tightness of the circle. Lower amount makes it smoother, higher amount makes it more of a clock looking circle.
* '''startAngle''': An integer representing the angle of the first point of the circle.
* '''stopAngle''': An integer representing the angle of the last point of the circle.
* '''color''': An integer of the hex color, produced using [[tocolor]] or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue).
* '''postGUI''': A bool representing whether the line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
 
==Code==
 
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
function guiMoveElement ( element, speed, x, y, type_ )
local type_ = type_ or "Linear"
if isElement ( element ) and tonumber ( speed ) and tonumber ( x ) and tonumber ( y ) and tostring ( type_ ) then
if isElement ( getElementData ( element, "object" ) ) then
local object = getElementData ( element, "object" )
moveObject ( object, speed, x, y, -999, 0, 0, 0, type_ )
local destroy = function ( old_object, old_gui )
if isElement ( old_object ) then
destroyElement ( old_object )
end
for i, gui_elements in ipairs ( table_ ) do
if gui_elements[1] == old_gui then
table.remove ( table_, i )
end
end
end
setTimer ( destroy, speed, 1, object, gui_element )
else
local p = { guiGetPosition ( element, false ) }
local object = createObject ( 902, p[1], p[2], -999 )
setElementData ( element, "object", object )
setElementAlpha ( object, 0 )
table.insert ( table_, (#table_)+1, { element, object } )
guiMoveElement ( element, speed, x, y, type_ )
end
end
end
function r ()
for i, gui_element in ipairs ( table_ ) do
if isElement (gui_element[1]) and isElement (gui_element[2]) then
local x, y = getElementPosition ( gui_element[2] )
guiSetPosition ( gui_element[1], x, y, false )
end
end
end
addEventHandler ( "onClientRender", root, r )
</syntaxhighlight>
</section>
 
<br />'''Author:''' killerProject<br />
 
==Examples==
 
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
local screenW, screenH = guiGetScreenSize()
local myWindow = guiCreateWindow ( -500, ( screenH - 500 ) /2, 500, 500, "killerProject", false )
guiMoveElement ( myWindow, 5000, ( screenW - 500 ) / 2, ( screenH - 500 ) /2, "OutElastic" )
</syntaxhighlight>
</section>
 
==See Also==
{{Useful_Functions}}

Revision as of 22:30, 21 May 2018

TESTING