This will be a rather unusual tutorial. You are going to use something you know, Actionscript, and code with it in a way so ridiculously similar to the way you would do it in Java, that you will learn Java! First are going to build a game in Flash, and then rebuild it in Java.
What makes Actionscript so different?
No. Not the vector thing. Although to say Java can use Vector just as Flash can is like saying Notepad can use Text just as Word can.
Actionscript has the Display List idea, and I know of no other language (script or otherwise) that has that. It has MovieClips, Sprites, Bitmaps; the addChild, removeChild methods, the add to stage event, removed from stage event…
What all that represents in the end are methods of a Framework, and what that Framework gives you is a pretty decent screen manager, which decides when to updtate the screen.
Change an object’s scale, its x or y position, its alpha, or rotation… and the change fires up an event that tells the framework: show this change.
Remove the notion of a display list and display objects, and you are screwed, right? As it turns out: nah, not really.
Java, C#, C, Objective C… these languages don’t have this framework, although they allow for the creation of one, if you would like… But you don’t need it. Instead these languages use methods like screen painting, double buffering, and the most famous of them all for game programmers: blitting.
And let me explain away some of the jargon. Think of blitting this way: You have a character moving across the screen, on top of a white background. In one iteration the character is at X = 10. So in order to show that, you paint the screen white, and then you copy the pixels of that character from a source image that contains the drawing of the character, and you copy those pixels starting at X = 10. In the next iteration the X changes to 20. So you fill the screen with white, “painting over” what was there from the previous iteration, and once again you copy the pixels from the same image source containing the art for the character, but this time you copy it to X = 20. And so on and on, until the character has moved off the screen. This is blitting. The transfer of blocks of bits, particularly as it relates to screen painting.
Actionscript can be made to work in a similar way to Java, through blitting, and that is what I will show you in the Flash part of the tutorial.
There will be no Sprites used in the game, except for the stage. No Movie Clips, not one addChild or removeChild call, and so of course no Added To Stage events, no updates on the X and Y of a display object… Nada. All I’m going to use is the Graphics property of the stage, and fill it with a bitmap for every iteration of the game. The rest is taken care of by Rectangles.
The notion, much praised by me, of coding as if nothing is on stage, will once again be used. The gave is nothing but rectangles, which are nothing but specialized groupings of integers. It just happens that in every iteration, we paint something over the rectangles.
What You Will Need
– You will need Eclipse for Java SE, or NetBeans or Dr. Java… in other words, a free IDE for Java. I use Eclipse.
– You will need the Java SE SDK. Online, you can find a bunch of tutorials on how to install these. You could check this one out.
– And I will make an ass out you and me and assume that you know how to use Flash FDT or Flash Builder or any Eclipse clone, and therefore know how to set a project on Eclipse and run it.