Air for Android: Animation causes lagging in my game

本小妞迷上赌 提交于 2019-12-20 07:33:01

问题


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.



来源:https://stackoverflow.com/questions/31775200/air-for-android-animation-causes-lagging-in-my-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!