Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way of using graphics for games

I am new to java and programming in general,and i am trying to write a little shooting game with a spaceship and aliens, but having a lot of trouble with the graphics. It seems that I am mixing a lot of different kind of components.

How should I do it right?
- Should I use Swing JFrame and then add it a Graphics object?
- Should I make a panel first and add the graphics on to it instead?
- Or maybe should I use a canvas instead of a JPanel?

There are a lot of options, and searching the net for answers makes me very confused. Some advise to use the paint() method while others demonstrates code while using the paintComponent()...

What is the preferred way in the right order for the graphics to be laid and what classes should I use?

like image 787
user2030118 Avatar asked Dec 12 '22 18:12

user2030118


1 Answers

For serious gaming, don't use Swing but rather other more game-specific GUI libraries such as the LWJGL. For simple Games, Swing is OK, but be sure to read the graphics tutorials first as your assumptions on how to draw may need to be changed (I know mine were). For instance you would not use a Graphics class field but would usually draw passively in a JComponent's paintComponent method.

like image 188
Hovercraft Full Of Eels Avatar answered Dec 26 '22 08:12

Hovercraft Full Of Eels