You must compare the cursor position to the image draw position and size.
You can use this function to avoid all the math calculations:
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 )
if ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) then
return true
else
return false
end
end
Example:
addEventHandler ( "onClientRender", root,
function ( )
local imgX, imgY, imgWidth, imgHeight = 50, 50, 200, 200
dxDrawImage ( imgX, imgY, imgWidth, imgHeight, ( isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) and "myImage2.png" or "myImage.png" ), tocolor ( 255, 255, 255 ) )
end
)