スプライトアニメーションでキャラクターをアニメーションさせているため、Bitmapの数が多く1つのキャラクターに10つほどのBitmapを使用しています。
このキャラクターが1画面中に30体ほどでるゲームを作りたいのですが、非常に処理が重く10体ほど登場させただけでフレームレートが下がってしまいます。
初めて制作するAndroidゲームなので軽量化についてほとんど経験がないです。
どうしたら多くのbitmapを高速に描画できるでしょうか?
現在のソースコード、描画処理の一部を載せます。
//メインループ部分とマルチスレッドの描画処理(参考:dixq.net/Android/s02_01.html)
@Override
public void run() {
while (thread!=null) {
//前フレームのタッチ情報をコピー
notifyTouch.Mimicry(touch);
gameManager.SetTouch(notifyTouch);
//次の画面を取得
RunScrAdmin = RunScrAdmin.GetNextScreen(gameManager);
RunScrAdmin.Update(gameManager);
Draw(getHolder());
}
}
private void Draw(SurfaceHolder holder) {
Canvas c = holder.lockCanvas();
if(c == null)return;
c.drawColor(0x00000000, Mode.CLEAR);
RunScrAdmin.Draw(c,gameManager);
RunScrAdmin.ScreenChange(c,gameManager);
//c.drawRect(0, 0, 800, 480, apaint);
holder.unlockCanvasAndPost(c);
}
//SurfaceViewのDrawスレッドから呼ばれるメソッドで、フレームレートの低下の原因と思われる描画処理部分
public void Draw(Canvas canvas,GameManager gameManager,Object2D object2D){
Matrix matrix = new Matrix();//変数共有して軽くできるかも?
MotionNode motionNode;
Bitmap image;
if(motionList.getMotion(motion) != null){
//モーションの種類(歩くとかジャンプ).モーションのフレーム(連番).モーションのノード(1つの画像の座標とか角度)
//つまり現在のモーションの現在の時間に使うすべてのモーションのノードをループで描画します。
for(int i=0;i<motionList.getMotion(motion).getMotionFrame(animationTimeLine).getMotionNodeSize();i++){
//ノードは、描画順にソートされています
//つまりループ内で描画してもおk
//共有変数の設定
matrix.reset();
motionNode = motionList.getMotion(motion).getMotionFrame(animationTimeLine).getMotionNode(i);
image = gameManager.getBitmap(motionList.getImageID(motionNode.getRes_id()));
matrix.postScale(motionNode.getScale_x(),motionNode.getScale_y());
matrix.postRotate(motionNode.getAngle(),image.getWidth()/2,image.getHeight()/2);
matrix.postTranslate(motionNode.getX(), motionNode.getY());
//アニメーションできたら指定された場所へ移動
matrix.postTranslate(object2D.getX(), object2D.getY());
canvas.drawBitmap(image, matrix, gameManager.getFont());
}
}
}