Thursday, May 31, 2012

Tune your AIR for iOS development skills: compile, install and profile like a pro

The purpose of this article is to share with you some tips, that might help you to speed up and improve the process of building AIR for iOS apps. These are the practices that I use every day and hopefully some of you will find them useful.

Installing an app (*.IPA) on your iOS device

As a developer you want to save time, being able to install apps on the device quickly and see the results is the most important thing. Using iTunes for app install has some drawbacks: you will have to synchronize it and it takes lot of time and you cannot install apps on devices that are not synchronized with your iTunes (like friend’s iPad).
There are three ways I find quicker:
iPhone Configuration Utility
Available for Windows and Mac from Apple, this smart piece of software helps you to manage apps installed on your devices. Drag and drop IPA file to Applications and then choose a device and install or uninstall specific apps. Works for iPad as well. You can also manage configuration and provisioning profiles.
Download for Windows | Download for Mac
iPhone Configuration Utility
Xcode Organizer
Read more: Tune your AIR for iOS development skills: compile, install and profile like a pro

Sunday, May 27, 2012

FlashPunk UI Components: Advanced Graphics, Extra Skins, and Polish

This entry is part 2 of 2 in the series FlashPunk UI Components
In this tutorial we’ll finish what we started in the first part of this UI with FlashPunk mini-series. We’ll learn how to customize the graphics of our components, and make a few adjustments to make our UI perfect.


Final Result Preview

Let’s take a look at the final result we will be working towards:
Make sure you click everything to see how it responds!

Section 1: How to Draw

Step 1.1: Open Your Existing Project

If you don’t already have it, be sure to download the source code from part one. Open the project file in FlashDevelop (info here) and get ready to upgrade your UI!

Step 1.2: Drawing Stuff

The next step we need to do to be able to extensively customize the graphic side of our UI is learn how to draw the graphic stuff directly with code. At the momment we needed an image for each state of our UI (button normal, button hover, checkbox normal unselected, checkbox normal selected, etc.), so we needed a large ammount of Images. Now, let’s say you want a different color for each button, or even a different shape for each one, and selected randomly… we can’t afford to have millions of images: too work to make them and they consume too much memory.
But before starting to draw the components itself, we must first learn how to draw stuff using code in FlashPunk.

Step 1.3: Preparing a Drawing Test World

First of all, we need a new World to test the Drawing stuff. Create a new World class, called DrawWorld, and tell Main to go there when starting the game.
DrawWorld.as:
package
{
 import net.flashpunk.World;

 public class DrawWorld extends World
 {
  public function DrawWorld()
  {

  }
 }
}

Step 1.4: Using the FlashPunk Drawing Utils

The FlashPunk Engine has a few utils which lets us Draw things to the screen or to a BitmapData.
These functions are: line, linePlus, rect, rectPlus, circle, circlePlus and curve (the other ones are used to draw other kinds of stuff). The ‘plus’ versions come with more options and give better results (using antialiasing) but are more CPU intensive.
Using them is easy; override the render method of your World or an Entity and call those functions, like this overriden render function for our DrawWorld, which draws some shapes:
override public function render():void
  {
   super.render();

   Draw.line(10, 10, 100, 100, 0x00FF00);
   Draw.rectPlus(120, 120, 200, 200, 0x9999FF, 1, true, 2, 10);
   Draw.circle(100, 100, 50, 0xFF0000);
   Draw.curve(100, 100, 140, 90, 122, 122, 0x00FFFF, 1, 3);
  }

Read more: FlashPunk UI Components: Advanced Graphics, Extra Skins, and Polish

Thursday, May 24, 2012

The guide to implementing 2D platformers

Did you ever wanted to develop you own platform game, or simply wondered how platform games are made?
Rodrigo Monteiro from Higher-Order Fun wrote the most complete guide I ever found in internet, with a tons of suggestions to let us create our platform game and gives me the permission to share it with you.
It’s a very long topic, so take your time because this is an incredible journey into the world of platformers.
Having previously been disappointed by the information available on the topic, this is my attempt at categorizing different ways to implement 2D platform games, list their strengths and weaknesses, and discuss some implementation details.
The long-term goal is to make this an exhaustive and comprehensible guide to the implementation of 2D platform games. If you have any sort of feedback, correction, request, or addition – please leave it in the comments!
Disclaimer: some of the information presented here comes from reverse engineering the behavior of the game, not from its code or programmers. It’s possible that they are not ACTUALLY implemented in this way, and merely behave in an equivalent way. Also note that tile sizes are for the game logic, graphical tiles might be of a different size.
Four Ways of Implementing
I can think of four major ways in which a platform game can be implemented. From simplest to most complicated, they are:
Type #1: Tile-based (pure)
Character movement is limited to tiles, so you can never stand halfway between two tiles. Animations may be used to create the illusion of smooth movement, but as far as the game logic is concerned, the player is always right on top of a specific tile. This is the easiest way to implement a platform game, but it imposes heavy restrictions on the control of character, making it unsuitable for traditional action-based platformers. It is, however, popular with puzzle and “cinematographic” platformers [...]
Read more: The guide to implementing 2D platformers

Monday, May 21, 2012

The Math and ActionScript of Curves: Drawing Quadratic and Cubic Curves

We see lines used in a lot of scenarios; curves are also used but perhaps not as frequently – but that doesn’t undermine their importance! In this tutorial we shall take a closer look at curves, particularly the quadratic and cubic curve, along with some of their commonly used mathematical features.

Final Result Preview

Let’s take a look at the final result we will be working towards. Drag the red dots and see the gradients change in position.
And here’s another demo, using cubic curves, without the gradients:

Step 1: Curves

Quadratic and cubic will be featured in each of these sections. So let’s first look at the equation of curves. These equations are written in polynomial form, starting with the term of highest degree. The first one is quadratic equation (highest degree is 2); the second is cubic equation (highest degree is 3). \[f(x) = Ax^2 + Bx + C\ ... (eq\ 1)\] \[g(x) = Ax^3 + Bx^2 + Cx + D\ ... (eq\ 2)\] Note that A, B, C and D are real numbers. So now that we are aquainted with it, let’s try to visualise it. Graphing curves will be our next attempt.

Step 2: Graphing Curves

First, let’s graph a quadratic curve. I’m sure all readers have graphed quadratic curve in high school math class, but just to refresh your memory, I present graphs below. They are placed side by side to ease comparison.
  • Left graph is using Cartesian coordinate space
  • Right graph is using Flash coordinate space
Graphing onto Cartesian and Flash coordinate spaces.
The obvious difference is the inverted y-axis on Flash coordinate space. They look simple overall, right? Okay, now we’re ready to plot onto Flash coordinate space.

Step 3: Quadratic Coefficients

To position quadratic curves at the right spot, we need to understand their corresponding equations. The curve drawn is really dependant on the equation’s coefficients (for the case of quadratic, those are A, B and C). I’ve included a Flash presentation below so you can easily tweak these coefficients and get immediate feedback. [...]
Read more: The Math and ActionScript of Curves: Drawing Quadratic and Cubic Curves

Monday, May 7, 2012

Generating Ghosts That Follow in Your Footsteps

Path following is a simple concept to grasp: the object moves from point A to point B to point C, and so on. But what if we want our object to follow the path of the player, like ghosts in racing games? In this tutorial, I’ll show you how to achieve this with waypoints in AS3.


Final Result Preview

Click the SWF, then use the arrow keys to move around. Press space to switch to the ghost, which will follow the path you’ve created.

The Logic Behind Path Following

Let’s suppose the player moves 4 units left and 2 units down from our point of origin. For our ghost to end up in the same location it will have to also move 4 units left and 2 units down from the same point of origin. Now let’s say our player is moving at a speed of 2; for the path following to remain accurate our ghost will also have a speed rate of 2.
What if our player decides to take a pause before continuing on? The obvious solution is for the ghost to keep track of the player’s exact position every tick – but this will involve storing a lot of data. Instead, what we’ll do is simply store data every time the player presses different keys – so if the player moves right for ten seconds, we’ll store the same amount of data as if the player moved right for half a second.
For this technique to work our ghost must abide by the following rules:
  • The ghost and player have the same point of origin.
  • The ghost must follow the exact same path as the player.
  • The ghost should move at the same speed as the player.
  • The ghost has to store the current time each time the player’s motion changes.

Step 1: Setting Up

Start by creating a new Flash file (ActionScript 3.0). Set the width to 480, the height to 320 and frames per second to 30. Leave the background color as white and save the file as CreatingGhosts.fla; lastly set its class to CreatingGhosts.
Before we move into the classes we need to create a pair of MovieClips. Start by drawing two separate 20px squares without a stroke. Convert the first fill to a MovieClip, setting its registration to the center, naming it player and exporting it for ActionScript with the class name Player. Now repeat the same process, except replace the name with ghost and the class with Ghost. Remove these MovieClips from the stage.
Create your document class with the following code:
Read more: Generating Ghosts That Follow in Your Footsteps

Wednesday, May 2, 2012

Gaming Your Way: So how does the NPC AI in Outpost:Swarm work ?

Now Outpost:Swarm is live I thought it may be an idea to explain how I did your in-game partners AI. If you've ever read up on Boids you'll know they have 3 simple rules, Separation Alignment Cohesion And all the examples you'll see are bird like objects flying around, maybe towards your mouse pointer, maybe avoiding obstacles. All seems simple enough. Adding them to a real game however quite a bit trickier. For separation we have to ensure the NPC is avoiding both the player and all the baddies. Firstly we find the distance to the players sprite using a simple distance=dx*dx + dy*dy; Like you would in your usual circle to circle tests. If we're too close then we need to repel the NPC from the player, via: tmpPoint1.x+=dx+dx; tmpPoint1.y+=dy+dy; Where tmpPoint1 is just a new Point(0,0); That's part 1 of the test done, the second is checking against all the baddies, and there can be a load at any one time. What I did was use a flip flop, every even frame we get a list of all the possible neighbours ( Baddies which are close enough to care about, if they're on the other side of the screen then we can skip them ), every odd frame we do exactly the same distance check as we did above. Finally we divide our Point value, tmpPoint1.x/=speedDivisor; tmpPoint1.y/=speedDivisor; ( private var speedDivisor:Number=20; ) This keeps the values within a respectable range so we don't move too fast. Read more: Gaming Your Way: So how does the NPC AI in Outpost:Swarm work ?