Right now I have a "GameGUI Entity" that it's very much like any other entity in the game (the ship, the shots, the aliens). That entity has a sprite of 800x600 pixels with borders and a bottom bar for displaying the game's info. Its center is transparent and the other entities check borders within it.On the info bar, there is a text "Ship's hp" and an "empty life bar" drawn on it.Upon it, I draw 10 entities which holds "first", "mid" and "last" health bar sprites, like this:

Picture of health bars:First: Mid: Last:

Picture of how the GUI it is right now:

Picture of the game running (showing the health bar with some hits, allowing to see the empty effect):

The health bar is held in an ArrayList and depending on the Player's hp, they are allowed to be drawn or not (boolean field on the HealthBarEntity object).

This approach lets me draw a decent game GUI and show the player's life. But I hate it. I need help to make:- Game Menu window (New game, Option...)- In Game GUI to show Player Health, Current Level, Weapon Selected and the like.

Please point me to somewhere, I tried the search option in the forum before posting this but came to nowhere

I've been thinking here at work about making the separation you mention and you just made it very clear and simple, thanks!

But about the GUI itself, I need a bit more of help:

- First, is it ok to do it as I did? One picture loaded into the sprite field of an entity? What if I need to show some numbers, should all be entities and sprites?

This should be fine for your entities, if you need to show numbers just include that in their render methods

Quote

- Why do I need to make sure it has alpha support?

Using the way I suggested you would be drawing the game render first, then drawing an image representing the gui on top of the game render, if there isn't alpha support on that image it will simply cover up the game render. Which is no good, you want people to see the game render, haha!

Quote

- What about the game menu? Should I do it with JPanel?? How do I use custom background and buttons then? Any insight would be very much apreciated.

What I do is create game states, one for the menu another for the game. Something like this:(pseudo code)game state class>init method>>put all your initialization code here, does the state need access to images (sprites) or other system files, does it need to set up any specific output settings? Put all that here

>render method>>put all the drawing stuff here

>enter method>>call this method every time your changing from ANOTHER state to this state, if any settings need to be reset, this is where that happens

>leave method>>call this method any time your changing from THIS state to another state

game loop>update current state>render current state...>sleep

I modify this post later to add in some code, but I am really busy now... about an hour.

Hey! Don't you worry, this is a hobby, no need for hurry. You already done A LOT! If you want, come back tomorrow (it's 19:00 here)

I should learn about game states, because I really don't fully understand how states work, not the methods, they are ok, but the general concept and implementation it's what bugs me. Do states allow me to implement pause, escape to menu, and other stuffs like accessing a map?

Also, don't use 2 BufferedImages for game and GUI, especially since blending is slooowww using Java2D. Draw everything onto a BufferStrategy using Canvas, on 1 Graphics2D instance. If you don't know how to use BufferStrategy, this code should be helpful.

Yeah, it's best to do all your rendering/painting with 1 Graphics2D object. If you use 2 BufferedImage objects, every render you need to get the graphics context from both images, which could cause unneeded slowdown. Not to mention that one is alpha-enabled.

After doing some bench-marking I agree that 2 bufferedImages is slower than passing around a graphics2d object. Though having 2 images certainly made the rendering logic less complicated. But the basic premise remains the same. Game States with update and render methods.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org