Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th Nov 2010 15:55 Edited at: 19th Nov 2010 11:03
This thread will be a sort of learning tool for those wanting to make a half decent menu for their game. I will post all my processes (and alternatives) and we can discuss menus and stuff.

What I'm Making:
I will be making a menu similar to Gothic 4 to show you a 2D UI System. [Beginner - Intermediate]
And a menu based off Halo Reach to show you a 3D UI System. [Advanced]

Stuff Were Looking At:
2D/3D UI Systems and Structure
UI Gadgets
Linked Lists
Forward/Up/Right Vectors (needed for 3d Stuff)
Bitmap Font (last thing)

Examples Of The Menus:
Halo Reach


Gothic 4


The reason I'm reacting one rather than creating an original, is you can analyse what's gone into the menu and experiment with trying to reproduce the same effect. I find you end up learning more about things that way.

-Will chuck all my working here when the menu is nearing completion-

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Nov 2010 16:50 Edited at: 18th Nov 2010 16:51
Looking forward to it.

Your image for GTA is not linkable...

I particularly like the Halo menu, I'll be having a go at something similar in my next game for sure.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Nov 2010 21:21
Quote: "So firstly, what menu from any game shall I recreate?"

If you are talking about the specific menus we can see, then Gothic 4 - it has a bit of everything.

Come to think about it, even if you mean the whole menu system, then Gothic 4 would be a good one.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 18th Nov 2010 23:49 Edited at: 19th Nov 2010 14:29
Yeah, I agree, the Gothic 4 Menu system is very complete and easy to make as well. What I'm going to do is a 2D UI based on Gothic 4 and a 3D UI based on Halo Reach.

I've just started on the Halo Reach one.

Here's a video of what I'm trying to replicate, skip ahead a bit:



This is a shot of what the background part of the root menu looks like from the side. This is created via a 3D UI Layer system. The Layers work by giving them a resolution and world space width/height, say a resolution of 1920x1080 and are layer plain say 5x3, so a 5x3 plain has a resolution of 1920x1080. Then anything that's attached to the layer is automatically sized in pixels based off the resolution and width/height of the layer plain. It works just like drawing to a 2D image, except the final result comes out 3d. Layers support full rotation so anything attached to it is automatically rotated and position just like a limb of an object.

For instance the Reach logo is a GFX (graphic only) gadget attached to the root layer outlined in green. The Layer is rotated slightly but the Reach logo gadget is rotated so it will face the camera.

The other layers are moving scenery and smoke.



What it looks like when played normally:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Nov 2010 00:03
Looks great. I like the style very much.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Nov 2010 00:40 Edited at: 19th Nov 2010 14:31
Demo Of The Halo Reach Menu
The result so far of the Halo Menu, root menu animated backdrop exe attached. (Forgot to put the better version logo in this)

Note: The files containing the characters '[PH]' stands for Place Holder because I don't own the rights to them. Makes sure when you using media, document what is a placeholder and what isn't. Copyright infringement can be messy.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 19th Nov 2010 13:46 Edited at: 21st Nov 2010 04:53
2D UI System - The Origin

When creating anything, we need to plan what it needs. So what do we want as a base to work off:

We want some buttons to interact with:
- Button Gadget (also include checkbuttons, radialbuttons as types)

We want different pages for different menus:
- Scenes

We want non-interactive graphics
- GFX Gadget


Now Let's Make Something - Button Gadget

Again we have to plan what we're doing. We need to interect with a portion of the screen and this is the root of the button, a 2d bounds check. So thats what we need to make first.

We will need to:
- Store the mouse coordinate in a Point Class - Point[ x as integer, y as integer ]
- Store the coordinates for are bounds in a Rect Class - Rect[ x as integer, y as integer, width as integer, height as integer ]

Now the planning is done, let look at the code:


So this is the bases for are button, so lets start making are button class.

Again what we need:
- Store the Bounds of the Button
- Control Alpha // won't be used yet
- String Caption



And putting this into play:



Now Lets Add Button States and Interactivity. (Edit: 21/11/10)

We will be making a 3 state button:
UP - What the button looks like when it's idle.
OVER - What the button looks like when the mouse is within it's bounds.
DOWN - What the button looks like when it's being pressed.

This is where most get it wrong, especially the DOWN state. Most set up the button so when the mouse is clicked then an event is triggered. This is wrong. It should be when the mouse click is released then the event is triggered.

And For The Mouse:
All we need is to store the current and last clicks. With this, we can work out what state the mouse is, for example:


Now the code:


Now that the functionality is done, we can work on the visual component, something basic for now. So here's the final result:


And this is the base for a button. The visual component can be changed for anything, preferably pre-render image/sprites. But this is an example of a good button. In the next part, I'll be going into structing this into a proper class, gadget types and going into to Linked Lists for Scene Childs.

Note: I'm still working on the Halo Reach Menu while making this one. The 3D one takes awhile to setup with the scripting components for animations of gadgets. So I'll update you on the progress of that before a proper tut comes out of it, which will be very similar to the 2D UI System. I'm thinking I might just just highlight details on the 3D one, cause it would take ages to make a tutorial on. So I'll just explain some detail on how it works. I don't want to give away all my secrets, cause you'll end up with loads of newbies with a great 3D menu that they just copied and pasted and a pants game.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 19th Nov 2010 22:53
This is an excellent thread and a great idea.

Some of these can easily be translated to writing a GUI a game in general as well, and not just the menu.

I hope you continue to add lots of examples and alternative ways of doing things, as this will serve as a great tutorial series for novices like myself.

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 20th Nov 2010 21:57
Very Nice! - lots for all of us to learn
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 20th Nov 2010 23:06 Edited at: 21st Nov 2010 01:51
Thanks Guy's

Halo Reach Menu Update

Actual Menu:


My Menu:




The only issue with 3d menus these days is that they are flash based render targets rendering in real time (Scaleform). So they can take full advantage of all those lovely image blending techniques, plus don't suffer from anti aliasing issues. Though this ins't impossible to do in DBP, it's would be a pain and not very performance friendly. So to fake it, you could use shaders for image blending and to eliminate the edges of the plain (when rotated), increase the canvas size of the image and blur out the edges of the image.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 21st Nov 2010 00:21 Edited at: 22nd Nov 2010 03:42
2D UI System - Class Structure and Code Format

When we code larger projects we want are code to have a format, so we don't have to spend ages looking all over for a bit of code. So it's wise to create a format for where everything should be. For example here's mine:

Program Structure (Top Down)
- Core Constant for are program
- Core UDT's
- Core Delcare (globals)
- Class Declares
< SYNC ON >
- Core Setup
- Class Setups
< Initialize Loop >
> Within Game States (because some classes might not need updating until in a certain state) >
- Core Updates
- Class Updates
< SYNC >
< End Loop >
- Clear All Data (to prevent memory issues)
< End Program >
- (Core/Class Structure Go Here)

Class Structure (Top Down)
- Constants
- UDT's (User Defined Types)
- Declares
- Setup or Initials (After SYNC)
- Function Set For Are Class¬
- > Creator/Operator Functions (ex. Create Object)
- > Update Functions (ex. Update Object)
- > Arguments Functions (ex. If Object Exist)
- Misc (Data Statements or Other Gosubs)

Just to explain Declares and Setup/Initials. Any variables we need to declare for are class are chucked all in a gosub. Gosub's are faster than functions so they are useful for declaring variables. Setup/Initials is the part where we need to load media or setup media, and this needs to happen after the sync has been delcared, so all that is chucked into a setup function.

So using this format as an example, lets format are button gadget and program:


Everything has a place now, now we can start working on are UI system.


Diving Into The Depths of UDT's

We going to take a quick look at UDT's, just to show you that they have many uses and because I'm going to be using them in this way for are UI system.

The Passing Variable

This is more personal preferance, but is very handy and thought I'd share. Let's make a ridiculous setup object function, for an example:



Can you imagine using that, what if you wanted to add more params, then that function line would become huge, making are code look horrible. So we introduce the passing variable:



Why is this handy you ask? Well it's when we start defining variables, because firstly it makes your program really tidy, you can see what everything is and you only define what you need. So if we wanted to only set the object positions, we could do this:



Very tidy right. Now for the best part, we introduce the Deflaut Variable. Now this is very handy when using UDT in this way, especially when working editors. What we do is define are deflauts and add a line to are function resetting are passing variable:



Doing things in this way can really reduce the amount of code and keep everything tidy, plus add that little bit of functionality. For example:



A Little Bit On Gosubs

There was a massive debate about Gosubs vs Functions and I couldn't understand what the debate was about because of the major difference between them, declaration of variables. If you declare a variable within a function, it's only local (unless its a global declaration) to that function an that variable is destroyed on function end, freeing up memory. Where as a if you declare a variable in a gosub, your just stuck with it forever (though I do believe you can get rid of variables now, IanM plugin) and you'll end up with tons of temporary variables sitting in memory.

So I believe Gosubs should be used for declaring variables (global or local) you program will need and functions will use them. Gosubs are faster than Functions, so there perfect for declare all are variables.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Nov 2010 15:33 Edited at: 22nd Nov 2010 15:36
2D UI System - Immediate UI

Just thought I'd add this. And Immediate UI is like an 'On Demand' UI, so basically we if we needed a button some where, we only do a check for a button without having to setup a button before hand. This is very handy for small programs or large programs where you just need a basic UI for now. So lets take a look at an example, the Button Gadget again:



All it requires is the bounds and a caption on use, but requires no setup. You can create a menu or gui for an editor entirely on a Immediate UI system. I will give an better example of how do to this as we go further into other gadgets, but for now, here's quick menu example:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 22nd Nov 2010 19:36
Just quickly ask, is there anything people want me to cover or talk about?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 22nd Nov 2010 22:50
I've always been fascinated by the immediate UI deal.. Interesting stuff, and if you have any ideas on expanding on what you've done with the 2D Immediate/UI stuff so far, that would be neat as well.


Also... since you're the only other person I've seen write at length about program structure, maybe you would like to check out a thread I recently made and share your comments there.

http://forum.thegamecreators.com/?m=forum_view&t=178038&b=1

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Nov 2010 00:57
Quote: "I've always been fascinated by the immediate UI deal.. Interesting stuff, and if you have any ideas on expanding on what you've done with the 2D Immediate/UI stuff so far, that would be neat as well."


The only issue with the immediate GUI stuff is some gadgets are difficult to do without storing something, for instance, how would you work out if a drop box or combo list is open, you can't. You'd have to have a global that says the gadget is open. Plus you have to render it every frame, unlike a... do they call it a 'Retained' GUI? you can render things when something has changed. I think you could combine the too though, but I'll have to experiment with that for abit and then post my findings.

MODS: I think this thread should be called Creating a UI System, would you agree?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Lost Dragon
15
Years of Service
User Offline
Joined: 22nd Aug 2010
Location:
Posted: 23rd Nov 2010 05:32
The demo says it's missing msvcp71.dll.
Duke E
17
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 23rd Nov 2010 09:56
My new GUI uses locked (3D) planes to display items in 2D. I use Sven B's Image kit to render the menu item textures.
The 3D plane method means very fast rendering.

I also discussed it some here:
http://forum.thegamecreators.com/?m=forum_view&t=177139&b=1&msg=2111926#m2111926

I use one typed array that holds all the GUI items be it buttons, panels or sliders and so on. I use a variable in the type thats called "Dirty". I set this to true as i get a mouse over or click event or if the GUI updates a textbox that needs to be redrawn. As i know the range of the array to work on depending what is visible on the screen i just have to loop trough a part of the array to look for the Dirty parts and branch out to render those.

On events i set a "State" variable to whats going on (mouse over, mouse pressed) so the retexture branch knows if for example a button is to be rendered as depressed or not.

Regards
Duke
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Nov 2010 15:29
Quote: "My new GUI uses locked (3D) planes to display items in 2D. I use Sven B's Image kit to render the menu item textures.
The 3D plane method means very fast rendering."


Thats what I do, but as a learning tool I thought that might be to advanced to go into. Near the end of the 2d stuff, I'll do a topic on 2.5D UI's.

Quote: "I also discussed it some here:"

Cheers, it was a good read.

Quote: "I use one typed array that holds all the GUI items be it buttons, panels or sliders and so on. I use a variable in the type thats called "Dirty". I set this to true as i get a mouse over or click event or if the GUI updates a textbox that needs to be redrawn. As i know the range of the array to work on depending what is visible on the screen i just have to loop trough a part of the array to look for the Dirty parts and branch out to render those."


When I start talking about other gadgets I'm going to combine them into one type (sort of... there will be a bit on unused variables too), but for now I'll stick to the buttonGadget so people can understand it easily.

As for the 'Dirty' variable, I suggest you look into linked lists, this way you can speed that process up by not having to loop through gadgets that are not dirty. Will go into great lengths about link list at some point and the hugh optimization people can make. I might just end up writing a linked list tutorial.

Quote: "The demo says it's missing msvcp71.dll."

You may be missing some DLL's, if you look at IanM's utilities thread at the bottom of the first post, you can get them there: The Matrix1Utils plugins collection

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Nov 2010 12:53 Edited at: 24th Nov 2010 13:00
2D UI System - Pre-Rendered Gadget Images

Putting all your drawn gadgets into images will speed up your program immensly, even with Cloggys D3D plugin that increasing 2D drawing insanly (mainly text, text in DBP is really demanding), it's still quicker to use pre-rendered images. The simplest way to create a pre-render is the Get Image Command:

Get Image <Image Num>, <left>,<top>,<right>,<bottom>,<texture flag>

Left/Top/Right/Bottom are screen coordinates.
The value of the texture flag to use (0-use stretching, filter, colorkey, or 1-no stretching, no filter, colorkey, or 2-use stretching, no filter, no colorkey, or 3-no stretching, no filter, no colorkey.

The Get Image command is slow so I suggest only using it in the initialization stage of your games. Get Image doesn't retrieve alpha, my rule about alpha with this command is: if you require an alpha channel then create this image in a drawing program and save it as a PNG or DDS. If you only need rgb(0,0,0) for alpha and your game is small then you can use this command, otherwise don't use it.

You don't need to create a bitmap for this command to work, just insure the screen is clear CLS (rgb). But if you don't want to disturb the screen I suggest creating a bitmap. From the help files:

CREATE BITMAP Bitmap Number,Width,Height
CREATE BITMAP Bitmap Number,Width,Height,SystemMemoryMode

The size of the bitmap is only limited by the amount of system memory available. When you create a bitmap, it becomes the current bitmap. All drawing operations will be re-directed to the current bitmap and away from the screen. You can use the SET CURRENT BITMAP command to restore drawing operations to the screen. The parameters should be specified using integer values.

Note: I believe deleting the bitmap restores drawing operations aswell.

Here's an example:

Without Bitmap:


With Bitmap:


Pre-Rendered Button

Take are example of are base button so far seen above, we'd need to render each state for are button and store them, then draw them to the screen. There are 2 methods we can use, Images and Sprites (there's also 3d Plains, but I won't go into that yet). So:

Images Drawing

This involves drawing images directly to the screen:


Sprite Drawing

The advantages of Sprites is there fast, control over alpha/colour and we only update them when we need to. For this I'm adding an last state variable to are button so we don't update the sprite every frame:



A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Nov 2010 21:32
Need some feedback on this please, how useful this is and anything I have missed or need to talk about more. Cheers

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
thenerd
17
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 24th Nov 2010 21:59
I just saw this, very nice stuff here, I love the Halo menu. I haven't read through all the posts yet but it looks like you've got some very valuable info...

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 25th Nov 2010 19:53
Cheers thenerd

I'm nearly done on the halo 3d menu, demo up soon. Just takes awhile to make all the media and the key frame animation stuff I had to do inside DBP. Not fun coding all that without an editor, but still it has a good result.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 27th Nov 2010 02:16 Edited at: 27th Nov 2010 02:18
I am interested in the idea of drawing 2D objects on a 3D plane.. That's supposed to give a speed increase, right?

I was wondering if that can realistically expanded upon and translated into a 2D rendering engine for a game and basically use the GPU to do the bulk of the graphics processing load and let the CPU be more free to handle the logic. Can you also use shaders/other 3D effects to create better Special Effects for your game as well? What about Isometric (2.5D) ?

Or do I misunderstand how it works?

It would be something I might highly consider trying to learn/trackle when I finally move on and attempt my first 2D game.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Dec 2010 00:07
Don't think this is done, been really busy of late. But now back in action, more stuff up soon

Quote: "I was wondering if that can realistically expanded upon and translated into a 2D rendering engine for a game and basically use the GPU to do the bulk of the graphics processing load and let the CPU be more free to handle the logic. Can you also use shaders/other 3D effects to create better Special Effects for your game as well? What about Isometric (2.5D) ?"


Will be going into that as well.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.

Login to post a reply

Server time is: 2026-07-21 17:02:11
Your offset time is: 2026-07-21 17:02:11