Yesterday I noticed that Adobe had released a few APIs for dealing with Xbox and OUYA controller support for Flash games, so I went out during lunch and purchased an Xbox controller that I could experiment with.
I spent a couple hours researching and playing around with the APIs, and eventually wrote something usable that wraps those APIs for working with an Xbox controller. The classes are available here and are pretty straightforward to implement. The 2 important classes are XboxInput and XboxController, used like so:
var controller:XboxController = XboxInput.getController(0);
if(controller !== null)
// Check for input.
Once the controller is not null, you can determine whether buttons are currently held down on the controller using .buttonIsDown():
trace("A is held down.");
You can also access the current pressure applied to the left and right triggers, which ranges from 0 (not pressed at all) to 1 (fully pressed down):
And you can determine the x and y positions of the left and right joysticks, which range from -1 to 1:
I haven't tested this with multiple controllers yet, so I can't comment on how well that works at this stage. I do intend to add more features to my wrapper (e.g. buttonWasPressed() and buttonWasReleased()) and fully test multiple controllers connecting and disconnecting.
var i = array.indexOf(target);
if(i >= 0) array.splice(i, 1);
There is a massive downside to this approach that most inexperienced developers aren't aware of, which is that this approach will need to re-index every other element after the target. This is an extremely slow process, especially if the target is near the start of the array. If the target was the number 3, the process could be visualized as:
1,2,3,4,5 // Starting array
1,2,x,4,5 // First iteration
1,2,4,x,5 // Second iteration
1,2,4,5 // Final iteration
As you can imagine, the process lengthens as there are more items to shift down the array. A method that I use in cases where there are many items that need to be rapidly added and removed, but where a linked list or other simpler data structure isn't adequate, is to use pop().
pop() removes the last element from an array, a process which does not affect other elements' positions in the array. If this element isn't the target, and we know the index of the target that we want to remove, we can replace the target with the result of pop(). This removes the need to re-index the array because the target index is not being emptied, just filled with something new. That code looks like this:
var i = array.indexOf(target);
if(i >= 0)
if(array.length === 1 || i === array.length - 1)
// Simply remove the only remaining element.
// Replace target with last element.
var tmp = array.pop();
array[i] = tmp;
I had the chance a few weeks ago to do a little bit of game development. I didn't have anything in particular that I wanted to work on, but I wanted it to be something easy to get up and running, in an attempt to get myself into the flow and potentially start working on an actual complete project.
I only got about 2 full days into it, but I ended up taking the route of a pixelated 2D space game:
Given the chance to continue development, I would aim add 3 main components:
Mining & gathering.
Trading (travelling between different areas to get better buy & sell prices on goods mined or collected).
RPG elements including ship customization / advancement and a wide range of loot. Also included would be missions / quest which would eventually result in game completion.
I liked where what I had was going, but unfortunately I don't have the time at this stage to continue development. If I do get the chance, I'll post additional progress and likely a gameplay demo.
The game was being developed in ActionScript 3, using Exalted (my own incomplete game engine), which makes use of Starling for high-performance 2D rendering and Box2D for physics.
I've decided to go with a straightforward, plain blog look with minimal styling. Most of the reason is the fact that I'm not a designer, and don't have the talent to make something appealing as a result. Another reason is the fact that I'd like to keep my site fast and working nicely across devices (I've found that it's actually quite an effective decision for mobile).