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?

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/

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?

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

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? 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.

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...

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.

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

publicvoiddoUpdate(intdelta) {// I always like to convert milliseconds into a percent of a second.floatslicePercent = ((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. 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.

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? 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.

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

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.

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