Mordred Posted February 14, 2014 Share Posted February 14, 2014 Hello fellow Leadwerkers, it's been a few days since i asked my last question, but i have a new one now . I'm tring to setup a basic 2d HUD with menues and such ("Play", "Exit", "Character", "Stats" etc.). That stuff is basically up and running, you can hover over buttons, click buttons, the visible buttons do change as intended and such, but i have 2 problems i might need help / suggestions. 1. Sometimes i have to click several times before the engine actually accepts my input, that just does not feel really native as i expect to click one time on a button and see the result in "an instant" 2. If i show the mouse graphics when opening the menue, it takes roughly 3 seconds befor it's actually shown. The same if i disable the mouse cursor it's still shown for about 3 seconds before it's gone. I believe that the problems might come due to the fact that i use several if statements within the postrender to check the currenct mousepos and, if clicked, to switch different variables to save internally if a button is clicked and if yes, which one it was, to show the coressponding menues. Where should i do those checks instead of the PostRenderer? Or how am i able to increase the reaction time of the events? The code is quite basic, and it uses several if statements and for loops to draw buttons / check the position, so i think there's potential to make the development better too, so in case you have any suggestions / hints for me you're mostly welcome. I think the code is important to check to answer my question, so i did paste it at pastebin, and here's the link. http://pastebin.com/Xw0G4LPt Thanks for your replys in advance! [Edit] Here's a small video showing the problems. As you can see at the beginning the "Start" button top left is flickering several times, there i try to move the cursor on it, but i cannot see it. It "pops" up later. And you might see the cursor itself flickering several times when i try to click a button but the engine doesn't respont within the expected time. Quote Link to comment Share on other sites More sharing options...
Rick Posted February 14, 2014 Share Posted February 14, 2014 Are you using MouseHit()? XXHit() functions only fire once a frame so if you have other Hit()'s in other scripts for the same keys/mouse they won't register on that same frame. The first one to get called wins (at least I remember this being the case) Be sure you are using MouseDown() with booleans to keep track in each script to avoid this issue. if MouseDown(1) == true and leftMouseDown == false then -- do mouse down stuff here leftMouseDown = true elseif MouseDown(1) == false and leftMouseDown == true then -- do mouse up/click stuff here leftMouseDown = false end I'm at work and it won't let me get to your link to your code so just wanted to point that out that I remember having issues with this on later versions of LE so I'm guessing 3.1 is the same. Quote Link to comment Share on other sites More sharing options...
Mordred Posted February 14, 2014 Author Share Posted February 14, 2014 Hey Rick, thanks a lot for that reply, i was already quite sure that there's something like that (well, not really that, but that i did smth. in the wrong place) leading to my issues. Your example sound's really reasonable and i think that might help. I'll give it a try later (maybe tomorrow). And to answer your question: Yes, i do use "MouseHit", since i didn't want to test if someone is keeping the button pressed but just if it was "hit", that seemed at that time to be quite reasonable for what i tried to achieve. Again my thanks for pointing that out, i appreaciate your help as usual! Quote Link to comment Share on other sites More sharing options...
Rick Posted February 14, 2014 Share Posted February 14, 2014 np, I hope it's that easy . This gives you the added benefit of capturing the mouse down event so you can switch your button states to show that as well. so you got that going for you now I always like buttons that allow me to press down but then move off if I change my mind at the last minute. Quote Link to comment Share on other sites More sharing options...
Mordred Posted February 15, 2014 Author Share Posted February 15, 2014 mhmm I'm still struggling with that. I did think about the suggestion you made Rick, and i came to the conclusion that it should work somehow different. The problem is, if i do it the way you showed me i would have another variable that i need to fill and i already use like 10 or 15 for those menu buttons. I think that's too much. I believe the problem is, that i run the code within the "PostRender" function and the more buttons i click (and thus menus i open) the lower the FPS goes and thus the longer the engine needs to check if there has been clicked on a specific place. But as soon as i try to switch the "MouseHit" Events into App:Loop function i only get a white screen followed by a crash (no errormessage). So my idea, to make a own function for "ButtonClick" doesn't work too. Now i added the function "ButtonClick" into the PostRender and removed the corresponding code from my "Menu" function and it works a bit better, but i still have the issue that several clicks are not accepted. As said, the more menues i open, the more often i do get that problem. Here's a newer version of the code at pastebin http://pastebin.com/KXcQRmNW Any other suggestions to prevent that problem is mostly welcome. So, again it basically works, but it does not feel "native" Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 15, 2014 Share Posted February 15, 2014 If it is some character special panel , imagine you display character on right and menus on left. Why not using 3D Menus ? Or simple 3D Boxes you can click detect using Pick function ? Change their size/Color when picked for example. Should not be as problematic as what you try to do with PotsRender() function. Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Rick Posted February 15, 2014 Share Posted February 15, 2014 PostRender should only be used for drawing. UpdateWorld() is where you should be checking for mouse stuff. Also, you will have lots of variables with this stuff. You are starting to see why organization becomes important and why you now need to start breaking your controls into their own class that handles these things. Quote Link to comment Share on other sites More sharing options...
Mordred Posted February 15, 2014 Author Share Posted February 15, 2014 If it is some character special panel , imagine you display character on right and menus on left.Why not using 3D Menus ? Or simple 3D Boxes you can click detect using Pick function ? Change their size/Color when picked for example. Because i do not see any reason why i should make a simple menue in 3d, it seems to be harder to achieve as a simple 2d menue and the functionality would be the same. It's just the "lag" problem, but i gonna try to move the stuff into App:UpdateWorld() today, look if it works better If not i can still give it a try to make it 3d. Even though i have no idea how to "show" / "hide" a menue made with 3d stuff O_o The menue itself shall not only show the character panel, but depending on the clicks the inventory and such later too, so a simple "left this, right this" might be too much, especially since i haven't all skills and such in that code, it's just an example for myself to see how it works. Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 15, 2014 Share Posted February 15, 2014 3D cubes with text. You can show them or hide using Show(), Hide() And detect mouse click collision using Pick() function, in fact where you pass your 2D cursor, when you click, you detect if your Raycast hits a box and see what box is picked by it's name of entity or it's type you would have defined before. You can also delete or create 3D Boxes so not a big deal. But perhaps more appropriate for general menu. And i would be curious to see the frame rate using pure 3D menus, should be lot better i think Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Mordred Posted February 15, 2014 Author Share Posted February 15, 2014 Hey YouGroove, thanks for your hint, even though i might not get into that, i do appreciate you taking the time to explain it. The Problem using 3d menues is: I think it works as an initial menu, like "Game start", "Load", "Settings" and such, everything where you do not have to move. But in my case i want to open / close the menue whenever i want to, and i think it's more hardwarehungry (and harder to achieve) to have "hidden" 3d objects moving arround with the player as a simple 2d drawn menue. I'd say that just feels like shooting with a cannon on birds Quote Link to comment Share on other sites More sharing options...
YouGroove Posted February 15, 2014 Share Posted February 15, 2014 Indeed If you had some second viewport creation possible , you could do it with the 3D Way , as you would display inventory on the 2nd viewport without worrying what is going on on primary viewport displaying your game. Well let's wait for some solid GUI system for LE3 ... some day .. perhaps .... Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.