DxCreateTexture: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (moved CreateTexture to DxCreateTexture: Function renamed)
No edit summary
Line 7: Line 7:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element createTexture ( string filepath )
element dxCreateTexture ( string filepath )
</syntaxhighlight>  
</syntaxhighlight>  


Line 30: Line 30:
     function()
     function()
         if not myImage then
         if not myImage then
             myImage = createTexture( "moonpig.png" )  -- Create texture
             myImage = dxCreateTexture( "moonpig.png" )  -- Create texture
         else         
         else         
             destroyElement( myImage )                -- Destroy texture
             destroyElement( myImage )                -- Destroy texture

Revision as of 11:53, 13 June 2011

Only available in 1.1 This function creates a texture element that can be used in the dxDraw functions

Syntax

element dxCreateTexture ( string filepath )

Required Arguments

  • filepath: The filepath of the image. (.dds images are also supported). Image files should ideally have dimensions that are a power of two, to prevent possible blurring.

Returns

Returns a texture element if successful, false if invalid arguments were passed to the function.

Example

addEventHandler( "onClientRender", root,
    function()
        if myImage then
            dxDrawImage( 100, 350, 300, 350, myImage  )
        end
    end
)

-- Use 'toggle' command to switch image on and off
addCommandHandler( "toggle",
    function()
        if not myImage then
            myImage = dxCreateTexture( "moonpig.png" )  -- Create texture
        else        
            destroyElement( myImage )                 -- Destroy texture
            myImage = nil
        end
    end
)

See Also