Hayakii Posted January 3, 2015 Share Posted January 3, 2015 --------------------------------------------------------------------------------------------------------------------------------------------- Hi everyone! Im working on a login panel since 1 day and i couldn't find how to do this: I've made an image with dxDrawImage and i want when i place my cursor over the image, it is replace by another one. Not over => Image 1 Over it => Image 2 And also that you can click on it. I've tried many things without success. I need you help guys, thank you! -Hayakii- --------------------------------------------------------------------------------------------------------------------------------------------- Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 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 ) Link to comment
Hayakii Posted January 3, 2015 Author Share Posted January 3, 2015 Its working perfectly great! But my button are a little bit rotating. Do you know why ? Thanks for the help man! Link to comment
Hayakii Posted January 3, 2015 Author Share Posted January 3, 2015 Its fine, i've just delete "tocolor ( 255, 255, 255 )" and my button are not rotating anymore. Finally it work! Thanks a lot! Now i need to make them clickable, im gonna work on it. Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 You can use the same function, and combine it with the event onClientClick. Link to comment
Hayakii Posted January 3, 2015 Author Share Posted January 3, 2015 Oh ok, Alright, cool! Link to comment
Hayakii Posted January 3, 2015 Author Share Posted January 3, 2015 I need to open an other DxDrawRectangle, when i click on the button. I've made the click function but i dont know how to open (or make it visible) the DxRectangle. Link to comment
Castillo Posted January 3, 2015 Share Posted January 3, 2015 You mean to show/hide it? you can define a variable with the interface state, and update it when you need to show it. Link to comment
Hayakii Posted January 4, 2015 Author Share Posted January 4, 2015 Yea, i already find how to do it before you told me. Thanks anyway. But i have a probleme (yes, another...) with a function. I want the players, when they click a little cross i've made, all the page on the menu panel is close. Its working, but we can still click on it even though the pages are close. We can still ear the sound (click.mp3). So, i imagine that i cant remove the EventHandler onClickCross in the OnClickCross function . Let me paste my code below: function onClickCross(button,state) if button=="left" and state=="down" then local imgX, imgY, imgWidth, imgHeight = (810/1024)*sx, (200/768)*sy , (20/1024)*sx, (20/768)*sy --- Button Location on the screen if isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) then playSound("click.mp3") --- The click sound when you click on the button --- Close all the pages removeEventHandler("onClientRender",getRootElement(),playPanel) removeEventHandler("onClientRender",getRootElement(),registerPanel) removeEventHandler("onClientRender",getRootElement(),updatesPanel) --- Close the onClickCross function (this function) removeEventHandler("onClientRender",getRootElement(),onClickCross) end else return false end end That would be awesome if you can help me with that! Because im learning lua at the same time (Sorry for my bad english by the way, french are not good at english you should know that ^^) Link to comment
Dealman Posted January 4, 2015 Share Posted January 4, 2015 That's because it will always be true so long as your cursor is within the position you defined. if isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) then playSound("click.mp3") One way to remedy this would be to use a variable, for example; local shouldPlaySound = true function onClickCross(button,state) if button=="left" and state=="down" then local imgX, imgY, imgWidth, imgHeight = (810/1024)*sx, (200/768)*sy , (20/1024)*sx, (20/768)*sy --- Button Location on the screen if isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) then if(shouldPlaySound == true) then playSound("click.mp3") --- The click sound when you click on the button end --- Close all the pages removeEventHandler("onClientRender",getRootElement(),playPanel) removeEventHandler("onClientRender",getRootElement(),registerPanel) removeEventHandler("onClientRender",getRootElement(),updatesPanel) --- Close the onClickCross function (this function) removeEventHandler("onClientRender",getRootElement(),onClickCross) end else return false end end And then just change this variable between true and false depending on whether the interface is showing or not. Link to comment
Hayakii Posted January 4, 2015 Author Share Posted January 4, 2015 I've done it this way, its working. Thanks man, I appreciate you help! local shouldPlaySound = false function onClickCross(button,state) if button=="left" and state=="down" then local imgX, imgY, imgWidth, imgHeight = (810/1024)*sx, (200/768)*sy , (20/1024)*sx, (20/768)*sy if isMouseInPosition ( imgX, imgY, imgWidth, imgHeight ) then if (shouldPlaySound == true) then playSound("click.mp3") removeEventHandler("onClientRender",getRootElement(),registerPanel) removeEventHandler("onClientRender",getRootElement(),updatesPanel) removeEventHandler("onClientRender",getRootElement(),playPanel) removeEventHandler("onClientRender",getRootElement(),onClickCross) end shouldPlaySound = false end else return false end end 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