Jump to content

click to the dxImage


w3rt1x

Recommended Posts

Hello y'all! I need help.  I wanna do this, when I click to the dxImage "phone.png" this image will be destroyed and the "phone_main.png" will draw. How can I do this? I tried to do "creatingMain" function to draw and destroy, however it ain't working. Thank you! Maybe it's the stupid question, but im just noob :)

 

local isImage = false

addEventHandler("onClientRender", root,
    function()
       if(isImage) then
        block = dxDrawImage(969, 618, 220, 423, "phone.png", 0, 0, 0, tocolor(255, 255, 255, 255), true) -- draw image if isImage true
            function creatingMain()
                dxDrawImage(969, 618, 220, 423, "phone_main.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
                destroyElement(block)
            end
            addEventHandler ( "onClientClick", root, creatingMain)
        -- dxDrawImage(969, 618, 220, 423, "phone_main.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
        showCursor(true)
       end
    end
)

bindKey("i", "down",
    function()
       if(isImage) then
          isImage = false
          showCursor(false)
       else
             isImage = true
       end
    end
)
Link to comment

There are many ways to do it, I will leave you a small simple example.

local path       = "phone.png"
local x, y, w, h = 969, 618, 220, 423
local isDraw     = true 
showCursor(true)


function drawImage()
    dxDrawImage(x, y, w, h, path, 0, 0, 0, tocolor(255, 255, 255, 255), true) -- draw image if isImage true
end 
addEventHandler("onClientRender", root, drawImage)

addEventHandler("onClientClick", root
   function()
      if isMouseInPosition ( x, y, w, h ) then 
         path = "phone_main.png"
      end 
   end
)

bindKey("i", "down",
    function()
       if isDraw then 
          isDraw = false 
          showCursor(false)
          removeEventHandler("onClientRender", root, drawImage)
       end 
    end
)

function isMouseInPosition ( x, y, width, height )
   if ( not isCursorShowing( ) ) then
	  return false
   end
   local sx, sy = guiGetScreenSize ( )
   local cx, cy = getCursorPosition ( )
   local cx, cy = ( cx * sx ), ( cy * sy )
   return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) )
end

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...