aka Blue Posted July 24, 2017 Share Posted July 24, 2017 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
Rose Posted July 24, 2017 Share Posted July 24, 2017 (edited) 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 July 24, 2017 by Rose Link to comment
#Dv^ Posted July 24, 2017 Share Posted July 24, 2017 (edited) 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 July 24, 2017 by #Dv^ Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now