Notes on Creating 2D and 3D Games with Java

Project - Creating 2D and 3D Games with Java

As I try to complete the YouTube videos on 3D Game Programming I am working on my own set of notes/book about 2D and 3D Game Programming with Java. My goal is to finally complete these notes as I make my way through videos and older PC game books that covered the creation of games at the pixel level - yes without all the APIs and frameworks that enclose and hide all the complexity. Here is a rough draft of Chapter 1. Check out the pdf for the lastest version

Part I – The Foundation

Chapter 1 - Creating Games with Java (Getting Started)

2D platformer

These notes cover the knowledge that is required in order to build 2D and/or 3D games with Java. The initial goal will be to understand how to create games without using the advanced Java APIs. We will start off learning to manage a screen at the pixel level. This will allow us to gain an appreciation for what is going on when we use advanced libraries and frameworks. In the next stage we will learn the basic Java 2D and 3D graphics APIs. In addition, we will explore some popular Java game frameworks that make it easier to create Java game engines.

We will assume that you have at least one-year programming experience with Java so that the basics will not be covered in any detail. We will create many different types of games from various game genres – 2D platformer, puzzle games, car racing and first-person shooters. The ultimate goal is make you the developer comfortable with the concepts, techniques and purpose of tools invented to make building game easier than ever before.


I was reading/working on a rather popular book in Java game programming. I was disappointed that the reasoning behind some basic logic (e.g. the use of trigonometric functions to make space ships move in a particular pattern on the screen) was not explained. I don’t mean “not explained well” I mean not explained AT ALL. In addition, the reasoning behind using some basic Java 2D graphic functions was also missing from the text explanation. The author assumed the reader was familiar with how to use the Java classes such as AffineTransform and Translation but I doubt that could be true in the same book purporting to teach Java to the beginner programmer. In order to feel accomplished and provide the ability take the material to the next level the author was the responsibility to explain things as completely as possible.

This book is for you if you want to learn how to build 2D and 3D games using Java and want to understand the fundamentals in order to be able to construct your own games from scratch. This book is for you if you are tired of feeling like a ‘code monkey’ with no idea what any of the code is doing and how to make changes for your bring your own ideas to code. This book is for you if you seek a comprehensive presentation on game engine development that covers almost every software development aspect – graphics, user input, audio, tools and assets.

Creating software in the arena of video games requires being comfortable and knowledgeable in many different fields of study – mathematics, physics, art, graphics, user interface and artificial intelligence. The math is required in order to appreciate the equations to layout and or move the various actors on the screen. The physics to appreciate how to make objects behave as we normally see them in the real world – for example, a ball bouncing down the road. As a developer we will probably acquire our art online but we will need to know how to handle the graphics that represent our 2D or 3D world. The user interface defines how the player interacts with the game and lastly we will need artificial intelligence in order to imbue or enemies or non-playing character (NPC) actors with challenging and believable behavior.

Why Java?

Quick History of Java

Java was invented at Sun Microsystems by James Gosling, Mike Sheridan and Patrick Naughton. The project started in 1991 by the Green Team and released to the world in 1995. The Java programming language was way ahead of its time since it as created to be used to connect consumer devices and computers. It is not until recently that the concept of devices, or what is widely known as the Internet of Things has gained prominence and popularity (note this is over twenty years after Java’s debut).

Java version 1.0 and 1.1 was released in 1995 on many different platforms. Java was promoted as a “write once, run anywhere” language, a statement that was not initially true but has become more so as the language has grown to include a plethora of libraries and third-party frameworks (many if not most available for free) that make the creation of complex applications easier than ever before. One cannot understate the importance of being able to build a Java application on a Window’s PC and deploy it and use on a Mac or Linux machine – with no changes to the code. When I learned how to program this was not only unheard of but thought to be impossible.

So Java started as a language for small devices and moved to the browsers as applets but actually solidified its place as a language used on the server-side of the world. It is used to deliver web pages, manage banking applications, access databases, as stand-alone applications running on your desktop (e.g. Eclipse) and it is now the main language used to develop Android applications for smartphones and devices.

Java for Games

Does it make sense to develop games using Java?

A very good question to pose: “Is Java the ideal language to create games?” At one time I would have certainly said – no way. Why? Java did have a reputation for being slow and rather awful at building applications with graphical components. In addition, the fact is the most popular and practical language used today to create video games is the programming language C++ not an interpreted language like Java. But the popularity of games such as Minecraft and the number of Java-based games written on Android mobile devices have shown that Java has matured to provide programmers the capability to create 2D or 3D games. Since the original release of Java there have many advancements with the development of Swing components, Java 2D API, just-in-time compilation and various support libraries to support the development of fast full-screen Java applications.


The question really isn’t why develop a game in Java – but why not! The fact is that you can install the Java development kit on Windows PC, Linux and Macintosh machines. The tools or libraries that you will be using are available on all these platforms and they are all free to download and install from the Internet. The concepts and ideas we will be developing are transferrable to other programming languages. It makes sense to use Java!

Eclipse and Setup

The programs will be created using the free and popular Integrated Development Environment (IDE) name Eclipse ( I usually create a workspace for all the work related to a project. We will have several major workspaces for the Java projects we create:

  • JavaGraphics – will cover the basic structure of all our Java game projects
  • JavaLibs – will cover a discussion of Java2D and Java3D libraries.
  • Java2D – Covers the creation of several Java 2D games – from Asteroids to a classic 2D platformer.
  • Java3D – Covers the creation of a Java First Person Shooter (FPS)
  • JavaLWJGL – covers the Java framework Lightweight Java Game Library (LWJGL)
  • JavaLibGDX – covers the LibGDX framework
  • Java jMonkeyEngine - covers the jMonkeyEngine

Each workspace will consist of several projects that cover various aspects of the topic at hand. These notes will cover the reasoning behind the code from the logic to the math.

       : Check latest notes in PDF...

If you want to correspond don't hesitate to connect using Twitter or Tumblr.