Tuesday, April 14, 2009

Playing Around With ActionScript 3

Recently inspired by a series of tutorials in AS Gamer, I spent about 3 days to put together my first flash game in action script 3. Here's the end result:



The game is quite short, but it is a complete game. It's my first time to code something in action script 3, so there were many problems that I encountered. I like to put down some notes here to serve as a future reference for myself:
  • Frame-based animation vs Time-based animation: In Flash, there are primarily two types of animation: first is the frame-based, which has a smoother result when run on different frame rates. However, its playback speed will vary depends on the frame rate. Second is the time-based animation, which has constant playback speed regardless the frame rate, but sometime it causes loss of frames if the machine cannot run on the specified frame rate.

    Usually, time-based animation will be preferred due to its unified performance. However, I couldn't fine-tune my game objects to have desired movement in a time-based manner while keeping the keyboard controlling mechanics. After some tests and trails, I decided to switch the controlling mechanics to mouse only. Also, I used the frame rate as denominator for the movement speed in a frame-based manner for the game objects. This solution worked out rather nicely. The animations look similar with either 24 fps or 60 fps. It's certainly not perfect, but hey, it works! :)

  • Central game engine: There is a Main class that serves as the entry point for the program and it is intended to act like a game engine as well. However, I didn't end up utilizing this class enough, and later when I tried to add in intro screen, game over screen, and a pause feature, it turned out to be a mess because I had to sparkle code all over different places. Then I decided to cut the pause feature because it will require a lot of changes in the other codes. I realize the same-old "big game loop" will work better than the different initialization code that I added in the constructor.

    Also, the flash library become quite crowdy when I kept adding in different movie clips. A better resource management could be implemented with the engine as well. Next time I'll try to plan ahead of what my engine should do.

  • Class inheritance: I was surprised to find out at the end that most of my game objects, which are usually movie clip subclasses, have many properties and methods to share in common. It would be nice to have a parent class or interface for all these objects. It would make the code more neat and clean.

  • Music, arts, and dedication: A lot of time was spent on making my ship look nicer or finding the appropriate sound effect for firing bullet. Then I just again realize that I'm not an artist or musician in any shape or form. I should have network more with some artists/musicians in the GDC 09. :P

    Then it's the final note: if one wants to become a game developer, making game on his/her own time is necessary. Not only it looks nicer on the portfolio or resume, but also it shows one's dedication for gaming. It doesn't really matter the quality of the game, what really matters is the lessons learned from making the game.

3 comments:

Anonymous said...

Very cool :D
I'm happy AsGamer helped some. Great job on the game.

Anonymous said...

Hi, brilliant tutorial. I was wondering if you could upload the Code so I can compare with AS Gamers. I am having trouble trying to get the Start Screen going. And also would like to know how you get the ship to follow the mouse.

Thanks
Dino

Jianfei Liao (Fei) said...

Hi Dino,

Unfortunately, this is so long ago I actually lost my source code. As far as to get the ship follow the mouse, I basically just replace the normal mouse image with my ship image.