why are people trying to use Java2D to make games?

Why are so many people here trying to use Java2D to make games? The API is clunky, riddled with gotchas, and generally slow. You can make a nice game with it, but it’s harder than it needs to be. I’m not mentioning this to push libgdx, I just think writing games in Java might be taken more ever so slightly more seriously if we do more to discourage using Java2D at all (java4k excluded of course).

People are using it because most Java tutorials shows Java2d as example to graphics.

I guess it’s also not too easy for a newbe to set up jars and natives in their IDE’s…

I take it you never tried libGDX? :smiley:

Every single tutorial, excluding the few I’ve seen on this site, that I’ve read/looked at/referenced/etc… all showed how to use Java2D to do whatever I was trying to do. All these other things like Stick2D, LWJGL and whatever else there are seem to be a complete pain to use and figure out how to use when you first look at them.

I do have ^^

LWJGL is much easier than it seems for programming newbies, but it suffers from a lack of good tutorials.

Then we need to get some tutorials made for all of these non-Java2D thinggys.

basic reason is that there is a wealth of information about Java2D, and you end up naturally there, when learning java.
You get told OpenGL is way more complicated and libs like libgdx use OpenGL.
And what is a lib anyway and how do you use it ?

Libgdx has not as much documentation, example, blog entries and stuff as java2D, naturally
and much of libgdx tutorials and examples are actually outdated and do not work anymore - those should really be removed from the web btw.

I think it was davedes who suggested it: Someone should really write some code to make usage for libgdx “easier”, to hide things like spritebatches and stuff

While I do agree with you, I did learn a lot from using Java2D for my first 2 games. I would not have been able to understand the workings of libgdx, had I not been faced with many of the mathematical challenges, and the use of patterns, while using Java2D.

I don’t think it’s THAT difficult to work with Java2D, but it does force you to learn every little bit of the process, of getting a small game running even remotely smoothly. Libgdx, while a very helpful framework, does leave you without having to build your own game-structure, and lets you concentrate on the most creative pieces of the process.

I think some of you might’ve become too adept at game-programming, to see the small challenges newbies can run into. It is very frustrating to debug something, when you don’t understand how it works. The kinds of problems you run into, only depends how much you know about programming and/or system-/data-structures.

And the fact that most of the tutorials requre you to have X library/API
Even if you use immediate mode you get about the same performance as Java2D. (okay, that’s a guess, someone could confirm this?)
I’d say that once you know how to use it, it’s easier to code than Java2D.
Especially setting up the canvas/display. Display.create() and a few matrix setups vs creating a jframe, a jpanel, a canvas, setting the size, double buffering, adding the components to their parents etc.

Back to the statement on tutorials all being for APIs, I am against this kind of thing. If someone wants help with one aspect of LWJGL, don’t link them to an API/library with tons of other irrelevant stuff, give them source code specifically for the problem (if you have it) and tell them to go nuts. Most non-n00bs don’t want to have to download a whole library just to solve one simple problem. They want to learn how something is done so they can develop their skills at programming.
[/rant]

Anyway, Java2D is not all that bad for simple 2d games. It’s just when people start asking questions about how to do X with it when most people here use some OpenGL based library that the problem begins.

IMO most people who are encouraging the use of Java2D for newbies have not had very much experience with alternatives like LibGDX.

LibGDX is easy as pie to setup and includes a huge number of utilities to avoid reinventing the wheel. No need to worry about physics, tiled map loading, texture packing, bitmap font rendering, efficient sprite rendering, game loops, etc. Sound is obviously another huge bonus. A newb shouldn’t have to worry about BufferStrategy or how to implement their own game loop – 99% of them will just copy-paste loops, anyways – instead, they should be focusing on essential gameplay programming. Once they get more comfortable, they can start learning about graphical programming and optimizations, including shaders, game loops, vertex buffers, and other more advanced concepts.

Even the concepts that you learn in Java2D – i.e. CPU image processing to tint an image red, or using AlphaComposites to work with transparency – do not transfer well to the OpenGL pipeline. This is why so many newbies coming from Java2D have issues like “Why is my 9041x52 texture not loading?” or “How can I modify the byte[] array of an OpenGL texture?” Another common mistake is trying to use polygons to make a circle/line, when really a texture region would be much more efficient.

Now that we’re in 2012, the only reason to use Java2D is for Java4k.

With that said, the major drawback to LibGDX is that it introduces a few foreign concepts to newbies – e.g. texture regions, color format, matrices, glBlendFunc, Framebuffer, etc. Slick did a good job at hiding those concepts (although, at the expense of performance/flexibility) which is why it appealed to newbies.

[quote]Back to the statement on tutorials all being for APIs, I am against this kind of thing. If someone wants help with one aspect of LWJGL, don’t link them to an API/library with tons of other irrelevant stuff, give them source code specifically for the problem (if you have it) and tell them to go nuts.
[/quote]
This is simply not possible. Imagine the following, which is an extremely common question:

“How do I render a texture to the screen?”

In the programmable pipeline, you need shaders, matrices, VBOs, texture loaders, etc. If they don’t understand any of those concepts, dumping thousands of lines of disorganized code is not going to help them. This is why the lwjgl-basics API exists – because it’s really the most minimal way to give a “code paste” to the above answer, using modern GL and OO practices.

This is simply not possible. Imagine the following, which is an extremely common question:

“How do I render a texture to the screen?”

In the programmable pipeline, you need shaders, matrices, VBOs, texture loaders, etc. If they don’t understand any of those concepts, dumping thousands of lines of disorganized code is not going to help them. This is why the lwjgl-basics API exists – because it’s really the most minimal way to give a “code paste” to the above answer, using modern GL.
[/quote]
Bold #1: Those are a case of not using Google.
Bold #2: Another case of not using Google.

Google is the answer. There is always someone who knows the answer other people don’t, you just have to find them.
[hint-for-Riven]There should be a notice that shows before posting in Newbie & Debugging Questions that says “Have you Googled it first?”[/hint-for-Riven]

While your solutions are good for newbies, what about slightly more experienced programmers who want to actually learn how to do things instead of just blindly using other people’s code?

I might be one of the few who prefer this, but I prefer knowing why and how my code works, before moving on. So I enjoyed learning how to make game loops and the like in java2d.

I’m currently trying to learn some opengl with lwjgl, and to be honest, it’s A LOT easier to start out with java2d. How many lines of code does it take to render a fricking square? 1 line in java2d, and too many in opengl.

And yes, more or less all tutorials on opengl out there doesn’t work. I’ve seen more than 1 tutorial that uses indexes less than -1 and greater than 1 for vertex2f and the like, and when I’ve tried to use those snippets, they don’t work, because that’ll render it outside of the screen. No explanation of why though… So, I’ve figured that 0,0 is the center of the screen(wtf? how does that make sense in a world where the upper left corner is 0,0?) and the indexes is percentages… so 1 is clinging to the right side of the screen and -1 is the left… Couldn’t find any documentation on it though…

I haven’t even gotten to rendering simple sprites to the screen yet, because that requires that I learn shaders and whatnot, just to render a picture…

So yeah, for a newbie, learning opengl right off the bat is the worst kind of idea anyone could get. However, if the amount of tutorials that are up to date, useful and organized grows a couple of thousand times, then maybe opengl will be something that’s “easy” to learn…

Of course you’ll still need to know of matrices etc. but that shouldn’t be too big of a problem for anyone aspiring to becoming a programmer. (Seeing how important math is in the field of programming.)

That’s just my 2 cents. :slight_smile:

You like being patronized much?

[quote]I might be one of the few who prefer this, but I prefer knowing why and how my code works, before moving on. So I enjoyed learning how to make game loops and the like in java2d.

I’m currently trying to learn some opengl with lwjgl, and to be honest, it’s A LOT easier to start out with java2d. How many lines of code does it take to render a fricking square? 1 line in java2d, and too many in opengl.
[/quote]
I don’t get this “I don’t like to use APIs, I want to write everything myself” attitude. Java2D is an API. Do you think Graphics.drawImage is a magical method that exists on all operating systems?

LWJGL is a thin wrapper on OpenGL – it’s not meant to make your life easier when rendering a 2D sprite. That’s why LibGDX, Slick, lwjgl-basics, etc. exist.

I dare you to compare a bare-bones Java2D (active rendering) sprite rendering example to a Slick/LibGDX/etc sprite rendering example, and then tell me that the Java2D example is easier for newbies to understand or requires less code. ::slight_smile:

A quick google for “lwjgl sprite rendering” let me to http://www.cokeandcode.com/info/tut2d-4.html and looking at the code under “LWJLGL Sprite” I see an exceptional lot of lines, vs. g.drawImage(sprite, x, y, null);

So yeah… :slight_smile:

There is no point arguing this.

People do what they want. :point: Best answer so far.

Why argue about rape, people do what they want.

Why have elections, people do what they want.

Why do we need police, people do what they want.

The question was WHY people use Java2D, not whether people should use it.