John Smith Posted August 14, 2014 Share Posted August 14, 2014 hi im having this code(its not full code but i'm posting everything regarding this button) menuButton = guiCreateButton( 873, 720, 150, 40, "Exit to Menu", false ) function drawRooms() guiSetAlpha(menuButton,0) end addEventHandler( "onClientMouseEnter", getRootElement(), function () if source == menuButton then -- also tried replacing this with 'guielement' dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') end end ) addEventHandler( "onClientMouseLeave", getRootElement(), function () if source == menuButton then dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu.png') end end ) no debug errors Link to comment
Bonsai Posted August 14, 2014 Share Posted August 14, 2014 dxDrawImage: "Draws an image on the screen for a single frame. In order for the image to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender)." Link to comment
John Smith Posted August 14, 2014 Author Share Posted August 14, 2014 umm maybe im doing it wrong but it doesnt work function buttonEnter () if source == menuButton then dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') addEventHandler("onClientRender",root,buttonEnter) end end addEventHandler( "onClientMouseEnter", getRootElement(),buttonEnter) function buttonExit () if source == menuButton then removeEventHandler("onClientRender",root,buttonEnter) end end addEventHandler( "onClientMouseLeave", getRootElement(),buttonExit) Link to comment
Bonsai Posted August 14, 2014 Share Posted August 14, 2014 If you wanna make dxButtons I suggest you to get the cursor position and check if its over one button. Using gui buttons to fake that is a kinda dirty solution, at least in my opinion. Anyway, if you wanna stick to this, I would do something like this: - a function that sets some variable whether cursor is on button or not onClientMouseEnter/onClientMouseLeave - a function that handles the drawing depending on that variable Link to comment
John Smith Posted August 14, 2014 Author Share Posted August 14, 2014 i have made outputChatBox debugs and events work fine for exactly my button, but the problem is in setting the new image i am trying to overlap current image because if i remove event handler of original image, everything will be fucked up due to my low scripting skills and not knowing how to avoid onclientrender is already handled error Link to comment
Et-win Posted August 14, 2014 Share Posted August 14, 2014 Make another function and attach it to the 'onClientRender' event. (And place the 'dxDrawImage' code in it) You are now making a event by every frame. Link to comment
John Smith Posted August 14, 2014 Author Share Posted August 14, 2014 Make another function and attach it to the 'onClientRender' event. (And place the 'dxDrawImage' code in it) You are now making a event by every frame. i dont understand what you exactly mean by this Link to comment
Et-win Posted August 14, 2014 Share Posted August 14, 2014 function renderHandler() dxDrawImage(screenWidth/2.20,screenHeight/1.50, 150,40,'images/exitmenu_hover.png') end function buttonEnter () if source == menuButton then addEventHandler("onClientRender",root,renderHandler) end end addEventHandler( "onClientMouseEnter", getRootElement(),buttonEnter) function buttonExit () if source == menuButton then removeEventHandler("onClientRender",root,renderHandler) end end addEventHandler( "onClientMouseLeave", getRootElement(),buttonExit) Link to comment
Bonsai Posted August 14, 2014 Share Posted August 14, 2014 Its two different pictures. Therefore, best way could be using a variable containing the image name and just change it. Link to comment
John Smith Posted August 14, 2014 Author Share Posted August 14, 2014 both methods of yours work - @Et-win, @Bonsai thanks for help, Et-win and Bonsai Link to comment
cheez3d Posted August 15, 2014 Share Posted August 15, 2014 Don't use root, use guiRoot. Link to comment
#DRAGON!FIRE Posted August 15, 2014 Share Posted August 15, 2014 Don't use root, use guiRoot. ( resourceRoot ) better . Link to comment
cheez3d Posted August 15, 2014 Share Posted August 15, 2014 No. Every resourceRoot has it's own guiRoot. Link to comment
#DRAGON!FIRE Posted August 15, 2014 Share Posted August 15, 2014 .. resourceRoot = All Resource Elements ! Link to comment
cheez3d Posted August 15, 2014 Share Posted August 15, 2014 Stop posting if you don't know what you're talking about... Link to comment
cheez3d Posted August 15, 2014 Share Posted August 15, 2014 onClientMouseEnter: This event is fired when the user moves the mouse over a GUI element.onClientMouseLeave: This event is fired when the user moves the mouse away from a GUI element. https://wiki.multitheftauto.com/wiki/Element_tree You could also make it even faster by only ataching the event to the menuButton instead of guiRoot. local RenderHandler = function() dxDrawImage(screenWidth/2.20,screenHeight/1.50,150,40,'images/exitmenu_hover.png'); end; local ButtonEnter = function() addEventHandler("onClientRender",root,RenderHandler); end; addEventHandler("onClientMouseEnter",menuButton,ButtonEnter,false); local ButtonExit = function() removeEventHandler("onClientRender",root,RenderHandler); end; addEventHandler("onClientMouseLeave",menuButton,ButtonExit,false) That 4th false in the addEventHandler will make sure the event will not propagate trough the parent and the children of the button. 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