The web site for Flash ActionScript 3.0 game developers

 
         
   

Blogs

Game Inventory System

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, shows you how to create a very simple particle system using a class and by adding and removing movie clips from the display list.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Simple Particle System

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, shows you how to create a very simple particle system using a class and by adding and removing movie clips from the display list.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Continuous Animation

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, answers a question in this podcast of how to maintain continuous animation while receiving user input. The character on the screen continues to follow a walk animation even while the player triggers the animation over and over.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Multiple Windows with Flash

How can I create a Projector that opens multiple windows, say I want to simulate a windows application with a main window that opens additional windows on top for configuration purposes.
Thanks, Sharon

If you want a real OS window, you'll need to look into using a Flash Wrapper application -- something that add functionality to Flash projectors. Search for "flash wrapper" and start looking it different ones.
On the other hand, you can use Movie clips and Loaders to simulate windows inside of a Flash movie. Just make a movie clip that looks like a window, and have that appear on top of everything else. When the user is done with it (OK or Cancel buttons?) then remove it from the stage. You could also add a close button if you like, and even the ability to move the window around around by dragging it from the top. These kinds of things can be quite simple, or very complex, depending on what you want.

Using Bitmap Drawing as a Substitute For Lots of MovieClips.

Ant wrote:

Just wondering if you know of any useful ways to reduce the slowdown effect caused by having lots of MovieClips in a game. For example I have a student making a shooting game that gets progressively laggier due to all the blood he makes them spawn. At the moment he's using the "cacheAsBitmap" setting which helped a little but I just wondered if there's a way to combine drawings/graphics similarly to how Break Apart works in the normal Flash environment.

Your student must be using a lot of movieclips. I've used hundreds, even thousands, of them without seeing a slowdown in AS3. One key is to keep the complexity of these symbols simple. If they are a drop of blood, for instance, select the shape in the symbol and use the Modify, Shape, Optimize function to reduce its complexity. See how simply you can get the shape while still looking good. Also avoid using gradients if you don't have to. Even using cacheAsBitmap isn't as good as actually using a bitmap, so you may want to consider using a bitmap.
On the other hand, instead of using multiple symbols at all, why not have a single bitmap graphic layer that you draw to? Then add the blood to this single layer by using the BitmapData.draw command.

FlashGameU.com Video Tutorial: External Constants From an XML File

Gary Rosenzweig, author of ActionScript 3.0 Game Programming University, shows you how to read in a small XML file containing some constant variable values.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Not Repeating Items in a List

Markus Wrote:

I am making a rather simple word game which reads in words from an XML-file (randomized). What I want to do is having a randomized order but sometime keeping track of which words has already been used in the game, so that I dont risk that a word will appear twice in the game. Do you have any solution for this?

This is a pretty common task. If your list is shuffled into a random order, though, then you don't have to worry about it. For instance, if you have 100 words, and then put them in a random order, and then take one word from the list at a time, then you should never end up with the same word twice as you are removing words from the list as you go. The key is to shuffle the array or words, and then remove them as you use them. For an example, see the section "Randomizing the Questions" in chapter 10 of the book.

hitTestObject Not As Expected

John Writes:

I have a long rectangle shaped movie clip and a ball on my stage. I want to detect when the ball hits the rectangle. The rectangle is angled at 45 degrees using transform. hitTestObject appears to true based on a rectangular are that encompasses the entire rotated movieclip (Imagine drawing a rectangle around the object so that the object goes from the upper left to lower right corners of the rectangle).
I want to test when the ball is touching the actual movie clip - not the area around it - how do I do that?

You are right. The hitTestObject function just looks at the bounding boxes, not the actual shape of the objects. If you think about it, this makes sense. Can you imagine the complexities of looking at the shape of two Flash display objects and determining if they overlap? Such a function would be very slow, which is why I imagine it doesn't exist. I talk a bit about how hitTestObject and hitTestPoint work in chapter 2, in the section on Collision Detection.

So, to your problem. If the ball is small enough, then you can simply use hitTestPoint with the point being the center of the ball. But if the ball is too large, then you'll need to dig into deeper math to determine when the ball actually touches the side of the rectangle. You can do a Google search on "collision detection circle line" to see some articles on the subject. It is pretty complex if you don't have a background in math.

FlashGameU.com Video Tutorial: Countdown Clock

Gary Rosenzweig from FlashGameU.com shows you how to build a simple clock to count down time until the end of a game.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Random Direction and Background

Hello there, I am a beginner at flash and have been trying to make a game.. Two things, the first is, that I want a Math.random that has the interval from -1 to 1, so that I can create a random direction for a ball. The other question is that I want to create a button that gives the background a random color. These are my problems, can you help me ?
Yours sincerly
Brian

If you are looking to create a random number from -1 to 1, which includes all stops in between, then you would need a range of 2, but lowered by 1 so it is -1 to 1 instead of 0 to 2. So, the statement would be var myRandomNumber:Number = Math.random()*2-1;
However, if your intention is to create a number that is -1 half the time and 1 half the time, then you can't simply round the number, as you would get -1, 0 and 1 at various times. So you would probably want: var myRandomDirection:int = (Math.random() < .5) ? -1 : 1;
The ? and : statement has three parts. The first checks to see if Math.random() is less than .5, which will happen 50% of the time. If so, then -1 is returned. Otherwise 1 is returned.
One way to create a random background color is to have a sprite that is a solid fill behind everything else. Then use the colorTransform to set its color. Like this:

var myColorTransform:ColorTransform = new ColorTransform();
myColorTransform.color = 0xFF0000;
myBackgroundMC.transform.colorTransform = myColorTransform;

To make it random, have the color value chosen at random from an array of possible colors.

Syndicate content

Copyright Gary Rosenzweig