Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Starting off  (Read 2270 times)
0 Members and 1 Guest are viewing this topic.
Offline SquidNig

Senior Newbie





« Posted 2012-05-24 06:03:20 »

Hello everyone! I am am new to java, but not coding overall. I want to start making a simple Java 2D game and work my way up from that. But the problem is, i dont know where to start. I know a lot about the basics of Java. I'm a tad bit rusty on threading but that about it.

Alright, so the problem is: I dont know where to start.

Like, at all...

I take a look at the tutorial section of the site and it has a lot of helpful things! Maybe not a lot but it sure can help! So im like, "Alright, this is understandable." So i continue to read it and yes, it is really easy to understand. I start off my java project and continue the Basic Game class in the tutorials section of the forum. But then, my head starts to fill with an immense amount of questions and i dont know what to do...

Like, for example:

1. Whats the difference of Drawing on a JPanel, Canvas, and JFrame? Why do i sometimes need all 3?
2. What is the concept of deltaTime?
3. What the heck is a bufferStrategy!? (Seriously, cant find anything on it.)
4. Why do you pack(); a frame? Or any other means of Components.
5. Why is it that whenever people say to use threads to keep games running smoothly; then i use threads, and its sleeps the entire program?
6. Why is that people have a lot of different ways for setting up a gaming class? Are others not considered correct?


Those are just 6 of the seemingly long list of questions i have for Java, and im pretty sure i have more. But i mean, if anyone can answer feel free?

I suppose the main reason for this post was, where do i truly start java game development? Most of the things i know are coming from Java Tutorials itself and reading books? Now, im kinda at that point where i dont know how to continue.

Can anyone share their stories of how they accomplished getting to where they are now?

Thanks in Advance.
Offline davedes
« Reply #1 - Posted 2012-05-24 06:38:35 »

Java2D is a poor place to start learning game development. You need to write your own game loops, GUI, bitmap font handling, game states, sprite sheeting handling, animated sprites, etc. It's a lot of work for somebody who is just starting out, and on top of all that it's very slow compared to OpenGL. (You can enable OpenGL via a command line switch, but that is not very reliable; and even then likely slower than simple OpenGL because of the overhead of Java2D.)

1.
Canvas is a heavy-weight AWT component primarily designed for the sake of 2D drawing operations; i.e. many people choose to render their game onto it. JPanel is a simple light-weight Swing container. It can hold other components, like Canvas. It could also replace Canvas, and you could render your game right onto a JPanel.

JFrame is the window that has the title bar, close button etc. It also has a "content pane" -- a JPanel that holds any widgets you want displayed within the frame.

You could simply add the Canvas to your JFrame to draw your game. It's more a preference whether you add it to the JFrame's content pane, or whether you add it to another panel, which is in turn added to the content pane.

2. The time in-between each frame is not constant, so you will want to multiply sprite movement by the delta value to ensure that it moves consistently across systems. For example, imagine your game is running at 100 frames per second. If you then try it on a much better computer, and that computer is able to run it at 1000 frames per second, then the gameplay will seem significantly faster. The solution is to determine the amount of time between each frame, and then render the movement based on that. That way, whether your running at 30 frames per second, or 100, or 1000, your sprites will be moving at a consistent speed across platforms.
http://entropyinteractive.com/2011/02/game-engine-design-the-game-loop/

3. It's simply a way to use double-buffering in your application, in order to reduce tearing and keep things efficient.
http://content.gpwiki.org/index.php/Java:Tutorials:Double_Buffering
http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferStrategy.html
http://www.javalobby.org/forums/thread.jspa?threadID=16867&tstart=0

4. It lays out the frame based on the size of its elements -- did you read the javadocs???

5. Because you aren't using them right...

6. Lots of reasons. Preference, efficiency, organization, etc.

Where do you truly start game development? You learn by actually programming -- testing things, experimenting, trial and error, etc. And google. Google will be your absolute best weapon.

Offline SquidNig

Senior Newbie





« Reply #2 - Posted 2012-05-24 06:44:51 »

Well thank you for taking the time to reply to me and answering my questions. It has really helped. I understand that google is my friend (believe me, i use google everyday) but what i mean is. When i truly start to learn, where exactly do i start. Should i go ahead and read most of the javadocs? (seems like the manual you throw away for a watch) Should i start by learning simple gameLoops?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-05-24 06:53:49 »

Hey SquidNig and welcome to JGO!

I remember exactly when I was in your position. I strongly recommend you read this long post just to get a general glimpse of the situation with java game development.

Since you are a beginner, I think you should start with Java2D, since it is simple yet powerful and takes care of things for you so you aren't bothered while learning game development. For more info about Java2D including links about how to load resources, a sample game loop, and more helpful links, check out this post.

For beyond Java2D, that first long post should explain and provide links for later use. As davedes said: Google and the Javadocs are your best friends, not to mention this forum Wink

Good luck!

Offline davedes
« Reply #4 - Posted 2012-05-24 07:32:39 »

Quote
takes care of things for you so you aren't bothered while learning game development
What does Java2D take care of for a game developer? Huh It makes every step of game development more difficult, especially for a beginner.

If you want to make a game, the logical solution is to choose a game library. Java2D is not a game library.

I'm saying this from experience. I also started with Java2D, and I later regretted it. My time would have been much better spent learning Slick2D or LibGDX. Wink

But, decide for yourself. Try drawing some sprites moving across a screen at 60 FPS, with a sound playing in the background, in Java2D. Then try doing the same thing in Slick or LibGDX. Let me know which you prefer...

Offline ReBirth
« Reply #5 - Posted 2012-05-24 07:39:50 »

Quote
takes care of things for you so you aren't bothered while learning game development
What does Java2D take care of for a game developer? Huh It makes every step of game development more difficult, especially for a beginner.
He compares it to other language like C++, Assembly, Cobol, or Brainf**k.

Offline cylab

JGO Ninja


Medals: 38



« Reply #6 - Posted 2012-05-24 10:03:45 »

IMHO currently the best option is to use libGDX right away . It's nice, powerfull, actively maintained and has a strong user base. Just skip the Android setup stuff for starters and use the LWJGL backend.

Mathias - I Know What [you] Did Last Summer!
Offline DruLeeParsec

Junior Member


Medals: 2
Projects: 1



« Reply #7 - Posted 2012-05-24 18:38:01 »

Squidnig:

Even though there are some problems with the book, "Killer Java Game Programming" is pretty decent.  Also, the author has a great website here:
http://fivedots.coe.psu.ac.th/~ad/jg/

That site has all the source code for the book.  In particular I liked his chapters on loop timing.

Since you're starting out I suggest doing something really easy (although you'll quickly find out how difficult "easy" can be).  Try making a background image appear in a frame.

Then make a square bounce around the window.  Start small.  But I'll tell ya, you will learn so much.

1. Whats the difference of Drawing on a JPanel, Canvas, and JFrame? Why do i sometimes need all 3?

I like Canvas because it has a buffer strategy (See #3)


2. What is the concept of deltaTime?

Your game loop will have essentially 2 methods which repeat: the update and the render  methods.  Update usually has an int which is the number of milliseconds since update was last called.  This helps you figure out how far to move things or how fast to animate things.  For example.  Let's say you have a box which moves to the right at 100 pixels per second.  Your update method will pass in milliseconds like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void doUpdate(int delta) {
    // I always like to convert milliseconds into a percent of a second.
   float slicePercent = ((float)delta)/1000;

   // I use the word "slice" because I think of each update as a slice of time. If there was 100 milliseconds since the last update
  // this slice of time would be 10% of a second or slice = 0.10

  // dx is "delta x" or "the change in the x direction"  In this case dx is 100 (pixels per second) and we want to
 // move 10% of that during this slice.
 x = x + (slicePercent * dx);

  // and here we do all our other updates

}


3. What the heck is a bufferStrategy!? (Seriously, cant find anything on it.)

bufferStrategy is essentially having a place to draw your graphics which don't show up on the screen.  When the drawing is done you can flip the offscreen buffer with the screen buffer so now the screen shows what you've drawn.

5. Why is it that whenever people say to use threads to keep games running smoothly; then i use threads, and its sleeps the entire program?
See the "Killer Java Game Programming" link above.  There are good examples there.

6. Why is that people have a lot of different ways for setting up a gaming class? Are others not considered correct?

Oh my gosh now we're treading on religion.   Wink   There will always be as many ways of doing things as there are programmers.  The more I code (and I've been doing it a LONG time) the more I learn and the more my style changes.  Since you're learning just get something in code and get it to work.  Quite a few times I've written something, learned a lot from it, and then threw it all away because now that I understand the problem I realize I should have approached it completely differently.

Good luck and have fun coding something.
Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2012-05-24 19:10:25 »

Quote
takes care of things for you so you aren't bothered while learning game development
What does Java2D take care of for a game developer? Huh It makes every step of game development more difficult, especially for a beginner.

If you want to make a game, the logical solution is to choose a game library. Java2D is not a game library.

I'm saying this from experience. I also started with Java2D, and I later regretted it. My time would have been much better spent learning Slick2D or LibGDX. Wink

But, decide for yourself. Try drawing some sprites moving across a screen at 60 FPS, with a sound playing in the background, in Java2D. Then try doing the same thing in Slick or LibGDX. Let me know which you prefer...
Compared to pure OpenGL and Slick2D, Java2D takes care of many more things for you. The entire java.awt, java.awt.image, and java.awt.geom are amazing tools. Their only downside is the speed.

I don't regret starting with Java2D at all and I never really liked Slick2D Tongue

Offline davedes
« Reply #9 - Posted 2012-05-25 00:10:05 »

Well, compared to pure OpenGL, of course Java2D does more for you in regards to 2D.

But compared to Slick? What are the "many" game-related advantages of Java2D that you find Slick lacks?

Obviously not game loops, joystick input, sprite sheets, tiled map loading, bitmap font rendering, game states, deferred loading, particle systems, sound/music system, SVG parsing, or abstraction of applet/desktop container (just to name a few features of Slick)...

And what did you not like about Slick's API, considering it basically just emulates Java2D's design? (Graphics, drawImage, etc)

Of course, in the end it's all just a matter of preference. Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #10 - Posted 2012-05-25 00:11:03 »

I'm talking more about Graphics2D's features Wink

Offline davedes
« Reply #11 - Posted 2012-05-25 00:21:38 »

What features?
Slick's graphics includes clipping, drawing shapes, drawing images, drawing strings, rotating/scaling/translating, blend modes / alpha masking (and some features Java2D doesn't include). It's missing shear and stroke, but surely those can't be your criteria for Java2D being a better game library than Slick2D? Roll Eyes

Offline SkyAphid
« Reply #12 - Posted 2012-05-25 09:09:57 »

What features?
Slick's graphics includes clipping, drawing shapes, drawing images, drawing strings, rotating/scaling/translating, blend modes / alpha masking (and some features Java2D doesn't include). It's missing shear and stroke, but surely those can't be your criteria for Java2D being a better game library than Slick2D? Roll Eyes

Slick2D is awesome for beginners. I loved it when I used it. Lot's of good documentation here and there too. There are a few glitches though, so be sure to grab the source so you can fix them yourself.

But no, Slick2d >>>>>> Java2D for sure. You can even use some of OpenGLs core functions too for that extra tough stuff. It's great.

“Life is pretty simple: You do some stuff. Most fails. Some works. You do more of what works. If it works big, others quickly copy it. Then you do something else. The trick is the doing something else.” ~Leonardo da Vinci
Online princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #13 - Posted 2012-05-25 10:37:46 »

Slick2D is probably more aimed at people who already know Java2D and as such I wouldn't recommend it for total beginners. If you really want to learn how to do stuff, try vanilla LWJGL, or libgdx.

Cas Smiley

Offline ReBirth
« Reply #14 - Posted 2012-05-25 15:01:01 »

Slick2D is probably more aimed at people who already know Java2D and as such I wouldn't recommend it for total beginners. If you really want to learn how to do stuff, try vanilla LWJGL, or libgdx.

Cas Smiley
Second that. Slick2D would be easy only if you know java2D.

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #15 - Posted 2012-05-25 15:03:14 »

Java2D's API isn't really difficult, in fact I think its quiet a beautiful 2D API especially for new comers and very good for prototyping idea's.

In fact Slick2D makes it even easier/better by removing some of the crappy parts and giving you a really nice game framework around it (better than Swing/AWT API's for games).

So yeh it is a nice place to start IMO Smiley
Offline ReBirth
« Reply #16 - Posted 2012-05-25 15:12:48 »

In fact I also think that java2D makes good job to new comer for limit their fantasy into creating mmorpg.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (35 views)
2014-07-24 01:59:36

Riven (33 views)
2014-07-23 21:16:32

Riven (21 views)
2014-07-23 21:07:15

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!