Preventing IntelliJ code auto formatting from ruining your day

1. febrero 2015

 

Today I ran into something extremely annoying while typing some JSON for a LibGDX tutorial.  LibGDX uses a naming convention that IntelliJ doesn’t like…  here, I’ll show you what I mean.

 

codeReform

 

Suffice to say… it’s pretty annoying.  What’s even more annoying is there is simply no way to turn this behavior off.  There is however a way to suppress it thankfully.  It isn’t intuitive however, so I figured I would make this post.  So hopefully if you are struggling with turning off IntelliJ automatic code reformatting in JSON, this will be useful to you.

 

Go to File->Settings… menu.  Locate Editor->Code Style settings.   Find “Formatter Control” and tick Enable Formatter markers in comments. 

image

 

Now add // @formatter:off at the top of your file and edit like normal.   Now…

 

codeReform2

 

Much better!

General, Programming ,




Godot Engine Tutorial Part 3 -- Program Lifecycle and Input Handling

28. enero 2015

 

This tutorial is available in video form here or embedded below. 

 

Now might be a good time to pause and look at the life cycle of a typical program, as this can be a bit confusing with Godot yet is something you really need to understand.  Every non-trivial game has a game loop somewhere.  This is the code that runs after a program starts and is basically the heart of your application.  In pseudo code, it might look something like this:

 

main() {
   
   setupApplication()
   scene = createScene()
   
   while(!quit){
      get_input()
      update_physics()

      scene.updateAllChildren()
      scene.render()
   }
}

At it's heart it’s a glorified loop that runs over and over, checking for input, updating the scene and rendering the results until told to stop.

 

Godot of course is no exception, although by default this behavior is hidden from you as is the norm with game engines.  Instead the object that owns your scene is a SceneTree which itself inherits the MainLoop, which provides the above functionality.  A default one is provided for you, but if you wish you can implement your own, more on that below. 

 

What you should however realize is that this SceneTree is the beating heart of your application.  Every frame it calls it’s active scene passing in all the input that has occurred, as well as updating nodes that request updating.  We will look at this process now.  One important thing to be aware of… Nodes can access the SceneTree using the method .get_tree().

 

Updating a Node every frame

 

Ok, so that’s the basics of how program execution flows, now let’s take a look at a more practical example.  Let’s say for example we have a Sprite that we want to update every frame.  How do we tell our MainLoop that we want or Node to be updated?  Fortunately it’s quite simple. 

 

Create a Sprite node, add a graphic, position it on the screen then add a new script to it.  All of this was covered in the previous tutorial if you are unsure how to proceed.

 

Now that we have a Script attached, first we need to tell it we want to receive updates.  That is, every iteration of the main loop, we want our script to be called.  This is a two part process, pun not intended… much.  First, in your _ready function, you tell Godot you want to receive updates by called set_process(true).  Then you override the virtual function _process().

 

Let’s take a look at a simple sprite that moves right until it hits the edge of the screen, at which point it wraps around.

extends Sprite


func _ready():
   self.set_process(true)
   
func _process(delta):
   var cur_pos = self.get_pos()
   cur_pos.x += 100 * delta
   
   # wrap around screen
   if(cur_pos.x > self.get_viewport_rect().size.width + self.get_item_rect().size.width/2):
      cur_pos.x = -self.get_item_rect().size.width/2
   self.set_pos(cur_pos)

set_process tells Godot to call this nodes _process() function.  The value passed in, delta, is the elapsed amount of time since the last time _process was called.  As you can see in the above example, this value can be used to animate at a constant rate.  The above example will update the X value by 100 pixels per second.  Your end result should look something like this:

 

Video_2015-01-27_105150

 

So, in a nutshell, if your want to handle updates in your Node derived object, you simply call set_process(true) and provide a _process(float) override.

 

Handling Input by Polling

 

That moves us on to handling input.  You will notice that Input and Process handling are very similar.  There are a couple ways you can handle input in Godot.  Let’s start with the easiest, polling.

 

You can poll input at any time using the global object Input, like so:

func _process(delta):
   if(Input.is_key_pressed(KEY_ESCAPE)):
      if(Input.is_key_pressed(KEY_SHIFT)):
         get_tree().quit()

 

This checks  first if the ESCAPE key, then if the SHIFT key (is also!) pressed.  If so we tell the SceneTree to exit the application.  As I said earlier, a node can access it’s SceneTree using get_tree().

 

In addition to polling for keyboard, there are also methods is_joy_button_pressed(), is_mouse_button_pressed() and is_action_pressed() which will make more sense in the near future.  You can also poll for status.  For example, to check the mouse cursor or touch location you could:

 

func _process(delta):
   if(Input.is_mouse_button_pressed(BUTTON_LEFT)):
      print(str("Mouse at location:",Input.get_mouse_pos(), " moving at speed: ", Input.get_mouse_speed()));

There are other inputs you can poll as well, mostly mobile based, but they all use a very similar interface. I will cover mobile specific controls at a later point in this series.

 

Handling Input as Event Driven

 

You can also have Godot hand your application all the Input events as they occur and choose what to process.  Just like handling updates, you have to register to receive input events, like so:

func _ready():
   set_process_input(true)

 

Then you override the function _input, which takes an InputEvent as a parameter.

func _input(event):
   # if user left clicks
   if(event.type == InputEvent.MOUSE_BUTTON):
      if(event.button_index == 1):
         self.set_pos(Vector2(event.x,event.y)) 
         
   # on keyboard cursor key
   if(event.type == InputEvent.KEY):
      var curPos = self.get_pos()
      
      if(event.scancode == KEY_RIGHT):
         curPos.x+= 10
         self.set_pos(curPos)

      if(event.scancode == KEY_LEFT):
         curPos.x-= 10
         self.set_pos(curPos)

 

The above example handles a couple different scenarios.  First if the user clicks the left button, we set the position to the mouse’s current x and y location, as passed in by the InputEvent class.  Notice in this case I tested for button by index instead of the define BUTTON_LEFT like earlier.  There should be no functional difference, although this would allow you to test for buttons for which a mapping isn’t defined, such as one of those insane 12 button mouse.  Next we check to see if the event is a KEY event and if it is we check which key.  In the event of the right or left arrow, we update our position accordingly.

 

Sometimes however when you handle an event you want it done and gone.  By default all events will continue to be broadcast to all event receivers.  When you don’t want this behavior, it’s fairly simple to tell Godot that an event is handled.  From the above example, let’s swallow the event in the case of it being an InputEvent.KEY.  This means only this class will have access to keyboard events ( well… and GUI controls, which actually get their crack at the events earlier on ).

   # on keyboard cursor key
   if(event.type == InputEvent.KEY):
      self.get_tree().set_input_as_handled()
      var curPos = self.get_pos()

 

Calling set_input_handled() will cause the InputEvent to propagate no further.

 

Finally it’s possible you want to do a catch all.  Perhaps you want to log all of the unhandled input events that occurred.  This can also be done and you also have to register for this behavior, like so:

func _ready():
   set_process_unhandled_input(true)

Then you simply override the corresponding function:


func _unhandled_input(event):
   print(str("An event was unhandled ",event))

In this case we simply log the event out to the console.  Warning though, there will be A LOT of them.  Just no keyboard events, since we are now eating those!

 

Input Maps

 

Quite often you want several commands to perform the same action.  For example you want pushing right on the controller d-pad to perform the same action as pushing the right arrow key.  Or perhaps you want to let the user define their own controls?  In both of these cases and input alias system is incredibly useful… and thankfully Godot has one built in… InputMaps.

 

You may have noticed the InputMap tab when we were in Project Settings earlier… if not open up Project Settings now…

image

 

Here you can see a number of mappings have already been defined for UI actions.  Lets go ahead and create a map of our own, MOVE_RIGHT.

At the top in Action enter MOVE_RIGHT

image

Then click Add

image

A new entry will be added to the bottom of the page, like so:

image

Click the + icon and add a new mapping of type Key

image

 

You will then be prompted to press a key:

image

 

Repeat this process and instead select another device… im going to also map the right mouse button, like so:

image

 

Your Input Map should now look something like this:

image

 

Now click the Save button and close the dialog. 

Now in code you can easily check activity using the input map, like so:

func _process(delta):
   if(Input.is_action_pressed("MOVE_RIGHT")):
      var cur_pos = self.get_pos()
      cur_pos.x += 1
      self.set_pos(cur_pos)

This code will run if either condition is true… the Right key is pressed or the Right mouse button is.  The above example is polled, but it’s just as easy to use an InputMap with event driven code, like so:

func _input(event):
   
   if(event.is_action("MOVE_RIGHT")):
      self.set_pos(Vector2(0,0))

 

One warning here however…  Actions are more states ( as in On or Off ) than they are Events, so it probably makes a great deal more sense dealing with them the former ( polling ) than the later ( event driven ).

 

A Peek Behind the Curtain

 

If you are like me, you probably aren’t content with not knowing exactly what is going on behind the scenes.  Black boxes just aren’t my thing and this is one of the great things about Godot being open-source, there are no black boxes!  So if you want to understand exactly how program flow works, it helps to jump into the source code.

 

THIS IS COMPLETELY OPTIONAL!

I figured I would bold that.  The following information is just for people that want to understand a bit more what is happening behind the scenes…  We are going to hunt down the actual main loop in the source code, and essentially it’s right here in the function main/main.cpp.  Specifically the method iteration() is effectively the main loop:

bool Main::iteration() {

   uint64_t ticks=OS::get_singleton()->get_ticks_usec();
   uint64_t ticks_elapsed=ticks-last_ticks;

   frame+=ticks_elapsed;

   last_ticks=ticks;
   double step=(double)ticks_elapsed / 1000000.0;

   float frame_slice=1.0/OS::get_singleton()->get_iterations_per_second();

   if (step>frame_slice*8)
      step=frame_slice*8;

   time_accum+=step;

   float time_scale = OS::get_singleton()->get_time_scale();

   bool exit=false;


   int iters = 0;

   while(time_accum>frame_slice) {

      uint64_t fixed_begin = OS::get_singleton()->get_ticks_usec();

      PhysicsServer::get_singleton()->sync();
      PhysicsServer::get_singleton()->flush_queries();

      Physics2DServer::get_singleton()->sync();
      Physics2DServer::get_singleton()->flush_queries();

      if (OS::get_singleton()->get_main_loop()->iteration( frame_slice*time_scale )) {
         exit=true;
         break;
      }

      message_queue->flush();

      PhysicsServer::get_singleton()->step(frame_slice*time_scale);
      Physics2DServer::get_singleton()->step(frame_slice*time_scale);

      time_accum-=frame_slice;
      message_queue->flush();
      //if (AudioServer::get_singleton())
      // AudioServer::get_singleton()->update();

      fixed_process_max=MAX(OS::get_singleton()->get_ticks_usec()-fixed_begin,fixed_process_max);
      iters++;
   }

   uint64_t idle_begin = OS::get_singleton()->get_ticks_usec();

   OS::get_singleton()->get_main_loop()->idle( step*time_scale );
   message_queue->flush();

   if (SpatialSoundServer::get_singleton())
      SpatialSoundServer::get_singleton()->update( step*time_scale );
   if (SpatialSound2DServer::get_singleton())
      SpatialSound2DServer::get_singleton()->update( step*time_scale );


   if (OS::get_singleton()->can_draw()) {

      if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
         if (VisualServer::get_singleton()->has_changed()) {
            VisualServer::get_singleton()->draw(); // flush visual commands
            OS::get_singleton()->frames_drawn++;
         }
      } else {
         VisualServer::get_singleton()->draw(); // flush visual commands
         OS::get_singleton()->frames_drawn++;
         force_redraw_requested = false;
      }
   } else {
      VisualServer::get_singleton()->flush(); // flush visual commands
   }

   if (AudioServer::get_singleton())
      AudioServer::get_singleton()->update();

   for(int i=0;i<ScriptServer::get_language_count();i++) {
      ScriptServer::get_language(i)->frame();
   }

   idle_process_max=MAX(OS::get_singleton()->get_ticks_usec()-idle_begin,idle_process_max);

   if (script_debugger)
      script_debugger->idle_poll();


   // x11_delay_usec(10000);
   frames++;

   if (frame>1000000) {

      if (GLOBAL_DEF("debug/print_fps", OS::get_singleton()->is_stdout_verbose())) {
         print_line("FPS: "+itos(frames));
      };

      OS::get_singleton()->_fps=frames;
      performance->set_process_time(idle_process_max/1000000.0);
      performance->set_fixed_process_time(fixed_process_max/1000000.0);
      idle_process_max=0;
      fixed_process_max=0;

      if (GLOBAL_DEF("debug/print_metrics", false)) {

         //PerformanceMetrics::print();
      };

      frame%=1000000;
      frames=0;
   }

   if (OS::get_singleton()->is_in_low_processor_usage_mode() || !OS::get_singleton()->can_draw())
      OS::get_singleton()->delay_usec(25000); //apply some delay to force idle time
   else {
      uint32_t frame_delay = OS::get_singleton()->get_frame_delay();
      if (frame_delay)
         OS::get_singleton()->delay_usec( OS::get_singleton()->get_frame_delay()*1000 );
   }

   int taret_fps = OS::get_singleton()->get_target_fps();
   if (taret_fps>0) {
      uint64_t time_step = 1000000L/taret_fps;
      target_ticks += time_step;
      uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
      if (current_ticks<target_ticks) OS::get_singleton()->delay_usec(target_ticks-current_ticks);
      current_ticks = OS::get_singleton()->get_ticks_usec();
      target_ticks = MIN(MAX(target_ticks,current_ticks-time_step),current_ticks+time_step);
   }

   return exit;
}

 

If you take a good look at that code, you'll notice beyond the complexity it's actually remarkably close to the pseudo code I started this post with. As I said, most game loops start looking pretty same-y over time. Now looking at the code you will notice a number of calls like this:

 

OS::get_singleton()->get_main_loop()->iteration( frame_slice*time_scale ))

These are callbacks in to the MainLoop we mentioned earlier. By default Godot implements one in C++ you can access here in core/os/main_loop.cpp:

 

#include "main_loop.h"
#include "script_language.h"

void MainLoop::_bind_methods() {

   ObjectTypeDB::bind_method("input_event",&MainLoop::input_event);

   BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN);
   BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT);
   BIND_CONSTANT(NOTIFICATION_WM_QUIT_REQUEST);
   BIND_CONSTANT(NOTIFICATION_WM_UNFOCUS_REQUEST);
   BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING);

};

void MainLoop::set_init_script(const Ref<Script>& p_init_script) {

   init_script=p_init_script;
}

MainLoop::MainLoop() {
}


MainLoop::~MainLoop()
{
}



void MainLoop::input_text( const String& p_text ) {


}

void MainLoop::input_event( const InputEvent& p_event ) {

   if (get_script_instance())
      get_script_instance()->call("input_event",p_event);

}

void MainLoop::init() {

   if (init_script.is_valid())
      set_script(init_script.get_ref_ptr());

   if (get_script_instance())
      get_script_instance()->call("init");

}
bool MainLoop::iteration(float p_time) {

   if (get_script_instance())
      return get_script_instance()->call("iteration",p_time);

   return false;

}
bool MainLoop::idle(float p_time) {

   if (get_script_instance())
      return get_script_instance()->call("idle",p_time);

   return false;
}
void MainLoop::finish() {

   if (get_script_instance()) {
      get_script_instance()->call("finish");
      set_script(RefPtr()); //clear script
   }


}

 

The default main loop in turn is mostly a set of callbacks into the active script.  You can easily replace this MainLoop implementation with your own, either in GDScript or C++.    Simply pass your class name in the to main_loop_type value in Project Settings:

image

 

Granted, very few people are actually going to need to do this…  mostly the people that want to live entirely in C++ land.  I do however think it’s extremely valuable to understand what is going on behind the scenes in a game engine!

 

The Video

 

Programming , , ,




Godot Engine Tutorial Part 2– 2D Scenes, Sprites, Coordinates and Viewports

26. enero 2015

 

In this tutorial we are going to be taking a look at what seems to be everyone’s favorite subject, graphics.  We are going to start by creating a Sprite.  A Sprite is basically a 2D image with spatial information such as scale, rotation and position.  We are then going to take a closer look at coordinates and viewports, critical concepts to understand.

 

The video version of this tutorial is available here.

 

Creating a Sprite

 

Start by creating a new node in your scene panel.

image

 

Locate and create a “Sprite” node in the resulting dialog:

image

 

Now you need an image file to use as a Sprite.  You could simply copy one into the folder structure of your project at the file system level but in this case I am going to use the Import menu.  Select Import->2D Texture:

image

 

Locate the file ( it doesn’t have to be in your project directory ), and pick where you want it to be located locally, like so:

image

 

Once again, you do not have to import this way, you could have simply copied in the files to your project directory!

 

Ok, now that we have an image, let’s use it with our Sprite.  With the Sprite selected, in the Inspector panel locate Texture, drop it down and select Load.

image

Select your newly imported 2D Texture.

 

Now in your 2D view you will see your sprite positioned centered about the screen origin:

image

 

Navigating the 2D View

 

Now might be a good time to do a quick overview of how the 2D view works.  Let’s start off by looking at the 2D view itself

(Click image to expand)

image

 

This is where you position and manipulate the nodes that make up your world.  As you can see, the X-axis is marked in red and the Y axis is marked in green.  Where the two join, that is the world origin.  In this particular example, the viewport ( blue rectangle ) is in the negative Y and positive X quadrant.  However, child nodes positioning is relative to it’s parent, so to our sprite 0,0 appears to be the top left corner of the screen.

 

The selected object is surrounded by a manipulator cage.  This can be used to easily scale the image, while left clicking and dragging within the cage will move the selected node around.  Remember you can also set positioning information in the Inspector numerically.  You can switch to Rotate mode to rotate an object, objects rotate relative to their center point.  Pan on the other hand allows you to move the camera itself around, enabling you to “pan” through your world.

 

Mouse Controls:

Button Action
Left Mouse Button Click Select clicked node
Left Mouse Button Click + Drag Translate or Rotate selected
Middle Mouse Button Pan the scene
Scroll Wheel Zoom in/out

 

Keyboard Controls

Key Action
Q Select Mode
W Translate/Move Mode
E Rotate Mode
Arrow Keys Move selected, very fine
Shift + Arrow Keys Move selected
ESC Unselect
F1 Help Panel
F Center Camera on Selected
Ctrl + F Frame Camera (Zoom to fit) on Selected
Ctrl + P Expand to selected node’s parent
V (hold) Move pivot point

 

Snapping

 

Some times snapping can be incredibly useful when laying out a scene.  Snapping essentially super imposes a grid over your scene and “snaps” the selected to that grid.  To enable Snapping, simply select Use Snap from the Edit Menu.

image

 

Using Configure Snap you can set the size of each grid in the snapping overlay.   Now your scene will look like this:

image

 

Note, this grid is just there to help you with accurate placement only!  It will not appear when you render your game.  Turn if off again by clicking Use Snap again.  If you are working on a tile based game, snapping can be invaluable.

 

Rotating, Translating and Scaling a Sprite using Code

 

So that covers how to add a Sprite to your world and how to navigate the 2D view, let’s take a quick look at the three most commonly performed actions… translating(moving), scaling and rotating.  The following code does all three:

 
extends Sprite


func _ready():

      #translate to center of the parent, in this case, the viewport
   var newPos = Vector2(self.get_parent().get_rect().size.width/2,self.get_parent().get_rect().size.height/2)
   self.set_pos(newPos)
   
   #rotate by 90 degrees.  set_rot takes radians so we need to convert using in-built function
   self.set_rot(deg2rad(90))
   
   #scale by 2x
   self.set_scale(Vector2(2,2))
   
func _draw():  
   # each frame draw a bounding rect to show boundaries clearer
   self.draw_rect(self.get_item_rect(),Color(0,0,1,0.2))
 

And when you run that, you should see:

image

 

Please note, I quite often use self because I find it adds a bit of clarity and frankly makes code completion easier.  In the above code, “self” is the inherited class “Sprite”.  If you prefer shorter code, you can omit the use of self and it is functionally identical!

 

One important thing to understand is, all of these transformations happened relative to the Sprite’s pivot point, which by default is at it’s center.  If you zoom in on your Sprite object you should be able to see the pivot point:

image

 

It’s the T like cross hair.  This point determines where local transforms occur relative to.  For example, when you say “rotate 90 degrees’ you are rotating 90 degrees around this point.  In the 2D editor, you can move this point ( or more accurately, move the Sprite relative to this point ), by holding the V key down while moving.

 

Here for example I hit W then left click dragged to move the sprite slightly.  Then I held down V and moved the sprite only and not the pivot point, like so:

image

 

Now if I run the same code, you will see that transforms are performed relative to this point instead of the middle:

image

 

This value can also be controlled in the Inspector.  It is called the offset and it is a value relative to the Node’s center point:

image

 

Or you can change the offset in code.  For example, to make the pivot the bottom left corner of the Sprite, you could do the following:

func _ready():

   var newOffset = Vector2(self.get_item_rect().size.width/2, -self.get_item_rect().size.height/2)
   self.set_offset(newOffset)

 

With the following result:

image

 

So, quick summary…  child Nodes are positioned relative to their parents and the top level node is the viewport.  All transformations happen relative to an objects offset, that offset is relative to the objects center which by default is the Node’s midpoint.

 

A Bit about Viewports

 

We should pause a bit to discuss the viewport, it’s a critical concept in graphics.  As you may notice in the earlier screenshots, the Viewport is drawn as a blue rectangle, with it’s top left corner at 0,0 in 3D space.  By default in Godot 2D, the root node is a viewport, which is why we could access it using get_parent() from our sprite node.  So, where exactly are this viewport’s dimensions set?  Good question!

 

image

 

In the Scene menu select Project Settings.  The following dialog appears ( this is where we set default scene earlier ):

image

 

These are your key viewport related settings.  Obviously width and height are what determine the dimensions of your viewport.  There are a few other key settings here too, such as resizable and fullscreen, that determine how the window works on a desktop computer ( these settings are meaningless on mobile devices ).  Orientation on the other hand is important to mobile devices ( landscape vs portrait or lengthwise vs widthwise ) but meaningless on PCs.  stretch_mode and stretch_aspect are useful for dealing with devices of differing resolutions, we will probably cover this in more detail in a separate posting.

 

Viewports are critical as they allow you to work across a number of different devices in different resolutions using the same basic code.

 

The Video Version

 

Programming , ,




Godot Engine Tutorial–Part1: Your First Godot Application

22. enero 2015

 

Welcome to the first coding tutorial of the GameFromScratch.com Godot tutorial series.  We are going to take a quick look at the Godot IDE then jump in and create our first application.  I want to say right up front, I am no Godot expert, so if I may a mistake or you spot something questionable be sure to point it out!  There certainly may be a better or more efficient way of doing things.  There is also a video version of this tutorial available here.  An embedded version is available down below.  The video covers the same topic but may go into a bit more detail.  This first tutorial goes in to a great deal of detail and all subsequent tutorials will assume you’ve read or watched the ones that come before.  As a result, future tutorials will probably be much shorter, or at least, have less screenshots.

 

Alright, without further ado, let’s jump in!

 

First off, you obviously need to have Godot installed before you continue.  If you havent already, go download Godot now.

 

Creating an initial project

 

Now when you run Godot you should see the following window appear:

image

 

If you have an existing project, you can load it here.  Also, if you have downloaded the demos and samples ( direct zip link ) you can load them using the Import button.  In our case however we want to create a new project.  Click the New Project button:

image

 

A new dialog will open.

image

 

Click the Browse button and navigate to the folder you wish to create your project in.  Keep in mind, Godot will not create a folder for your project, so use the Create Folder button should you need one.  Here are the settings I am using:

image

 

Once you have selected your directory, click Open.  Then in the previous dialog, the project name will be set to that of the directory you choose.  Once happy, click Create.

image

 

Now either double click or click select your project and choose Edit

image

 

 

Adding A Node to the World

 

You should now be in the main editor interface.  Let’s start creating our application.  First thing we need to add a text node to our world.  On the right hand side of the screen, make sure the Scene tab is selected, then click the Add/Create a new node button.

image

 

Now in the resulting dialog, locate RichTextLabel then click Create.

image

 

A new node will be added to your scene hierarchy:

image

 

You can rename the node by double clicking, I’ve renamed mine HelloWorldLabel:

image

 

With the Node selected, you can see it’s editable properties in the Inspector window:

image

 

Adding a Script

 

One thing you might notice is there is no property available to set the text!  Time for a bit of scripting.  We need to attach a script to our node.  In the scene panel, select your RichTextLabel node and click the script icon:

image

 

If there isn’t a script attached, this icon will bring up the following dialog:

image

 

Click the .. next to Path.  Now click “Create Folder”, create one called Scripts then click OK.  I should point out, this is completely optional, you could of course just put all the stuff in the root of your application.  You should note that the file system in Godot is entirely relative to the projects root directory.  If you want an asset included in your game, it needs to be copied into this folder or a subfolder to be usable.

image

 

Now name your script.  NOTE!  You have to add the .gd file format, unfortunately Godot wont do it for you.  I called mine “MyButtonScript.gd”.  Once done, click “Save”

image

 

Finally click “Create”

image

 

Script Editing

 

Once you hit Create, you should automatically be brought to the code editing window, like so:

image

 

As you can see, Godot has created a new script that inherits from RichTextLabel.  It implements the _ready() method which is where you do all the creation related logic in your script.  If you come from another language, _ready is not the constructor, it is not the first method to be called.  If you need constructor like behavior, instead use _init().  _ready() is an overrideable function inherited from Node which is the base class of all things that can appear in the Scene.  You will be seeing a lot of Node in the future!

 

As to GDScript itself, it’s a Python-esque scripting language, so if you’ve got some Python experience, you will feel immediately at home.  If you are used to curly brace ( { } ) languages like C++ or Java, the critical thing to understand is it uses newlines in place of curly braces and semi colons.  Don’t worry, while jarring at first, you will quickly get used to it.

 

Now if you want to brush up on GDScript, I recommend the following sources:

 

Additionally, you can access the library reference at any time in the Help tab or by Pressing F1:

image

 

You can also get context sensitive help by pressing Shift + F1 when using the Script tab.

 

Ok… that’s enough language overview, let’s change our code to set the text when our control loads.  Simply replace the code with:

extends RichTextLabel


func _ready():
   self.add_text("Hello World")

 

self is basically the same as this in other languages, which returns a reference to the local object.  In this case, self is a RichTextLabel.  We are calling the method add_text() that we inherited from RichTextLabel, setting the text for our control.

 

Next we want to run our code… but we can’t just yet.  First we need to set our default scene…  oh, and while we are on that topic, we need to save our scene!

 

Setting the Default Scene

 

First let’s save our scene.  Select the Scene menu button and select Save Scene.

image

 

In the resulting dialog, select a location and name.  Be sure to add the scn extension, as Godot requires it and wont do it for you!  Just like scripts, you could save all of your scenes in a scene folder, but in this case I’m just going to save in the root directory using the default name new_scene.scn.  When done click Save.

image

 

Ok, now that we have a scene, we need to set it as the default scene that is run when we load our game.  To do so, click Scene->Project Settings:

image

 

In the resulting dialog, locate main scene, then hit the folder icon to it’s right:

image

 

Select File…

image

 

Select your scene, then click Open.

image

 

Running your application

 

Now you can run your scene.  Simply click the play icon across the top of the application:

image

 

If everything went according to plan, you should see something like this:

image

 

Congratulations, you’ve just created your first Godot game!  Now, let’s make it suck slightly less!

 

To stop your application from running, simply click the Stop icon to the right of the play icon.

 

Editing a Scene Node

 

You may notice our text is across two lines and in the top left corner of the screen.  This is because we didn’t set the size or position.  Both of which can be done in the 2D Scene pane.

 

 

First, switch over to 2D Scene:

image

You can now see our RichTextLabel as a small rectangle at the top left corner:

image

You can use this window to position your various nodes in your scene.  If your node isn’t selected, you can select it by clicking it in the 2D window, or by selecting it from the Scenes panel to your right. 

 

Left click and drag within the selection to move it.  Grab one of the circles from the corner to resize it, like so:

image

 

If you look at the Inspector panel, you will see the values have been updated as you edit them in the scene:

image

You can also enter numeric values in the Inspector window if you prefer more precise control.  Just be sure to hit enter or your changes will not be saved.

 

Loading and changing a Font

 

One question you may have is, how do I change the size of the text?  The answer is, using a font.  You need to create a font for each size of text you want.  Fortunately creating fonts is incredibly simple.  From the Import menu, select Font

image

 

Now you will be able to import an existing font.  If you are running windows, several ttf ( TrueType Font ) files are located in Windows\Fonts.  Please note, these fonts are almost all trademarked and cannot be used without permission in a shipped game!  There are hundreds of open license TTF fonts available for download however.

image

So, open your font, select the size and properties you want to set, then set the Dest Resource filename, making sure to have the .fnt extension.  Finally click Import.

 

Now you need to set your RichTextLabel to use your new font.  With your label selected, in the Inspector window, locate Custom Font, click the drop down and select Load.  Select your newly imported font.

image

 

Now when you run the code, you should see:

image

 

Adding a Timer and wiring events

 

Now let’s add a bit of functionality to our app.  A lot of the logic in Godot is available in included nodes.  Let’s add a timer as a child to our RichTextLabel, that will be called every second, updating a counter on our message.

 

First we need to add a child node.  With our RichTextLabel selected in the Scene panel, click the New Node icon and add a Timer:

image

 

Select Timer and click Create.  Your timer should now appear as a child of your RichTextNode, like so:

image

 

Make sure the Timer is select and in Inspector, set the property AutoStart to on:

image

 

This will create a timer that is called every second and starts running as soon as it’s created.  Now lets connect the timer to our RichTextLabel.  In the Scene panel, with Timer selected, click the Edit Node Connections icon:

image

 

Next select the timeout() connection, which is the callback that will be called each time the timer “ticks”.  Then hit “Connect…”

image

 

In the next dialog, the defaults should be good.  This is wiring a connection between the timer object and the RichTextLabel.  When the connection is fired, it will call the method you are creating, in this case _on_Timer_2_timeout.  When done, click Connect:

image

 

This will automatically add a function to your script file and bring you to the Script editor.  Now let’s change our code slightly.  We are going to add a member variable that counts the number of seconds and update our total each time the timer ticks.  Edit your code like so:

extends RichTextLabel


var count = 0

func _ready():
   self.add_text("Hello World")

func _on_Timer_2_timeout():
   count += 1
   self.clear()
   self.add_text(str("Hello World!  Elapsed seconds = ",count))   

 

As you can see, we add a variable named count with the value 0.  GDScript is “duck typed” in that it infers the type from the value it is given.  So “if it looks like a duck, acts like a duck and quacks like a duck… it’s a duck!”, just applied to variables. 

 

Next you will notice Godot has added the func _on_Timer_2_timeout, which will be called by our timer each time it ticks.  We simply increment our counter, clear the existing value from out label, then add new text.  To concat our string and count variables together we use the built in str() function, which is similar to printf in other languages.

 

Now when your code runs, you will see:

image

 

… and that is the basics of creating an application in Godot.  In the future we will hopefully go in depth on all aspects of using Godot.  If you have any questions or comments, please don’t hesitate to ask!

 

The Video

 

Programming , ,




LibGDX Video Tutorial: Scene2D Grouping and Hit tests

20. enero 2015

 

In this third part of multiple part video tutorial looking at using Scene2D we look at creating Groups for organizing Actors, as well as hit testing, making it possible to select actors available in your scene.  All of the code is included below.  For an HD version of the video click here.

 

 

Groups

package com.gamefromscratch.group;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

public class GroupDemo extends ApplicationAdapter implements InputProcessor {
   Stage stage;

   @Override
   public void create () {
      stage = new Stage(new ScreenViewport());
      Group group =  new Group();

      Image tableImg = new Image(new Texture(Gdx.files.internal("table.png")));
      Image aceImg = new Image(new Texture(Gdx.files.internal("ace.png")));
      Image kingImg = new Image(new Texture(Gdx.files.internal("king.png")));

      tableImg.setName("table");
      aceImg.setName("ace");
      kingImg.setName("king");

      group.addActor(tableImg);
      group.addActor(kingImg);
      group.addActor(aceImg);

      stage.addActor(group);

      kingImg.setPosition(300,150);
      aceImg.setPosition(400,150);

      Gdx.input.setInputProcessor(this);
   }

   @Override
   public void render () {
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      stage.act(Gdx.graphics.getDeltaTime());
      stage.draw();
   }

   @Override
   public boolean keyDown(int keycode) {
      Group group = (Group)stage.getActors().first();
      Image ace = (Image)group.findActor("ace");

      if(keycode == Input.Keys.RIGHT)
         if(Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT))
            ace.setRotation(ace.getRotation() + 1f);
         else
            group.setRotation(group.getRotation() + 1f);

      if(keycode == Input.Keys.LEFT)
         if(Gdx.input.isKeyPressed(Input.Keys.CONTROL_LEFT))
            ace.setRotation(ace.getRotation() -1f);
         else
            group.setRotation(group.getRotation() - 1f);

      if(keycode == Input.Keys.UP)
         group.setColor(group.getColor().r,group.getColor().g,
               group.getColor().b,group.getColor().a + 0.1f );

      if(keycode == Input.Keys.DOWN)
         group.setColor(group.getColor().r,group.getColor().g,
               group.getColor().b,group.getColor().a - 0.1f );

      if(keycode == Input.Keys.NUM_1)
         ace.setZIndex(ace.getZIndex() -1);
      if(keycode == Input.Keys.NUM_2)
         ace.setZIndex(ace.getZIndex() +1);

      return true;
   }

   @Override
   public boolean keyUp(int keycode) {
      return false;
   }

   @Override
   public boolean keyTyped(char character) {
      return false;
   }

   @Override
   public boolean touchDown(int screenX, int screenY, int pointer, int button) {
      Vector2 coord = stage.screenToStageCoordinates(new Vector2((float)screenX,(float)screenY));
      Actor hitActor = stage.hit(coord.x,coord.y,false);

      if(hitActor != null)
         Gdx.app.log("HIT",hitActor.getName());

      return true;
   }

   @Override
   public boolean touchUp(int screenX, int screenY, int pointer, int button) {
      return false;
   }

   @Override
   public boolean touchDragged(int screenX, int screenY, int pointer) {
      return false;
   }

   @Override
   public boolean mouseMoved(int screenX, int screenY) {
      return false;
   }

   @Override
   public boolean scrolled(int amount) {
      return false;
   }
}

Programming , , ,




Have you got the time?

Have you got the time?

20. November 2011

 

 

Handling game time is problem that almost all games have to deal with.  A very good question recently came up in my C++ game from scratch tutorial about why I didn’t normalize the players movements which reminded me of a post on the subject.

 

 

Years ago Shawn Hargreaves of XNA ( and Allegro ) fame blogged about how XNA handles the Update and Render loops.  I simply post it here again because it is one of the most succinct posts I have encountered on the subject.  So, if you are looking into creating a game and need to figure out how to implement the game loop, I recommend you give it a read.

 

By default XNA runs in fixed timestep mode, with a TargetElapsedTime of 60 frames per second. This provides a simple guarantee:

  • We will call your Update method exactly 60 times per second
  • We will call your Draw method whenever we feel like it

 

Digging into exactly what that means, you will realize there are several possible scenarios depending on how long your Update and Draw methods take to execute.

 

The simplest situation is that the total time you spend in Update + Draw is exactly 1/60 of a second. In this case we will call Update, then call Draw, then look at the clock and notice it is time for another Update, then Draw, and so on. Simple!

 

What if your Update + Draw takes less than 1/60 of a second? Also simple. Here we call Update, then call Draw, then look at the clock, notice we have some time left over, so wait around twiddling our thumbs until it is time to call Update again.

 

What if Update + Draw takes longer than 1/60 of a second? This is where things get complicated. There are many reasons why this could happen:

 

  1. The computer might be slightly too slow to run the game at the desired speed.
  2. Or the computer might be way too slow to run the game at the desired speed!
  3. The computer might be basically fast enough, but this particular frame might have taken an unusually long time for some reason. Perhaps there were too many explosions on screen, or the game had to load a new texture, or there was a garbage collection.
  4. You could have paused the program in the debugger.

 

We do the same thing in response to all four causes of slowness:

  • Set GameTime.IsRunningSlowly to true.
  • Call Update extra times (without calling Draw) until we catch up.
  • If things are getting ridiculous and we are too far behind, we just give up.

If you think about how this algorithm deals with the four possible causes of slowdown I listed above, you'll see it handles them all rather well:

  1. Even if the computer is too slow to run Update + Draw inside a single frame, chances are that Update + Update + Draw will fit into two frames. The game may look a little jerky, but it will still play correctly. If the programmer is particularly smart they might even notice that we set IsRunningSlowly, and automatically reduce detail or turn off special effects to speed things up.
  2. If the computer is way too slow (ie. if the Update method alone is too slow to fit into a single frame) there isn't really much we can do, other than set IsRunningSlowly, cross our fingers, and hope the game might do something clever in response to that. Most of the time, though, if you find yourself in this situation you just need a faster computer!
  3. If a particular frame happens to take unusually long, we automatically call Update some extra times to catch up, after which everything carries on as normal. The player may notice a slight glitch, but we automatically correct for this to minimize the impact.
  4. Pausing in the debugger will leave the game a long way behind where the clock says it should be, so our algorithm will give up, accept that it has lost some time, and continue running smoothly from the time execution was resumed.

 

 

Shawn’s blog in general is a very good read, but this this post in particular is one that I seem to keep coming back to.

 

For the record, Pang from the C++ tutorial does not gracefully handle hitting a breakpoint ( it adds a layer of unwanted complexity for learning purposes ), so will do downright stupid things when it hits a breakpoint causing it to pause for a while.  I believe on the next frame it will cause your movement to be really really really far.  It would be as simple as adding if(elapsedTime > someReallyBigValue) startTimeOver() if you really wanted to fix this.

 

 

Sorry for digging up the past, now back to your regular broadcast!

Programming , ,







blog comments powered by Disqus
I want to be a game developer... now what?

I want to be a game developer... now what?

4. August 2011

 

With people looking to get into game development the same questions come up over and over, so I’ve opted to put my thoughts on the subject in one place and to compile a list of resources for new developers.

 

Those questions?

“I want to learn game programming, what language should I use?”

“Should I use an engine, or create my own?”

“What library/tools should I use"?”

“Now what?”

 

I will try to address all of these questions and more in the following post.

 

For those of you that like skipping ahead to the last page in a novel, these links are for you!

 

 

… the C++ question.

 

Let me get the 800lb gorilla out of the way first of all.  C++.  This is one of the most controversial and repetitious questions of all.  New developers hear from other developers that C++ “is what the pros use” and therefore want to use that.  To make matters even worse, people answering the questions are often new developers as well and will recommend what they know thus pushing people to use a language they probably shouldn’t.  Frankly, if you have only ever used a single language, you really shouldn’t be answering these kinds of questions!

 

Alright, back to the whole C++ question.  Should you start learning with C++?  NO.   See, no maybe, no wishy washy answer or caveats, it’s simple, C++ is an epically stupid language to start with.  It’s about the same as starting to learn math by starting with advanced calculus.  Again, dumb.  If you are going to listen to a single piece of advice I give, it’s DO NOT START WITH C++.  I know, of course, that you are going to completely disregard this advice and start with C++, but in 3 or 4 years when you’ve got the scars and trauma from ignoring my advice, I’m going to smugly *tisk tisk* and give you my best “I told you so!”.  I will offer another piece of advice while I am at it… anyone that recommends you start with C++, in the future ignore their advice!

 

Don’t get me wrong, I totally understand why you want to go with C++, I’m just as guilty.  Recently I purchased a set of golf clubs and I’m a horrifically meh golfer, but I got a set of “blades” cause that’s what the pro’s use.  The gotcha?  I’m no pro golfer, and my god did these golf clubs totally ruined my golf game.  Sometimes using what the pros use isn’t the right thing to do.  Alright, off that tangent.

 

Again, these are just my opinions ( and those of the vast majority of people that went down this road themselves! ) and I know you are going to start with C++ anyways, but don’t say I didn’t warn you, because you are making a really stupid mistake.

 

Now, if you did in fact make the decision to go ahead with C++, for the love of all that is holy, DO NOT USE DevC++.  It’s old, unsupported and a vastly inferior choice on every measurable level.  Don’t worry, I’ll cover the options off later.

 

Programming is… programming

 

This one is a bit depressing but completely true.  There is nothing really magical about Game Programming.  It’s programming, pure and simple.  In my professional life, I’ve done game programming, tools programming, desktop app development, mobile phone apps, web development, enterprise development and even created an Internet startup.  Through all of that, the programming, though for vastly different purposes was almost always the same.  Hell, the most advanced ( and difficult ) code I’ve ever written was in Javascript!  Now the biggest difference with game developing… math, yeah, you are going to have to learn math.

 

Anyways… why do I bring this up?  Simple, before you can program games, you need to be able to program.  I know that sounds horribly obvious but you would be amazed by how often people jump straight in to game programming without learning the basics first.  That said, my very first line of code was in the attempt to create a game.  I still remember it to this day:

10 PRINT “WHAT IS YOUR NAME?”

All this really means is, the very first thing you are going to have to learn is the basics of programming.  No worries though, I’ll cover that later too.

 

 

The most important thing is…

 

Do something.  Really, the most important thing you can do is start writing code, start learning, jump in.  All the planning, dreaming and forming of teams is all fun and such, but the most important thing you can do is, um… do.  Jump in, learn, make mistakes, the experience will be invaluable.

 

Your first game won’t be good.  Your second game won’t be much better.  But if you finish a single game, you’ve done better than 95% of people that came before you.  Don’t plan an MMO, it’s way beyond you, even with a team of a few hundred people.  Hell, aiming much higher than Pong is setting yourself up for failure.  Pick something small and execute.  Again, there is a 99.99% chance your game isn’t going to be published, so approach it as the learning experience it is.

 

Nothing frustrates new developers more than the lack of progress.  This is why small, doable goals are so important.  Nothing motivates like success!

 

 

Should I use an engine or create my own?

 

Assuming you are a new developer, frankly, this is a premature question.  Grasp the basics of programming before you even think about using or worse, creating an engine.  Otherwise you are doubling your workload, as you learn both a language AND an engine.  As a new learner, you should be minimizing the number of subjects you need to study at once, as you can quickly get overwhelmed if you try to learn everything at once.

 

Now once you’ve got the gist of things and are starting out creating a new game, this is a very valid question.  One thing to keep in mind, an engine like UDK or Unity are tens or hundreds of thousands of man hours worth of work… do you want to replicate that effort?  Generally, especially for a small developer, you are best off to use an engine, doubly so if trying to make a commercial quality product.

 

That said, if you are looking at it as a learning exercise… have at it!  You will learn a ton of interesting and useful things working on a engine of your own.  Generally, if it’s a learning exercise, it totally makes sense to do things that make no sense!

 

The most important take-away from this section is, if you are new to development, put a bit of time into learning programming, then ask this question later!

 

 

What libraries and tools should I use?

 

This one all comes down to the language you pick.   I’ll break it down by language in just a few minutes.

 

 

What are my language choices?

 

Alright, this one is a bit tricky, as frankly there are literally hundreds of programming languages, but I will cover off the most popular ones.

 

C++ – this is the language you shouldn’t pick, but no doubt will.

 

It’s pros…  you can get close to the metal, it’s the pro choice, lots of 3rd party commercial and free libraries and it is well supported across platforms.

 

It’s cons?  Just about everything else.  It takes 10x as many lines of code to do simple things, it’s like juggling live hand grenades safety wise, it’s compilation process is primitive and unwieldy, it’s syntax is painful, it’s learning curve is steep and it’s standard libraries are awful.

 

Learning difficulty: hard

 

EDIT: –8/16/2011 To be honest, I have been overly hard on C++.  Don’t get me wrong, this does not mean that I am endorsing it for new developers, that is still a seriously bad idea!  However, with the rise of iPhone ( which is Objective-C based, but supports C++ ) and Android ( which is Java based, but also supports C++ ) as gaming platforms, C++’s popularity is on the rise.

 

C -  See C++, which is a superset of C.  There are reasons to use just C and frankly it’s a bit easier to come to grips with, but it is like taking a trip back to the stone ages.

 

Learning difficulty: medium

 

C# – full disclosure, all things being equal, this is the language I go to.  Generally, this is the non-C++ language most people will recommend and for good reason.  C# is a modern derivative of C++, in that it was based on C++ ( and not Java as commonly held ).

 

The pros? EXCELLENT standard libraries. Probably the best on any platform I’ve ever used. So things like working over the network, manipulating strings, loading files, etc… are by far easier than C++.  Oh, and LINQ, generics, anonymous methods and various other “new” language features are pretty great.

 

It’s cons?  Probably the biggest is, it’s tied to Microsoft and that makes many people uncomfortable.  As a result, it’s best implementation is on MS platforms, although it is available on OS/X, iOS, Android and Linux, you do have to jump through a few more hoops outside of MS-land.  Next up, it’s garbage collected, meaning you don’t implicitly allocate memory.  Finally, in some regards, it can be slower than C++, although I think this point is way over blown these days.

 

Learning difficulty: medium

 

Java – Java is a tricky one to write about, because of my C# bias.  I used Java before C# came around and I could see how it was more productive than C++ and appreciated the encompassing libraries, especially as I was moving over from C++ at a time the Standard Template Library was anything but standard…  that said, since C# came along, it feels to me as a superior language in just about every way.

 

The pros?  The ecosystem is massive, the tools and library support are legion.  There are nine ways of doing everything in Java, and the number of free tools ( Eclipse, NetBeans, Ant, etc… ) are truly staggering.  Language wise, it’s much like C#, libraries are much more capable than C++ and the language is much less likely to bite you in the ass if you make a slight mistake.  Also, if you are doing Android development, well until very recently ( with added C++ support ) it was the only game in town.

 

The cons?  Java just has this way of annoying you, of getting in your way because it thinks it knows better than you.  Parts of the language are kludgy, overly verbose and again… just annoying.  In recent years, it has been evolving much less elegantly than C#, so the newer language features seem like half assed poorly implemented ugly step children compared to C# ( and in some regards, C++ ).  Also, Java is the language of academics and enterprises and it shows… so many things are so overwhelmingly OVER engineered as to drive you insane, as I said earlier, there are nine ways of doing everything, but 5 of those ways are outdated, 3 are awful and figuring out what the good choice is, is up to you.  Finally game library selection is pretty limited.

 

Oh, and Oracle own them now… of all the tech companies in the world I would want in charge of my language of choice, Oracle sure as hell wouldn’t be the company I would pick.  For people that think Microsoft are the devil… they don’t know Oracle!  Their throwing around lawsuits left, right and center ( including Google/Android ) would not make me feel good about things.

 

Learning difficulty: medium (*)

(*) – figuring out WHAT to use, from the hundreds of libraries, deprecated features, tools, etc..  is overwhelming and is probably going to be as big a challenge for a new developer as learning the language itself

 

 

Visual Basic – to be honest, since .NET, this language effectively died.  Using VB6 is frankly just too outdated to bother with these days, which is a bit of a shame, as it filled a very nice niche that hasn’t completely been filled.  Now, VB.net is basically C# with a VB’ish skin applied.  I am sure VB.net developers will disagree, but… they are wrong. Winking smile

 

Delphi – was a time I would highly recommend this language, but this haven't progressed well for Delphi. Ironically, the guy that invented C# was the guy behind Delphi.  Support just isn’t there, which is a shame as the language is very friendly to newer developers.

 

LUA/Python/Ruby – In all honesty, I’ve only really dabbled with these 3 languages and while all 3 are ( and commercially have been ) good languages for embedding within a game, only Python really has a really solid game development community built around it, so is probably the best recommendation for new developers.  All 3 languages should definitely be on your radar.  My experience is very limited in all regards, so I don’t really feel comfortable making a suggestion one way or the other.  If you are an advocate of any of these languages and want to write a section on them, send it to me for inclusion!

EDIT: If you are interested in Lua, be sure to check out Battle of the Lua game engines for more details.

 

One big advantage to all three of these languages is you can program them interactively, which means type some code and see a result.  When you are just trying to figure things out, that’s pretty powerful!  Later on in this post, I will mostly just cover Python, the most popular of the three, especially in regards to game programming.  There is also Iron Python which is an implementation of Python on the .NET platform, which means you get all the libraries available to C# and VB.net.

 

C++.NET – On the topic of .NET languages, C++ also made a “special” version of C++, with additional keywords to make it compatible with .NET libraries and a mode that makes memory management automatic.  That said, it was a kind screwy-hackish implementation and nobody really took to it, so you can probably ignore C++.NET completely.  The only real use case I can think of is, if you only know C++ syntax and want to do GUI development with WinForms, this may be the way to go.  That said, that’s a pretty damned minor use case!

 

JavaScript – I don’t know how this little language managed to fit into every niche, but damned if it doesn’t!  Most people think of JavaScript as a web scripting language and easily that is it’s most common use, but this language ends up being used just about everywhere.  It’s worth learning, as it is really everywhere, and although beginning life as a bit of a hack, it has proven itself capable again and again.  Not my favorite language to work in, but not the worse by a long shot!  If a new programming paradigm comes along, you can bet a JavaScript implementation will come along sooner then later!  Given HTML5 and Windows 8, Javascript is only going to get more popular in the future, although I’m not really sure this is a good thing.  Javascript is a prototype based language.  All told, Javascript has pretty good library support when it comes to games, and is one of the languages available when using Unity.

EDIT: If you are interested in JavaScript, be sure to check out the list of JavaScript gamedev libraries as well as my Cocos2D-html tutorials.  I also have a pair of JavaScript book recommendations.

 

Assembly – If you as a beginner pick assembly in this day and age, you did something wrong, extremely wrong! Choosing assembly as your first language makes C++ look like a wonderful choice!  That said, this is about as close to the metal as you can reasonably get.  In this age of i7 quad core processors though, getting close to that metal is a pretty stupid thing to do.  At some point Assembly may become important to you, but I highly doubt it.  Until it does, pretend it doesn’t exist.

 

The Rest  - I hope I didn’t miss your language of choice, as there’s Objective-C, D, F#, CAML, Smalltalk, LISP, Perl, PHP, Haskel, Pascal and a few hundred other languages available.  Many of them are domain or platform specific languages, or have fairly poor game library support.  ObjectiveC is gaining in popularity based on it being the main language of iOS platforms, but outside that world it is virtually unknown and frankly… I hate it.  I don’t recommend against any of these languages, but none are really well suited or very popular for game development.

 

 

But I’m an artist, where do I start?

 

In that case, you should probably start here.  Pick out an application and go with it.  Many of the programs on that list have free/demo versions available.  Also, the GFS list of applications used is mostly full of free applications used to create games.

 

 

So I have this great idea for an MMO…

 

Alright, back to being negative again.  You can’t create an MMO.  You and 10 of your best friends can’t create an MMO, unless of course your 10 friends are all A-list developers and even then frankly you still can’t afford to create an MMO.  Got a few million dollars?  No?  Then drop it, an MMO isn’t the way to go.  Now, some day you may be able to work on a Warcraft killer, but as your first project… well frankly that’s like trying to find a cure for cancer in your high school chemistry class.  Aim lower, much much lower.

 

 

Ok, I’ve decided to go ahead with…

 

 

 

 

C++ is the language for me!

 

Egads, you just wont listen will you…  all right, we all make this mistake when we start out.  If you insist on going the C++ route, learn the language first, using the following recommended tools and libraries.

 

Freely available resources for learning the language ( Books and Tutorials )

 

Once you get a bit more advanced, check out

 

I will fill this area in over time.  Much of the free resources are terrible, or outdated. If you have a good suggestion, email me or comment below and I will add it.

 

Recommended books ( Not free )

 

The C++ Programming Language

This is the book by the language creator himself.  It is considered the language bible of sorts.  It may not be the best book to learn on, but it is a book every C++ programmer should have on their bookshelf.

 

C++ How to Program

Currently in it’s 8th edition, this is a pretty good first book for a programmer to learn with.  It covers pretty much all of the language features and even covers Boost libraries, which is a valuable addition.  Keep in mind, this book, like most introductory texts, does not cover GUI programming of any form.

 

C++ Without Fear: A Beginner's Guide That Makes You Feel Smart (2nd Edition)

This one I recommend with a caveat.  It is probably the single best “conversational” introductory C++ texts out there.  It is very approachable and the pacing is quite good.  Nothing is implemented before it’s explained which is very nice.  That said, some things are wrong or outdated, occasionally teach you “The C way” of doing stuff instead of the C++ way.  Finally, the author recommends DevC++, which is really really really bad.  Those flaw aside, if you find all other texts to dry, confusing or technical, you may want to check this one out.  Again, no GUI coverage and no Boost, but many of the newer language features are covered, plus it spends a couple chapters at the end implementing more full solutions, which is a good thing.

 

Beginning C++Through Game Programming 3rd Edition

No doubt you have seen this title and in your future career as a C++ developer AND a game developer, this sounds about perfect.  It isn’t, but it is not bad.  Lets put this out there right away, this won’t teach you how to program games, but what it will do is teach you to program C++.  As an introduction to C++ text, it’s not as good as the previous two books.  As a game programming text it’s all but useless.  So why am I recommending it?  It’s a decent introduction to C++ programming that uses simple games for all of the demonstrations.  So, instead of fairly abstract or contrived examples you see in other texts, all the examples are game related.  For example, pointers and references are taught by creating a Tic Tac Toe game.  Many people will find this a heck of a lot easier to wrap their head around than many examples in other books.

 

Effective C++

This is not a beginner text.  This is an old text, outdated even as it doesn’t cover the latest C++ standard. Heck, it’s 6 years old!  So why am I recommending it?  Simple, every good C++ programmer owns this book.  Once you grasp the basics of the language, buy this book and it will make you a much better C++ programmer.  Seriously.  Hopefully Scott is working on a 4th edition as we speak.  On the bright side, it’s 6 years old so you should be able to find it cheaply.  In addition to Stroustrup’s book, this is the C++ bible.

 

Tools

 

When it comes to tools, the choices are pretty clear with C++

 

Of the two, I would recommend Visual C++ personally, unless of course you aren’t running Windows.  There are a few other options, but they all require a bit more work or installing plugins, but I will list them for completeness

  •  
    • KDevelop a linux based IDE, heavily copied from Visual Studio in style
    • Eclipse IDE for C++ a cross platform ( Linux, Win, Mac) IDE, mainly for Java, but supports C++
    • XCode Apple’s IDE, supports C++ but is obviously Mac OS only
    • Netbeans for C++  NetBeans is another Java IDE that supports C++.  It’s actually surprisingly new user friendly but now that Oracle is in charge, expect that to end!

 

Well, that’s about it.  If you are working on Windows, I see no reason to use anything but Visual C++ personally.  A number of tutorials out there will recommend Dev C++… DON’T under any circumstances use DevC++, it’s old, unsupported, buggy and has little to no advantages over the other choices.  It was popular at the time because back then, there was no freely available C++ IDE, times have changed.

 

Oh, and just to be thorough, there are also Emacs and Vi(m) which are actually just really powerful text editors that you then call out to the likes of Gcc or the MinGW compiler.  I mostly just mention these for completeness; as if I didn’t some guy with a beard and plaid shirt would no doubt scold me over the omission.  In no way do I recommend a new developer start with any of these items!

 

One last point I think should be made here, your choice of IDE has absolutely no affect on how cross platform your code is!  Code ( properly ) written in Visual C++ can be later compiled for Mac OS and Linux, for example.

 

Gaming related stuff

 

So, you are here for game programming advice and all I’ve talked about is C++, now I will rectify that.  First you need to decide if you are working in 2D or 3D.  Just starting out, I highly recommend sticking to 2D for now ( or stick to console apps until you get the gist of the language ), yet once you decide to make the graphical plunge, there are 3 major ( and a few thousand other! ) 2D graphic libraries out there.  I know this sounds like a cop-out, but all three are equally good, so you can’t really make a mistake here.

 

2D Libraries

 

SDL - SimpleDirect Media Layer

It’s beginner friendly, simple ( relatively ), cross platform, well supported and is used to make commercially shipping products ( like the recently release Dungeons of Dredmore ).  It handles just about every aspect of creating a 2D game, graphics, sound, loading files, networking… you name it.  It is very much a C based library.  You can use it from C++ without effort, just don’t expect any object oriented features.

 

Allegro

This is the library ( and Fastgraf ) I started out using many many many years ago.  It was originally written for the Atari ST and I am simply floored that it is still around and in active development.  That said, it was good then and it is good now.  Interesting trivia point, the guy behind Allegro way back in the early 90s, went on to become one of the main programmers behind XNA.  Anyways, this much like SDL, covers just about everything you would need for 2D game programming. Also like SDL, it’s very much a C library.

 

SFML - Simple and Fast Media Library

The new kid on the block, and frankly, I have zero personal experience with this library.  Like the other two, it handles just about everything you would need to implement a 2D game.  Unlike the others, this is an object oriented library ( C++ ).  A quick look at the classes and it looks like a very modern and clean design. On that level alone, I would probably go this route if I was starting out today.  It is event driven, which is a very handy thing ( and something Allegro is moving towards ), which should make your game structure easier to implement.

 

3D Libraries

 

If you are just learning, you probably shouldn’t be working in 3D right now, yet here are the primary libraries in use today.

 

Open GL

Originally developed by Silicon Graphics in the early 90s, this is the grand daddy of 3D APIs.  It’s biggest advantage is it’s cross platform nature, as OpenGL is everywhere.  This is especially true on mobile devices like Android and iPhone, which both implement a stripped down version of Open GL called OpenGL ES.  You can view the getting started guide here. If you prefer in book form the OpenGL Programming Guide ( Red Book ) has long be viewed as “The OpenGL Bible”, the one book all OpenGL programmers should own.  That said, in recent years OpenGL has changed quite a bit and the old cruft and obsolete instructions haven’t been pruned out of this book yet. The NeHe tutorials have long been the goto resource for new OpenGL developers, although in some ways they suffer the same problem as the Red Book, time waits for no docs!

 

DirectX

This is Microsoft’s primary game SDK ( Software Development Kit ) for creating games on Windows and Xbox using C++ ( not be confused with XNA ).  Unlike OpenGL, DirectX also supports Input and Sound.  Microsoft has provided some fairly good tutorials.  One thing to be aware of, DirectX 10 and 11 require Vista or higher, so no XP support!  That said, DirectX is no doubt the most popular SDK to use for commercial Windows games.  Beginning Game Programming is probably the best beginner friendly DirectX book, but keep in mind, you do need to understand C++ already!

 

Ogre 3D

Ogre3D sits in a weird spot.  It is not a full game engine, but it is not like OpenGL or DirectX either.  In fact OGRE uses both.  Ogre is a 3D rendering engine.  Written in very clean object oriented C++,  Ogre handles a number of tasks that neither DirectX or OpenGL do, like a scene graph ( the data structure your world is stored in ), importers for almost all major 3D modeling applications, landscapes, LOD ( level of detail ) support, etc.  If you are using DirectX or OpenGL to create a 3D game, these are all things you would have to write yourself.  Ogre is cross platform and has been used to create a number of published games.  The have a pretty good manual online.  There are also a beginner and a pro book available, neither of which I have read though.

 

Other Libraries

 

ODE - Open Dynamics Engine

nVidia PhysX

Are two freely available physics engines for accurately modeling real world physics in your game.  ODE is open sourced as well.  There is also Havok which is included in Unreal (UDK), but it’s licensing isn’t so straight forward.

 

Box2D

A physics engine for 2D games.  Free, powerful and quite a bit easier than working in 3D.

 

Boost

Boost is the future of C++, 10 of the boost libraries are already part of the C++ standard, with more coming soon.  Boost libraries perform dozens of common tasks and make up for a giant flaw in the C++ language ( the standard libraries are crap compared to other languages ).  That said, they aren’t the easiest to learn and even harder to understand.  Many Boost programmers are amongst the best in the field, and it shows. There are books available for Boost too, although the website actually has extremely good documentation for the majority of the libraries.

 

Game Engines

 

I will cover this off in a different post, as Engines aren’t really tied to a particular language.  For example, the popular Unreal engine, is very much written and programmable in C++, but also can be programmed in UnrealScript.  Unity is primarily C# based, but can be extended with C++ and scripting with Javascript and Boo.  Panda can be scripted in Python but can also be programmed in C++.  Engines don’t really fit in by language.

 

Still too many choices, tell me exactly what to do!

 

Alright, keep in mind this is all entirely my opinion, but as a game developer learning C++ you should:

 

Go here to download and install Visual C++ Express.

Take the guided tour that will introduce you to using the IDE and language.

At this point I would recommend buying a C++ book such as this one.  There are a ton of resources on the web, but many are outdated or wrong and the sheer volume is overwhelming. Having at least one good beginners guide is ideal.

Go through that book and do some basic exercise, create a few console applications and get a feel for the language.

Now go and download SFML ( Visual Studio 2008 ) <- until 2010 update occurs.

Run through the SFML configuration/starting tutorial.

Now start running through the other tutorials.

At this point, you should be ready to consider making a game.  Start with something small, like creating a PacMan clone or something similar.

Now start making more complex games, or using or creating a game engine.

Congratulations, if you got to this point, you are now a game programmer!

 

EDIT: This site now has a complete game from scratch using SFML tutorial available.  You need to have the basics of C++ down, but it will hopefully teach you quite a bit.  It is a good place to go once you’ve run through a couple C++ tutorials or a few chapters of a book.

 

 

 

 

 

 

C# is the language for me!

 

The C# section is a lot easier to right than C++, as it’s a newer language, there are fewer tools and one library dominates the game ecosystem.

 

Freely available resources for learning the language ( Books and Tutorials )

 

MSDN Visual C# Developer Center

One really nice thing about working with Microsoft technologies is Microsoft know documentation!  The number of tutorials and how to videos they make available is extremely vast.   This link alone should have everything you need to know to get up and running.  They also have more resources, including this introduction video available at the Beginner Developer Learning Center.  Once you are ready to move on to XNA give this tutorial a shot.  To be honest, they probably provide everything you need to succeed.

C# Essentials

A free e-book, covers the basics of C# pretty well.  A bit dated but still free.  Nicely many of the changes to C# over its evolution are complementary to the “old ways”, so not as many ways of doing things have been deprecated.

 

Rob Miles' C# Yellow Book

A free book from a professor at the University of Hull about learning to program using C#.  It’s actually pretty good and he updates annually.  Very good first step for a C# developer that doesn’t want to spend money.

 

Introduction to Programming Through Game Development Using Microsoft XNA Game Studio

Rob Miles also made this ebook available for free download as well.  It is all about learning how to program by creating games in XNA.  Personally I think this is kinda a bad idea, but the price is right!  Definitely give it a shot, it is a very thorough text and if it works for you, you will be up and “doing the fun stuff” at a much quicker pace.  It does cover just about everything you need to know to program a full featured 2D game.

Gang of Four Design Patterns

Truth is, this site is probably not going to make a lick of sense for you starting out, but bookmark it and come back every once in a while.  One of the best sites on design patterns, and design patterns are “a very good thing to know”™.  They will change the way you code, for the better.

 

Recommended books ( Not free )

 

 

.C# Programming Language 4th Edition ( Covering C# 4.0 )

One of the primary writers of this book is the language author.  Just like in C++, with C# I recommend the book by the language creator.  Unlike the C++ equivalent, this book is more beginner friendly although still comprehensive.  As a C# developer, this is probably “the bible” of C# books.  Unlike C++, C# has changed extensively in a short period of time, so be sure you get a copy covering version 4!

 

Headfirst C# 2nd edition

This one is a bit different, as the name implies, it just sorta jumps in and documents as it goes.  Instead of working on console applications, you are actually develop real GUI apps right from the start.  For those that learn by doing, this is an excellent book.  It is very conversational and easy to read, although a little chaotic in its formatting ( check out the preview and you will see what I mean! ).  If this is how you learn, this book will be godsend, but I know it is not for everyone!

 

C# 4 In A Nutshell

I just love this series of books.  These books are very concise and cover the entire language, but can also make for a useful reference well after you’ve got the hang of things.  The downside to this conciseness is, there is not a lot of hand holding, it covers the language only ( no talk of the IDE for example ) and there is no continuity of examples to “tie it all together”.  It describes a language feature, gives an example and moves on.  This may or may not work for you, especially if you have no prior language experience.

 

 

I looked at a number of learn XNA programming books to see if any of them were suitable to a new developer including Learning XNA 4, Microsoft XNA Game Studio 4.0: Learn Programming Now! and Beginning XNA Game Programming and none do a good job of covering the C# language.  My recommendation is to get a grasp of the language basics from another source before jumping into a XNA specific book.

 

Tools

 

This area should be extremely straight forward, as there are really only two ideal IDEs for C# development, Visual C# and Monodevelop.  That said, Microsoft have muddied the waters by letting their marketing department get involved, so you have Visual C#, XNA Game Studio and now Game Studio is included as part of Windows Phone Development Tools… yeah, that makes a ton of sense to me too!  Just to add to the stupidity, Windows Phone Development Tools ( just rolls off the tongue… ) only works on Vista and Windows 7, so if you are running Windows XP, you need to download the standalone version.

 

So…

Visual C# / GameStudio instructions

If you are running Windows 7 or Vista, download this or if you are interested in running the newest and beta-est download this.

 

However, if you are running Windows XP download this. ( Direct Link to EXE )

 

MonoDevelop / SharpDevelop instructions

Finally, if you are running on non-Microsoft platform or for some reason don’t want to use Visual C#, MonoDevelop is the IDE of choice.  ( Download Page )

 

There is also SharpDevelop if MonoDevelop isn’t for you.  ( Download Page ).  It is Windows only however.

 

One key thing to note, if you are working with and want full support for XNA, you will need to use GameStudio/Windows Phone Development Tools. A

 

 

Gaming related stuff

 

XNA

 

Instead of repeating this one in the 2D and 3D libraries section, I’ll just address it first.  XNA is well regarded and is seen as a big reason to use C# and for good reason, it really is a wonderful development environment.  At the most basic level, XNA is a C# friendly version of Direct X, but that is selling it far too short.

XNA handles most of the common tasks for game development.  2D graphics, 3D graphics, audio, asset loading and the content pipeline.  It is also a hell of a lot easier to get up to speed on than OpenGL or DirectX.  The downside is, it is supported on Windows, Xbox and ( a subset) on Windows Phone 7. A number of released games, including every Indy game on Xbox, have been released using XNA tools.

There are however projects to port XNA to other platforms or like this one.

For more details check it out.

 

2D Libraries

 

SDL.Net

It’s SDL, the C++ library, with C# bindings. Therefore it is capable of 2D graphics, sound, loading files, fonts, etc… just like SDL.  C# specific documentation can be found here.

 

3D Libraries

 

OpenTK

OpenTK is a wrapper around OpenGL ( 3d graphics ) , OpenCL ( allows code to run across CPU and GPU’s) and OpenAL ( audio ).  If you want to do cross platform 3D, OpenTK is the way to go.

 

SlimDX

This is a wrapper around all things DirectX 9/11.  So, if for some reason you don’t want to use XNA, you can use full Direct X.  For a beginner, there is probably very little reason, as XNA is a fair bit easier to use.

 

Tao

Tao brings OpenGL ( 3D Graphics ), OpenAL ( audio), ODE ( physics ) and a number of other libraries to C#. Sadly, it’s mostly been abandoned so OpenTK is probably a better bet at this point.

 

Axiom

This is a port of OGRE 3D to .NET.  Sadly it too doesn’t appear to be that active anymore.

 

Other Libraries

 

Box2D.NET

Box2D physics library, for .NET. A pretty impressive 2D only physics library.

 

BEPU Physics

Is a full 3D physics library for .NET that also support Xbox360 and Windows Phone 7.  In the developers words “It’s fast and has a bunch of cool features like constraints, terrain, static and instanced meshes, continuous collision detection, custom collision rules, vehicles, easy multithreading, yadda yadda yadda.”.

 

Still too many choices, tell me exactly what to do!

 

Alright, due to it’s youth and the excellence of XNA, this is an easy one to write.

 

First off, go and download the newest XNA Gamestudio.

Watch some of the Microsoft training materials.

Create a few console apps, get a feeling for the language. It would be a very good idea to buy a good introductory book right now if you can afford it, run through their examples.

Now it’s time to get your feet wet with XNA. Run through the 2D game tutorial.

Use XNA to create all manner of simple 2D then 3D games.

Congrats, you are now a game programmer!

 

 

 

 

 

 

 

 

Java is the language for me!

 

Freely available resources for learning the language ( Books and Tutorials )

 

Oracle's Tutorial Site

Sun ( and now Oracle ) put together a very comprehensive set of tutorials for learning the language.  Start with the getting started tutorials and go from there.  You can download the whole wack of them for offline reading here.

 

IBM Tutorials

IBM also has a huge list of Java tutorials available, running the gamut of subjects, some of which would really surprise you coming from big blue!  Keeping in mind, IBM was the source of Eclipse, they are probably the second most involved company in the Java ecosystem, aside from Oracle.  Lots of their tutorials are very enterprise oriented, but you will find many that are useful.  Here is their introductory tutorial, but perhaps coolest of all, they have a tutorial built around a game for teaching the language!  IBM really is a weird beast. Smile

 

Thinking In Java 3rd Edition

It’s a bit out dated ( 2002 ) at this point in time.  It is however a book that is very easy to read, following along and will help you learn the language.  You will need other resources, but this book is a very good guide down the path of learning Java.  Plus the whole free thing is very nice!

 

 

Recommended books ( Not free )

 

 

The Java Programming Language ( Forth Edition )

In keeping with my trend of recommending books by the language creator, this book is co-authored by James Gosling.  It is a comprehensive and relatively beginner friendly introduction to the Java programming language.  Unfortunately, it is getting a bit old, and only covers up to J2SE 5, while J2SE 6 is the most current release.  That said, this shouldn’t be much of a handicap.

 

Head First Java

This book is an easy read, incredibly easy.  Dare I say it, it is actually kind of fun.  I already knew Java to a degree and didn’t really need a “beginners book”, but I noticed this one was always trending in Safari’s top 10 list ( out of over 14K books! ) and couldn’t figure out why so I gave it a read.  It was a genuinely amusing book to read, it did a very good job of getting the technical information across in a way that didn’t feel so dry and stuffy like many texts do.  It may not be your style, but you should definitely check it out!  Amazon offers a “look inside” preview, and I suggest you do.

 

Java How To Program 9th Edition

A VERY comprehensive introduction to Java at a whopping 1500 pages, it also comes with a whopping price tag.  It is however the text of choice for many java courses and it covers pretty much all of the language aspects, including many common libraries and frameworks, which to you as a game programmer may not matter.  Again though, the price tag is a kick in the teeth.

 

Effective Java

This is not a beginners book, in that it won’t teach you the language basics.  This book, hands down, will make you a better Java programmer.  Once you’ve mastered the basics of the language, pick this up!

“I sure wish I had this book ten years ago. Some might think that I don’t need any Java books, but I need this one.”

Who said that about Effective Java?  James Gosling… the language creator!  I simply cannot think of higher praise.

 

Tools

 

This is an area where Java has always got it right, tools.  There over the years have been a number of great IDEs for Java, but three have really jumped to the forefront and fortunately all 3 are available freely.

 

Java SDK

When developing in Java, your first step is to install the SDK ( software development kit ).  In some cases it may be included in your IDE’s install, but it is safest to start here.  Just like all things Java there are bewildering number of options and flavors.  There is Java SE ( standard edition ), EE ( Enterprise Edition ), ME ( Micro Edition ), Embedded as well as various versions for very specific device devices and profiles.  Hell, even the Java used for Android development is completely different!  ( And frankly isn’t exactly Java, but that’s neither here nor there ).  Long story short though, unless you know a reason not to, what you want is Java SE Development Kit 7, at least as of writing it is.  You will also see this referred to as the JDK or as J2SE on occasion because, well… it’s Java.  You will start noticing a trend very soon!

 

Eclipse

Originally developed by IBM, the now open source Eclipse is the most popular Java IDE in use today.  Available across many platforms and sporting a pluggable UI, Eclipse has everything and the kitchen sink for features.  I would say it is the most capable of the IDEs but on the same token, it is also the most confusing.  If you are working on Android development it is Google’s preferred environment, so that’s where the native tools are for authoring Android apps.  That said, I recently worked on an Android app and I HATED the experience.  Eclipse kept fouling up my projects again and again and again, if I was a new developer I might have quit in frustration!  Get to know the –clean parameter, you are going to use it… a lot.  In all honesty, for a new developer who isn’t doing Android work, stay away from Eclipse to start would be my advice. If you must use Eclipse, be sure not to go wild installing plugins unless you absolutely need them!  Even figuring out which version of Eclipse to download can be a daunting task!  If you don’t know, download this version.

 

 

Netbeans

In that special sort of way that Java has of making things confusing as hell, Netbeans is both the name of an IDE and the name of a platform for developing Swing applications.  In this case we are talking about the IDE.  Originally started as a student project ( in 96! ), Sun purchased and open sourced it in 99.  Since then, Sun (and now Oracle) have made continuous new releases.  It, like Eclipse, supports plugins although nowhere near as extensive ( or annoying! ).  That said, it just works.  For a new developer this is the one I recommend starting with.  Again like Eclipse, there are many different versions and if you choose the wrong one it installs a TON of crap you don’t need and probably don’t want ( like web and database servers! ).  On this download page, unless you have a very good reason otherwise, it’s the JavaSE version you want.  ** I should note, you can do Android development using NetBeans, it’s just not supported or documented by Google.

 

 

IntelliJ IDEA

This incredibly popular IDE, well to be completely honest, I have almost no experience with.  See, it used to cost money and Eclipse/Netbeans were always “good enough”.  That said, in a world full of free tools, people were still willing to pay for IntelliJ IDEA, that says something!  Now though, they have a completely free edition!  Again, I have no direct experience with IntelliJ beyond reading the website, but come time for my next Java project, I will definitely check it out.

 

 

 

Gaming related stuff

 

2D Libraries

 

Slick

I believe this is the most commonly used 2D game library on Java these days.  It is built on lwjgl ( details below ) and uses OpenGL or Java2D for fast 2D rendering.  Additionally it supports fonts, sound, input and image loading.  There is also support for spritesheets, tilemaps and 2D collision detection, all very common requirements in creating a 2D game.  The tutorials even walk you through creating a complete game. A very clean and beginner friendly library.

 

LibGDX

This library handles not only graphics, but sound, file handling, logging and input.  You can also create Android apps with very minimal code changes.  Like slick it uses lwjgl, as well as jogl behind the scenes.  The design seems remarkably clean, but the documentation is a bit lacking.

 

Java2D

This is Java’s standard 2D drawing library.  I am just mentioning it for completeness, as I see no reason to use it over Slick or LibGDX.

 

3D Libraries

 

Jogamp/jogl

These provide Java language bindings for OpenGL, OpenCL, OpenAL and OpenMAX libraries.  This can provide you with low level access to all your graphic and audio needs.  Additionally it can work with Java2D, Swing and AWT. A tutorial for getting started is available here.  Jogamp is completely up to date with the latest OpenGL implementation and is the underlying technology in many higher level Java graphics libraries.

 

lwjgl - Lightweight Java Game Library

Much like jogl, lwjgl is a library built on top of OpenGL and OpenAL.  Additionally it supports game controllers like gamepads and steering wheels.  It has been used to make a number of games and is the underlying technology powering the jMonkeyEngine.

 

jMonkeyEngine

Ok, it’s not technically a library, it’s a full game engine.  What does that mean?  Well instead of accomplishing one task, it accomplishes all the various tasks you need to create a game ( and as just mentioned, uses the lwjgl library to do it ). So in addition to graphics and sound, it provides a full scene graph, mesh and graphics importing methods, a GUI, networking library and much more.  If you are planning to work on a 3D game on Java, start here.  There’s a good selection of tutorials available to get you started.

 

 

Other Libraries

 

jBullet / jbox2D

The popular Bullet 3D and Box 2D physics libraries also have Java implementations.

 

 

Still too many choices, tell me exactly what to do!

 

Ok, first step is to download and install the Java tools.

Next up, go ahead and get NetBeans and install it.

Now download and start reading Thinking in Java, giving silent thanks to Bruce Eckel for his generosity.  If you can’t follow this book, or need a print one, consider purchasing Head First Java.

Run through the first few chapters, do the examples and learn the basics of the language.

Once you grasp the language basics, download and install Slick.

Run through the "Spiegel" tutorial.

At this point, you should probably be capable of creating your own 2D games.  If you are interested in 3D programming, consider checking out the jMonkeyEngine.

Finally, go out and get Effective Java and read it, twice.  It will make you a better Java programmer.

Congratulations, if you got to this point, you are now a game programmer!

 

 

 

 

Python is the language for me!

 

Alright, this section is totally getting the shaft.  Why?  Frankly because I don’t really know Python all that well and don’t feel comfortable giving advice on a subject I am not educated on!

So, instead I am going to give a number of links that will be of use.

 

First, you need to download and install Python itself.  If you don’t know which to pick, go with Python 2.7.

 

Now, picking an IDE out for Python is a right confusing task.  If you follow that thread’s (incredibly bad) advice of choosing Vim or Emacs, I will personally come to your house and smack you!  That said, an easy alternative doesn’t spring to mind.  Personally if I was working with Python today I would use Eclipse with the PyDev plugin.  That said, I am not really comfortable recommending that to a new developer.  Komodo edit is perhaps as good a (free) choice as any to start with, but it does not support integrated debugging.

 

Now that the messy business of choosing an IDE is all over with things get much easier.  There is one dominant 2D game library and that is the PyGame which may just be the most new user friendly game library available.  Tutorial support is quite good, as is the documentation.  Python really handles everything you could need to create a 2D game, graphics, sound, controls, fonts, etc…

 

However, if 2D isn’t your thing, check out Panda3D.  Stupid name aside, this is a powerful engine that has been used to create commercial games.  Again, like PyGame, it handles everything you could possibly need to create a full 3D game.

 

There are even a couple free books like Dive Into Python 3 and A Byte of Python ( good beginner text ). There is also a freely downloadable book Invent Your Own Computer Game With Python.

 

The most important piece of advice I can give you, don’t let people convince you that Python isn’t “a real language”.  It has been used in a number of shipping, high quality games and will continue to be used as such.

 

 

 

 

 

 

 

Now what?

------------------------------

 

So, you’ve picked a language, the libraries you want to use and now you need to, you know… do something.  This is a list of suggested projects for a new developer interested in games, in ( fully my opinion ) order of difficulty. I am always open to new suggestions here, so send them in!  Also, if you want to share the results of your efforts, let me know and I will make that available too!

 

 

… and everything else!

 

If you are looking at getting into 3D development check this list of 3D engines to get started.  If you are struggling with the art side of the equation, be sure to check out A programmer's guide to creating art for your game.

 

Good luck with your game development career!

Programming , , , ,







blog comments powered by Disqus