Gannroids

In the breaks I have at work I downloaded and installed Adobe’s CS4 software and decided that I would make a quick little prototype game just to learn about ActionScript 3.0 and CS4.  I did what I usually do which is to make an Asteroids clone.  This time the theme would be one of my co-workers; I wanted to blow up his head, what can I say? *grin*  The collision is a little funky due to my sloppiness/laziness but I’m satisfied for the amount of time I put into it; which I would say perhaps 12 hours over a week and a half.  Most of the time was spent learning ActionScript idiosyncrasies.  Here is the result:

For some reason the transparent pixels wouldn’t save when I uploaded to WordPress, so you get square heads.

Gannroids

CS4 has some interesting features.  One can enter media objects onto the stage and bind them to a keyword and ActionScript file.  Its seems cool at first and really easy, however it only seems useful if you have one or a few instances of a class.  For the most part I just bound the stage to my game.as file and let game.as handle everything.  I created classes for Asteroids and Bullets to learn how to do class work in ActionScript and I ran into a few problems but for the most part everything was seamless.  (As seamless as it can be writing anything in a new language).

To look at some specific problems I encountered, continue reading.

Here are the problems some encountered in no specific order:

1 – Getting graphics objects to be included in the .swf.  I never really came up with a solution, my image for asteroids is externally loaded.  I’m sure there is a way to embed graphics in the .swf and call it programatically, similar to how you can bind a symbol to a keyword I’m sure you can bind an image to a keyword to access in the code.

2 – Keeping track of things in the DisplayList.  I spent a large portion of my time here trying to figure out how to cast things into the type of objects I needed them to be and figure out the correct depths of the DisplayList.  In the end I ended up just going through every object in the display list and checking its object type if I needed to modify an object that I was using.  In other programming languages I wrote my own draw functions so I would just have a Vector containing all my objects that I had created and draw that Vector.  The DisplayList is a very similar implementation however it seemed I had less control.  I probably just don’t know the ins and outs of the DisplayList class and that will come with time I’m sure.

3 – Collision detection.  I had all sorts of problems with positioning.  The default x and y properties inherent in a DisplayObject were acting strangely so I ended up adding my own properties for x and y, which in turn caused problems with display and later with the collision calculation.  If I were to go back I would make sure to use the default x and y property better.

4 – Image centering.  One can set a registration point on a symbol in CS4 and it will set the axis of rotation (center preferably)  I could not figure out how to do this programaticlly with a property so I created a Sprite container and put an image loader object inside it and offset x and y by -imageWidth/2 (thanks Nathan)  This was another thing causing collision issues, I had multiple objects using different x/y’s and then images that were rotating were offset and I would forget what was using what.  It was close enough in the end and I was too tired to track down what was wrong with it.  Next version of anything I do I will pay more attention upfront to draw/x/y coordinates.

Overall the experience was good, I feel comfortable enough with ActionScript now and delved a little into CS4.

1 comment · Written by Tyler at 2:26 pm · Tags , , ,


1 Comment »

  1. Yeah, the image centering thing is definitely weird. Once you get used to it, though, and the concept of Display Object Containers, it seems to be OK. I’m still experimenting with Actionscript’s built-in object collision detection (hitTestObject). My first test with it seemed to work. Embedding content in the SWF is also something I’ll have to figure out.

    Comment by Nathan — November 20, 2008 @ 9:00 am

RSS feed for comments on this post. · TrackBack URL

Leave a comment