Jump to content

DX pegado al ratón


aka Blue

Recommended Posts

Me gustaría crear un rectángulo que vaya siguiendo al ratón. He hecho esto pero no funciona correctamente.

local sx, sy = guiGetScreenSize( )
local sourceX, sourceY = 1336, 768

function x(var) return sx*( var/sourceX ) end
function y(var) return sy*( var/sourceY ) end

bindKey( "m", "down",
	function( )
		if isCursorShowing( ) then
			showCursor( false )
		else
			showCursor( true )
		end
	end
)

addEventHandler( "onClientRender", root,
	function( )
		if isCursorShowing( ) then
			local cx, cy, worldx, worldy, worldz = getCursorPosition()
			dxDrawRectangle( x(cx), y(cy), x(150), y(200), tocolor(255, 150, 0, 150) )
		end
	end
)

Gracis de antemano.

Link to comment

Un ejemplo: 

local x, y = nil 

addEventHandler( "onClientCursorMove", getRootElement( ),
    function ( _, _, xpos, ypos )
        x = xpos 
        y = ypos
    end
)

addEventHandler("onClientRender", root, 
	function( ... )
		if isCursorShowing() == true then
			dxDrawRectangle( x, y, 100, 25 )
		end
	end)

No sé cómo quieres que se mueva pero ahí se debería de mover según donde esté la flechita.

Y creo que showCursor( not isCursorShowing() ) es más rápido que comprobar si isCursorShowing es verdadero o falso.

Edited by Rose
Link to comment
local sx, sy = guiGetScreenSize( )

bindKey( "m", "down",
	function( )
		if isCursorShowing( ) then
			showCursor( false )
		else
			showCursor( true )
		end
	end
)

addEventHandler( "onClientRender", root,
	function( )
		if isCursorShowing( ) then
			local cx, cy, worldx, worldy, worldz = getCursorPosition()
			dxDrawRectangle( cx*sx, cy*sy, 150, 200, tocolor(255, 150, 0, 150) )
		end
	end
)

 

Edited by #Dv^
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...