Hi,First, let me introduce myself, as this is my first topic. I've been reading the forums for some time now, never posted a question or answered one, but have been around for some time. I'm from Portugal, so if any if there is any Portuguese out there feel free to say hi

I'm a student, finishing my bachelor degree in computer science, and have learned to program using games, most of my classes asked us to make some kind of game to teach us something about programming. So, games are something I like, a lot!, and, currently, am starting a small project to create various games using Java, as this is my favorite language of all. But I'm facing some questions that I would like to your help with.

I have no problem with Java, what I have some problem is understanding where to begin.I have a small game I want to write, it will feature some elements running from one end of the screen to the other, most likely some sharks, that the user needs to stop before they get to some treasure/food/whatever. The game is very simple and, as I don't have any graphics, I'll most like use any image that will allow me to test the game and learn.

So:1) should I use a game engine, and if so what are your suggestions?2) I've read some topics about lwjgl and I'm stating to read more on the official page, I understand it is aimed at 3D games, is it also useful for 2D games? Are there any immediate problems with the library, like multiplatform issues? Or I'm is it also good for 2D games?3) any good tutorials out there, that explain how and why to structure the code instead of the ins/outs of Java language, some that would offer solutions to common problems like performance, image flickering, optimizing dirty rectangles, etc.4) I want to use Swing on some games, mostly because it fits better than creating my own menus, is there any problem I should be aware of?5) any advices that you can offer?

I'm going to follow the Space Invaders tutorial, from www.cokeandcode.com, maybe some questions will be answered there, mostly I have no idea how to start creating the games I want.

LWJGL works great for 2d games as well. Check out my website and puppygames for some examples. It's been used for numerous commercial games and is cross platform. Highly recommended.

Don't use Swing however, unless you're doing something with lots of gui controls (like a management sim or something). Just do things yourself with text and images - you can get a long way with just text and buttons which can be coded up very simply and quickly. IMHO Swing is too ugly and slow for games.

Swing is one of the things I use more, and, like most things in Java, if it's slow it's the programmers fault As to being ugly, well, is as ugly as any other control in your OS, considering it uses the OS's look and feel and, if you want your own, either build one, not that hard, or use one of the many and nice look-and-feels out there.

But I'm considering Swing for small games that usually have such menus and interaction, things like the Windows games suite, Solitaire, Free Cell, that sort of things. Small applications that work best, from a usability view, with these controls that with "home made image/text based" graphics.

Sure you can write your own look and feel, but that only really affects the visual element. Swing controls don't give great feedback to the user and that can't be easily done with just a L&F change. Similarly you can't easily have overlapping or transparent controls, so you usually have to settle for a blocky rectangle next to your game area. You can't do something simple like this and so it sticks out like a sore thumb. This isn't really surprising - Swing is built for "traditional" GUI apps, with totally different conventions, interaction and rules. Trying to crowbar that into a game isn't going to yeild good results.

If you're going for something like Solitare then I guess it'd work, but I've always thought they had an ugly and non-intuitive UI anway.

You can't do something simple like this and so it sticks out like a sore thumb.

Though I'm starting to deviate from the topic, I'll have to say that you can easily make something like that, but I'm not thinking on using swing that way, most of the use will be for "standard" menus and windows.

One other way I want to use Swing is by using JFrame, JPanels, etc., instead of other components like Canvas or something alike.

Though I'm starting to deviate from the topic, I'll have to say that you can easily make something like that

I'd like to see that. There's only so far you can go with the L&F API and I think you'd have a hard time getting something that runs at an acceptable framerate with the same quality (ie. proper antialiased edges and everything).

However we're probably way off topic now.

Of course there's always Slick which has a nice variety of options for GUI controls.

LWJGL and JOGL are both terrific for 2D games. I don't recommend using a game engine because making your own won't take long and the process of making it will allow you to familiarize yourself with LWJGL/JOGL. When choosing which to use, LWJGL has been used for more commercial games, but it seems more people use JOGL; especially on these forums.

One other way I want to use Swing is by using JFrame, JPanels, etc., instead of other components like Canvas or something alike.

Using a JFrame and JPanel is most likely not going to provide you with any additional benefits over Frame or Canvas. I don't recommend using Swing for things like buttons because swing is bulky by nature, and while the performance hit is likely insignificant with a simple game, it is quite significant for a larger game.

When choosing which to use, LWJGL has been used for more commercial games, but it seems more people use JOGL; especially on these forums.

I think I'll be going for LWJGL at the moment, maybe I'll try JOGL later.So no game engine? I have been looking at GTGE, though I don't like the authors view on the LGPL license, but that's another problem, nevertheless I'm not very fond of reinventing the wheel , so sooner or later I'll have to use a game engine, even if it's made by me.

That was using a custom border layout that I made which lets you place images around each component. The result looks pretty clean, although I totally agree that Swing is annoying most of the time. On the program with the above screenshot, for example, components are often resized stupidly and there's no way to fix it. Also on Mac Swing seems to have been screwed over lately – unless you resize the window, it appears blank at first.

Below is a screenshot for a GUI for a level editor that I made without Swing. I think it looks prettier and it's much easier to control. Basically I just check to see if the mouse click intersects a Rectangle object that represents each button. Simple.

I know there are a lot of sprite sites out there, but where can I find a site with good tutorials on how to use sprite sheets?

I have used tiles, created from one single image, but that image had all sprites spaced evenly, I have some sheets with images of different sizes, how can I use them correctly?

Also, some nice tutorials would be welcome, for example, the Space Invaders tutorial was the first one to use accelerated graphics. But it uses a strange form of movement and sprite animation, at least from what I'm used to.

I believe the tutorial uses dx and dy and delta, which are actually much smarter to use on a game, because it allows for dynamic frame rate.

I got a bit lost on why the OO hierarchy was the way it was, but I failed to understand how to make an entity move with the same speed, it would start slowly but at the end was speeding up.But that is another problem for me to solve

I think I now understand what my real questions were, let's see if I can make any interesting games

Oh, by the way, anyone knows any jigsaw creation algorithms? I wanted to make a small jigsaw puzzle but I can't manage to find a single algorithm on the subject. Or any hints on how to start.

I made a jigsaw game back in the day. If I recall correctly I started out with the whole image and slowly worked in an algorithm to make pieces. I started by breaking it into squares that gradually became fancy arcs and curves.

I had an array of arrays to represent the pieces like a 2D rpg would have a tiled map. The pieces are initially set to null and are created one by one starting at the top left and filling in rows before columns. When the algorithm created the tile it would check for any neighbors, if the neighbor was not null, it would make its side the opposite of its neighbor's so they could fit together, if the neighbor was null, it would randomly create an arc to represent its side, and if the piece was at the edge of the image it would make that side flat.

The hardest part is that the shapes don't have set dimensions so converting screen coords to test if the piece belongs there when the player moves it is difficult. I don't remember how I overcame this, sorry.

I know my explanation is confusing and sorry about that, but hopefully it will give you ideas on how to start.

(...)The hardest part is that the shapes don't have set dimensions so converting screen coords to test if the piece belongs there when the player moves it is difficult. I don't remember how I overcame this, sorry.

I know my explanation is confusing and sorry about that, but hopefully it will give you ideas on how to start.

It was not confusing, don't worry .I had two methods to create the pieces, either have about 6 images representing pieces and then cut the image based on these example images or create the lines on the fly. I would prefer the last one.For matching the images I was thinking of creating an object that would have the piece and references for each neighbor, some linked list or similar, though a piece can have a max of 4 neighbors, so 4 simple variables would do.At creation I would fill in the variables or the list, whatever, and so each piece would know and have direct access to the ones next to it.

Now, cutting the pieces on the fly is something I honestly can't do. After posting here I search a bit more, even found a source code in Delphi, but I'm not that fluent in Delphi to completely understand how the curves are made.

And here is the source for a jigsaw game in python and pygame, python is fairly easy to read without experience programming in it. I think you might have to download the python language to view the code though, not sure. (it's a small download anyway).

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