There's a noticeable slowdown when initiating troops. That's because the sprite sheet I'm using is over 100 KB now that muzzle flashes and deaths are in it. Splitting the sprite sheet up into separate sprite sheets doesn't speed it up, it brought it down to 6 FPS whenever the troops were changing sprite sheet (hence me combining the sprite sheets into one big one).
The problem, as I see it, is that every time I create a troop, I'm generating a new sprite sheet bitmap.
PHP Code:
function createTroop(team:Number, soldier:Number):void {
if (soldier==1) {
var myTroop:Troop = new Troop(this);
myTroop.y = 200+Math.random()*150, myTroop.cacheAsBitmap = true;
if (team==1) {
myTroop.x = -44, myTroop.team=1;
var rifleRight:RiflemanRight = new RiflemanRight();
var rifleRightBMP:Bitmap = new Bitmap(rifleRight);
myTroop.addChild(rifleRightBMP);
troops1.push(myTroop);
} else {
myTroop.x = 750, myTroop.xspeed = -myTroop.xspeed, myTroop.team=2;
var rifleLeft:RiflemanLeft = new RiflemanLeft();
var rifleLeftBMP:Bitmap = new Bitmap(rifleLeft);
myTroop.addChild(rifleLeftBMP);
troops2.push(myTroop);
}
stage.addChild(myTroop);
myTroop.frame();
}
}
Most important part to read in that script is this, btw:
PHP Code:
var rifleRight:RiflemanRight = new RiflemanRight();
var rifleRightBMP:Bitmap = new Bitmap(rifleRight);
myTroop.addChild(rifleRightBMP);
Every time the createTroop() function is called, I'm creating a new bitmap (riflemanRight or riflemanLeft). Now, if I only declare this bitmap once (ie, moving it out of the createTroop() function), only one troop can use that sprite sheet at any given time (ie, when I create a new troop, it takes the sprite sheet from the previous troop, leaving that troop invisible).
Can anybody think of a more efficient way to do this?
Also, if anybody can suggest a way for me to create a copy of an array, that'd be great (since I create a big bi-dimensional array to push troops into every frame, and it'd probably be faster if I just created it once, and then made a copy of the original every frame).
Is there a speed difference between Bitmaps and BitmapData?
And the sprite sheets aren't a simple horizontal flip - they're actually a horizontal flip of each individual sprite (so the scroll script doesn't have to change).
Is there a speed difference between Bitmaps and BitmapData?
Bitmaps are the display objects that exist in the display list. They are the "things" in Flash's memory which get thrown on the screen and displayed in the Flash player. The data that determines what is displayed is separated from that object and placed in another object called BitmapData. This object contains the pixel information that is used in Bitmap display objects. This is separated because BitmapData can be used in other places other than in Bitmap isntances such as filters. But for a Bitmap instance to show an image, it needs that BitmapData. They work together (as Cimmerian said) so differentiating speed differences really isnt an issue.
Originally Posted by VENGEANCE MX
And the sprite sheets aren't a simple horizontal flip - they're actually a horizontal flip of each individual sprite (so the scroll script doesn't have to change).
You wouldn't be flipping the sheets, but the Bitmap or sprite itself. This prevents any need to change the internal code, you're just flipping the whole thing. I'll update the example I posted earlier to show this
Just skimming through your code, it looks like you're using scaleX to flip 'em. I got a massive lag when I tried using scaleX for the flips (was my original idea), lost about 10 fps.
Because when doing that you get rid of the movieClip wich is the stage class, mcs are slow cos they have a useless (in this case) timeline and besides that, they are dynamic and got to have internal hash to handle the new dynamic stuff
I think my Troop class used to extend Sprite instead of MovieClip. Dunno why I changed it originally, but now that I've replaces extends MovieClip with extends Sprite, I get this error:
**Error** /Users/twinz/Desktop/Birchlabs/Commando 4/Troop.as : Line 5, Column 29 : [Compiler] Error #1017: The definition of base class Sprite was not found.
public class Troop extends Sprite {
Do I have to define the Sprite class somewhere or something?