![]() |
|
[Open Layer] Creating a GUI |
Balinor
Member #8,278
January 2007
|
I'm working with Open Layer on an RPG. So, I want to integrate a GUI into my game but I don't exactly know how to do that. Are there libraries that I could use or do I have to code everything by myself? Is it possible to use the GUI functions of Allegro? |
Vanneto
Member #8,643
May 2007
|
I was thinking the exact same thing. I want to create a simple GUI for a game im making. Just a basic menu, start button, maybe some options and a quit button. But I dont know how to do it! So im hoping someone will reply to this thread! In capitalist America bank robs you. |
Paul Rowan
Member #8,612
May 2007
![]() |
I've had the same problem, but I solved it by using something similar to collision detection in a game. If you want any type of button, you will know the size of it say 64 wide x 32 deep. You also know where you're going to display it on the screen say 100,100. You can track where the x and y is of the mouse pointer on screen (you have to install the mouse first) and you can also check for the mouse button being clicked. So using the numbers above, the top left co-ords of the button on the screen are 100,100 and the bottom right co-ords of the button on screen are 163,131 (screen x: 100 + button width 64 - 1 [cos the button starts at 100 not 101] , screen y: 100 + button height 32 - 1 [for same reason]). So if the mouse buttom is clicked and mouse x>=100 and mouse x<=163 and mouse y>=100 and mouse y<=131 then the button on screen has been clicked and you can use that info to do what you want. If you want more than one button on screen at once, just keep a track of what the button co-ords are to initiate the correct function. If you want a full code example let me know |
Vanneto
Member #8,643
May 2007
|
A code example would be nice. Anyway sounds pretty simple. Now... But when youre thinking how to do its a diffrent story! Ill try this! Thanks! In capitalist America bank robs you. |
tobing
Member #5,213
November 2004
![]() |
I'm using guichan as a UI library together with OpenLayer, works fine, if you manage to setup all libraries you need. That means allegro, allegrogl, lpng (optional) and lzip (used only for lpng). |
Paul Rowan
Member #8,612
May 2007
![]() |
Hi, as promised here is my full code listing for my GUI. It's very basic and there may be other ways to do it better, but it worked for me
Let me know if this helps or I'd be interested if you find an easier/better way cos I'm quite new to all this and still learning |
Balinor
Member #8,278
January 2007
|
Thanks for your answers. Thanks for your code, Paul Rowan. That's the way I had done it before as I wrote a game with another library than Open Layer / Allegro. I think I will do it like that. |
Vanneto
Member #8,643
May 2007
|
Here is a class I made for the purpouse. Makes the process easier
In capitalist America bank robs you. |
spellcaster
Member #1,493
September 2001
![]() |
@Vanneto: Besides working like the user expects it, it also solves the problem that the click might be registered on the next page as well, if the page changes before the button was released. -- |
Vanneto
Member #8,643
May 2007
|
And how do I know if it was released? I will change the class appropriately. Thanks! In capitalist America bank robs you. |
spellcaster
Member #1,493
September 2001
![]() |
Well, that's the point where it gets more complicated.
If you want even more flexibility, you could add the concept of a grabbed item, receiving all related events until it declares itself as no longer interested. This way your button can grab the events as soon as the mouse button goes down inside his boundaries. It should release the grab as soon as the mouse button is no longer pressed. The code above was written on the fly and will probably contain errors. I hope the example will be good enough to visualize the idea, though. -- |
|