Ok, some of you may already know I working on a sequel to my Jak game...well everything is going great, but I'm having trouble figuring this out. I have a mouse aimed gun, and the shooting works great and all, but when I have the bullet hit something, I have it play the according animation to whatever it hit, and it all works, but the bullet is always at the highest depth. Now what I'm trying to do is make it so that the bullet appears behind the Front Layer (grass and trees) and above the background. I have it set to only have 10 bullets on screen at one time, so I made 10 movie clips to serve as Depth Swappers, so what the bullet does is when it gets duplicated, it swaps depth with one of the MC's and when it hits something, before it's removed it swaps back to its original depth. However, this is where the problem lies. This is the code:
if (i<10) {
duplicateMovieClip(bullets, "bullet"+i, this.getNextHighestDepth());
rot = (myDegrees4-95);
this["bullet"+i].swapDepths(this["swap"+
i]);
this["bullet"+i]._rotation = ((rot-180)*-1)+180;
this["bullet"+i].xMove = 50*Math.sin(rot*Math.PI/180);
this["bullet"+i].yMove = 50*Math.cos(rot*Math.PI/180);
this["bullet"+i]._x = xx;
this["bullet"+i]._y = yy+(this["bullet"+i].yMove*2);
i++;
}
and here is the code on the bullet to remove it:
stop();
if (_root.i>0) {
_root.i -= 1;
}
this.swapDepths(_root["swap"+_root.i]);
this.removeMovieClip();
What this basically does is, whenever I fire a bullet it adds 1 to "i" and whenever the bullet hits something, it removes 1 from "i". I helps me keep track of what bullet goes with which swapping thing, however, the Variable "i" is giving me some trouble here, because it doesnt do what the code says. When I trace the variable, it doesnt go back down to zero all the time, and it throws the whole thing off. Any ideas? I checked the code a bunch of times, but I dont see anything wrong with it, it just doesnt seem to be working right.