Ok, so I'm doing a remake of the old game Asteroids as I learn ActionScript. It's a long way from being finished, but I'm breaking it up into chunks. As I finish a section I move on to a new one.
I've already received some pointers from a couple people regarding smooth animation (thank you), so now I'm looking for pointers for a couple specific things, and am looking for any comments on alternate, even better, ways of doing what I've done.
For instance, I have looping sound effects attached with ActionScript on a frame within clips (rightThrusters_mc, leftThrusters_mc, and mainThrusters). I'd love to put it on the first frame of the main timeline, but because it's in a "if (Key.isDown....." statement, the same sound keeps loading over and over, until 100s of instances of the same sound bog down the computer. I'm looking for a way to dynamically attach the sound while the key is down and remove it when the key is up. My way is especially problematic, because if you keep holding the up arrow to move forward, AND turn left or right, the main thrust sound stops when you finish turning.
I also had to put animation that makes the asteroids rotate at various speeds INTO the clip, because the code on the main timeline that figures out the direction the asteroids tavel using the "._rotation", as does the rotate. If I try to get the asteroids to rotate randomly and move in random directions (at a fixed velocity), their directions change as they rotate.
Also, is there a way to call on the same function (specifically my WRAP function) without having to declare a variable each time? I couldn't get it to work for the asteroids until a made the clip name into a variable name and passed that through the function:
for (var i = 0; i<numAst; i++)
{
var ast:MovieClip = this["ast" + i];
move(ast);
var myClip:MovieClip = this["ast" + i];
wrap(myClip);
}
Anything I want to pass through the function "wrap" has to be renamed "myClip". I'd love to be able to put the code in as:
for (var i = 0; i<numAst; i++)
{
var ast:MovieClip = this["ast" + i];
move(ast);
wrap(ast);
}
I also had to copy word for word code from someone else's asteroid remake to do my shooting. I've been tweaking it to suit me, but most of that code is below mine, commented out. I don't understand it entirely, especially the fact that it seems to call on variables that aren't defined anywhere, but seem to have value anyway:
for (var k in lasers) {
lasers.splice(k,1);
What's "k"? I never saw a "k" set...what gives?? Tracing it didn't help; I got nothing the first four times i shot, then i got:
0
1
2
3
4
I'm pretty sure the code adds another shot into the array, until it hits 5 pieces in the array, then it starts removing the oldest everytime a new shot is fired. The problem I can't fix is that the sixth time you shoot, nothing happens. Then you can shoot 5 times, then nothing...... If I could understand what it meant, I could tweak it.
Most of all, since this is a learning experience for me, any and all feedback would help. I'd love to hear different ways to achieve the same effects (especially if I can understand the code, hehe).
Thanks for the help and comments so far, and in advance for any others!