-->

Air for Android: Animation causes lagging in my ga

2020-05-06 13:08发布

问题:

I'm making a game in cs6 air for android. When I make animations for my game, I use the 3D software blender. In blender I make an animation, and then render it as a sequence of PNG images, which I import to Flash CS6. So if I'm making a walk animation for my character, I make around 30 png images i blender, and import them as a sequence. This works pretty well most of the time, but I have a problem with some of the animations I made. As an example I have an animation of an enemy that explodes. So in my game, there is sometimes a lot of enemies at the same time, and they explode when I click on them. But the explode animation makes the game pretty laggy.

The question: Is there a way to maybe convert the png images to something else, that doesn't lag? Most of the other animations I made works without lagging. Maybe the explode animation is especially heavy, I don't know. I know that I could draw the animation myself in cs6, and then it would not lag, but it would take a lot of time, and not look as cool.

I hope I made myself clear, and thanks in advance!

回答1:

Only use bitmaps - everything else has to be off the stage. Bitmaps use the gpu, everything else uses the cpu. You can use whatever to create regular mc's but convert them to bitmap. Show a loading screen, load your png files into mc's, convert mc's into bitmaps, delete png files, remove loading screen and run.

Here's example function for creating bitmaps out of mc's. The code shows replacing a regular vector mc with a bitmap copy:

var bmpTemp: Bitmap;
bmpTemp = fDrawTile(mcVector, 0, 0, iWidth, iHeight);
mcHolder.mcBitmap.addChild(bmpTemp);
mcHolder.removeChild(mcHolder.mcVector);
mcHolder.mcVector = null;


function fDrawTile(pClip: MovieClip, pX: int, pY: int, pWidth: int, pHeight: int): Bitmap {
    trace("fDrawTile: " + pX + "," + pY + "  " + pWidth + "," + pHeight);
    var rectTemp: Rectangle = new Rectangle(pX, pY, pWidth, pHeight);
    var bdClip: BitmapData = new BitmapData(pWidth, pHeight, true, 0x00000000);
    var bdTemp: BitmapData = new BitmapData(pWidth, pHeight, true, 0x00000000);
    bdClip.draw(pClip, null, null, null, rectTemp, true);
    bdTemp.copyPixels(bdClip, rectTemp, new Point(0, 0));
    var bmpReturn: Bitmap = new Bitmap(bdTemp, "auto", true);
    return bmpReturn;
}

mcHolder can be moved around smoothly once converted to bitmap.

This method is so powerful because you can create images at runtime.