Java Gaming for Beginners
As some of you may already know, I'm a staff writer and produce the Java Technology Fundamentals Newsletter as well as write articles and tutorials.
Java gaming seems like a poplular entry point for folks wanting to learning Java programming. Not sure it's a practical entry point, but I may be wrong.
I'd love to hear ideas from you folks what Java topics you feel programmers need to thoroughly understand before even attempting to write a game. Also, are there specific Java technologies or areas you feel we could cover better for folks wanting to write Java games? Any typical beginner misconceptions we can help clear the air about?
Thanks!!!!
**** Nourie
They'd probably need to know about 2D or 3D graphics.
JTeen at 2007-7-5 22:04:47 >

> As some of you may already know, I'm a staff writer
> and produce the Java Technology Fundamentals
> Newsletter as well as write articles and tutorials.
Nice ta meet ya. :)
> Java gaming seems like a poplular entry point for
> folks wanting to learning Java programming. Not sure
> it's a practical entry point, but I may be wrong.
*hehe* Probably because a video game is the sort of application that a lot of people appreciate. Don't get me wrong, writing benchmarking applications can be interesting, but all sorts of people can appreciate a good game.
> I'd love to hear ideas from you folks what Java topics
> you feel programmers need to thoroughly understand
> before even attempting to write a game. Also, are
> there specific Java technologies or areas you feel we
> could cover better for folks wanting to write Java
> games? Any typical beginner misconceptions we can help
> clear the air about?
Topics to thoroughly understand...
Ya might want to emphasize that there is no system-independent way in Java to have free control of the text screen (since it's a stream). It took me a while to give up on writing ASCII-graphics games in Java.
I've noticed a lot of people trying to use the AWT listener thread to do very complicated things; that could be pointed out...
Covering Java2D and Java3D in detail would be nice, although I'd say 2D is more of a priority since it's more feasible for more peeps.
A lot of questions are posted regarding sound. I'm not sure what to do about this, since there is a sound tutorial on the site, but it might help if the J2SDK API doc contained a more obvious mention of it...
> Thanks!!!!
Best of luck to you!
tvynr at 2007-7-5 22:04:47 >

> Not sure it's a practical entry point, but I may be wrong.
Well, I started by writing games, graduated in computer science this year, and am now employed writing games. The important thing for an entry point is coming to grips with the concepts of variables and arrays and methods. OO can come later. To treat those concepts, it doesn't really matter whether you're writing a text adventure or a simple database.
It's not necessary to thoroughly understand anything before attempting to write a game. Trial and error, with the fallback of seeking advice from these forums, is probably going to be effective for anyone who's sufficiently patient and logical to make it as a programmer anyway.
If you're considering building a game that has nice graphics, knowledge of Java 2D should be essential. The Java2D Trail in the Java Tutorial is okay, but it doesn't really cover it from a gaming perspective.
One of the reasons Java games haven't really succeeded on the desktop is because most of the big-wig game developers prefer to code in C++ using Microsoft's DirectX.
Most games have tons of things happening all the same time, so I think its important that Java game programmers understand multithreading well.
And of course, if you're considering an online or multiplayer game, the networking classes are important.
My greatest wish is that someone would develop a game development trail in the Java Tutorial. =)
Regards,
Dante
Important to understand the problems Java present game developers. Such as the inability to control when and how long garbage collection happens. This can cause animation hickups. Along with this explain the problems with object creation during game play, more animation hickups. Therefore you should pre allocate as much as possible and don't clear references until absolutely neccessary.
Also point out ways around using the System.currentTimeMillis() method for controlling game objects based on time. The method is totally inaccurate.
You'll need to do something about the fact that under all windows versions the Thread.sleep() resolution has been set to 10 milliseconds in 1.4.1 beta. I belive (hope to God) this will get removed before it gets out of beta.
Explain various optimization techniques that can have a big impact on Java programs. For example loop invariant code motion for when accessing arrays.
Overall there are a million little tricks and things you need to know to write nice java games.
I am sure that writing games isn't the *best* starting point for using Java, but it is one of the things that often gets people interested in programming (this was certainly the case with me) and although I wouldn't think a "writing a game from scratch to completion" type of tutorial would be very helpful, as everyone wants to write different things, I definitely feel tutorials on the basics of different areas would be very handy. Some things, like basic AI and Pathfinding, basic physics modelling and the like are pretty much universally applicable.
It also seems to me that although 3D programming is by no means for the faint hearted, if I wanted to learn about it Java3D is actually a very good environment for it.
I would say that people - and here I am possibly including myself ;) - would like to see some good instructions on how to handle the basics of Java3D. I have kind of stumbled through with the use of a few good books, but a few tutorials that let you do something a little bit visually impressive in the Java3d environment would encourage people to use it. I'm thinking of stuff like a Lens Flare tutorial, creating your own objects from multiple polygons ( way too many J3D tutorials use the standard polygon objects- it took me ages to work out how to build my own ) and the like, would be very helpful. Also, a glossary of the terms used, Stripcounts, contours, transforms and so on would be really useful because one of the major problems I have had is actually working out what I am looking for when i know what I want an object to do, but I dont know the correct terminology for it.
Also, something on the benefits of object orientation for games development, illustrating basic OO technique would be really handy because most people coming to Java find the way of thinking to be the hardest part. I realise that once you are deep into writing optimised codes you will be using every dirty shortcut in the book, but learning to program clean first is very important imho. I suppose I'm kind of thinking of taking an introductory java course and giving it a games angle really here, because a walkthrough of the standard APIs and how they can be helpful would also be very good in my opinion. In fact, I can sort of imagine a whole course to be had here- lessons/trails along the lines of Introductory Java for writing games, Java Graphics for 2D games, Java graphics for 3D games, Java Networking for games and so on. I guess that's probably beyond your scope right now, but its all ideas, eh?
> I'd love to hear ideas from you folks what Java topics
> you feel programmers need to thoroughly understand
> before even attempting to write a game. Also, are
> there specific Java technologies or areas you feel we
> could cover better for folks wanting to write Java
> games? Any typical beginner misconceptions we can help
> clear the air about?
I'm a volunteer at a computer kids camp right now, and it offers four java courses. Two of those courses specifically teach games programming, since teenagers like me have a greater interest in gaming. In the beginning, we learn simple basics like variables and drawing images. Then we get into animation using threads and event handling, and finally collision detection and some AI. Of course, the students make games of their own, such as Pong, Asteroids, and Tic Tac Toe.
The concepts that the kids learn in this camp are probably the same ones that beginning game programmers will need to know. AWT and Graphics2D are a must for a newbie to learn, but I think some more information for threads would be good, since they're essential in making a fast, action-packed game. Event handling is also important or otherwise like one of our teachers said, "You're not making a game, you're making a movie."
Unfortunately, there are a few students who are just not programming material, or they complain profusely about how complicated/crappy/slow java is and how much other things like VB or Flash are better. When someone is first introduced to Java, they need a good first impression or otherwise they get discouraged. In one class, the teacher rambled on and on about technicalities and theories of the java language and the students didn't understand any of it. There needs to be a balance between hands-on programming and learning about the concepts of the language.
Anyways, for those who are curious about what we learned, here are some demos from last year for one of our games programming courses.
http://www.geocities.com/javagamesbcit/
Frumple
Hi,
Assuming that anyone who wants to write a Java game already has a good understanding of Java (Swing, threads, networking, etc.), I would start with 2d graphics - how to efficiently draw stuff on the screen (buffering, avoid unnecessary redrawing, etc.), how to paint sprites (bitmap basics, how to move/rotate those, etc.), how to perform collision detection. Handling input events (keyboard, mouse) is the next step I would take. All this could be done in a sequential way, no need for explicit multithreading at this stage - that would be the next thing to explain, perhaps introduce a simple robot (ai) that would make decisions as your opponent (second player) and generate the same events as the first player, running in a separate thread. That would be a good intro to networking, where events are also generated by third party, so to speak. That would be all for a basic 2d game. 3d is the same stuff the way I see it, just different drawing methods and collision detection - user interface/ai logic/networking stay the same.
A good way to explain all this would be to write a tutorial for a pacman-style game - it's not extremely complicated, so those who want to learn would not get discouraged, and it has all the important components a computer game needs (graphics, collision detection, user control, ai logic). Sound would be the last thing to worry about - when you have a playable game, you can beautify it with some nice samples.
Mark
> Assuming that anyone who wants to write a Java game already has a good understanding of Java (Swing, threads, networking, etc.)
I don't think that we can make this assumption at all- a lot of people are interested in learning a language purely so they can write games and are very likely to want to start as they mean to go on.
These are really great, helpful responses. Thanks so much!****
> These are really great, helpful responses. Thanks so> much!> > ****Hehehe, so you'd better do something about it. ^_^lol~Dante
> Sound would be the last thing> to worry about - when you have a playable game, you> can beautify it with some nice samples.yup, this is the approach all the **** games companies take as well.
Abuse at 2007-7-5 22:04:47 >

I disagree that sound is not important. It's an integral part of your game. Maybe it's just me, but to me, a game all in all is an experience. The sounds going on are just as important as the graphics that you're seeing ... they go hand in hand. It is extremely obvious to find games, Java or not, that do not take this into careful enough consideration.
Thing is sound is the hardest to do. If java's sound was just
new AudioClip(filename).play();
and would accept ogg/mp3/midi and a whole bunch of other formats it would be much better, as it is it took me 8KB to write a VERY basic midi player, with only start & stop functions. Also many good encoders are complicated or expensive. I think sound is more important the bigger the game, pong without sound is ok, but try a final fantasy with the sound off - it just gets annoying. Indeed, ff music is so good it gets it's own website, http://www.ffmusiconline.com, and it's got good enough to get to #1 in the japanese top of the pops. Thing is it took a whole orchestra (and in a couple of cases choir) to make it along with several hundred thousand pounds worth of equipment - somenting even most professional games studios don't have
If u want sound for internet games, just get Anvil Studio ( http://www.anvilstudio.com ). Anvil uses midi files, which are ultra small. That makes it great for internet games. It's also free.
JTeena at 2007-7-18 11:34:39 >

Suppose I'll jump into this forum.I write multiplayer gaming services, similar to Battle.net (though none are as successful!) I'll try to help anyone out with network-related issues.
St0rma at 2007-7-18 11:34:39 >

What I think you absolutely need to do is an article about threading for games. This is one of the harder points for me, because I don't want to over thread, nor do I want to under-thread. I once had 5 different threads to do a whole bunch of stuff, but I scratched that and changed it all into one. Still don't know if that was good.
Anyway, that is just my 2 cents.
Viruma at 2007-7-18 11:34:39 >

I think someone needs to write up a nice article on the different deployment options... Doesn't even need to be game-specific, for that matter. Yes, the info's spread out over the java pages, but it would be nice if someone could condense it into a tutorial path or something. Applets are good for x, but face limitations. Web Start is good for y, but faces these limitations... Or go the straight application route and get around the security problems... Here's how to pack everything into a .jar and access it in your code. (The .jar tutorial is terrible... Doesn't really explain how you get your helper files (ie .jpegs, .gifs, etc.) out of the jar and into your program) Of course, you're then limited to those who have the JRE... Explain digital signing, and all that other fun stuff.
After struggling with all this for the past few weeks, I can tell you from experience that someone fairly new to Java would LOVE to have this. :)
> If you're considering building a game that has nice
> graphics, knowledge of Java 2D should be essential.
> The Java2D Trail in the Java Tutorial is okay, but it
> doesn't really cover it from a gaming perspective.
>
> One of the reasons Java games haven't really succeeded
> on the desktop is because most of the big-wig game
> developers prefer to code in C++ using Microsoft's
> DirectX.
>
> Most games have tons of things happening all the same
> time, so I think its important that Java game
> programmers understand multithreading well.
>
> And of course, if you're considering an online or
> multiplayer game, the networking classes are
> important.
>
> My greatest wish is that someone would develop a game
> development trail in the Java Tutorial. =)
>
> Regards,
> Dante
__-
the greatest wish if fufilled
will really be a great asset.
_
Why no mention of http://www.javagaming.org/ ? It is Sun guys that got that site going and continue to administrate and monitor the posts.If you want to get the important info on Java gaming that's the place to look.
SWPa at 2007-7-18 11:34:39 >
