2011-10-24 25 views
0

私はスクロール(ジェスチャー)のパフォーマンスがかなり悪い場合は、400 +回を使用して、各フレーム関数drawBitmapでcanvas.drawBitmap()関数を使用する描画タイルベースのゲームを開発する。Androidタイルベースのゲーム

誰でも私にスムーズなアニメーションをさせるためにパフォーマンスを上げる方法をアドバイスできますか?

public class DiamondIsometric implements Render{ 
    private int MapWidth; 
    private int MapHeight; 
    private Bitmap _surface; 
    private Bitmap tempBitmap; 
    public DiamondIsometric(int MapWidth,int MapHeight,Bitmap _surface) 
    { 
     this.MapWidth=MapWidth; 
     this.MapHeight=MapHeight; 
     this._surface = _surface; 
    } 
    public MapObject[][] BuildMap() 
    { 
     int rx; 
     int ry; 
     MapObject[][] MapObjects = new MapObject[MapWidth][MapHeight]; 
     for(int x=0;x<MapHeight;x++) 
      for(int y=0;y<MapWidth;y++) 
      { 
       rx=(x-y)*_surface.getWidth()/2; 
       ry=(x+y)*_surface.getHeight()/2; 
       MapObject temp = new MapObject(new Point(rx,ry),_surface);    
       MapObjects[x][y]=temp;    
      } 
     return MapObjects;  
    } 

    @Override 
    public void Render(Canvas canvas) {  
    } 
    @Override 
    public void Render(Canvas canvas,MapObject[][] MapObjects) 
    { 
     Paint temp = new Paint(); 
     temp.setColor(Color.BLACK); 
     canvas.drawPaint(temp); 
     Bitmap toDraw = Bitmap.createBitmap(MapWidth*_surface.getWidth(), MapHeight*_surface.getHeight(), Config.RGB_565); 
     int bitmapOffsetX,bitmapOffsetY; 
     canvas.drawBitmap(this.Render2(canvas,MapObjects),0,0,null); 

    } 
    public Bitmap Render2(Canvas canvas, MapObject[][] MapObjects) 
    { 
     Paint temp = new Paint(); 
     temp.setColor(Color.BLACK); 
     tempBitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Config.RGB_565); 
     Canvas wideBMPCanvas = new Canvas(tempBitmap); 
     int bitmapOffsetX,bitmapOffsetY; 
     for(int i=0;i<MapObjects.length;i++) 
      for(int j=0;j<MapObjects[i].length;j++) 
      { 
       bitmapOffsetX=(IsometricView.globalAnchor.x % MapObjects[i][j]._bitmap.getWidth()); 
       bitmapOffsetY=(IsometricView.globalAnchor.y % MapObjects[i][j]._bitmap.getHeight()); 
       wideBMPCanvas.drawBitmap(MapObjects[i][j]._bitmap,MapObjects[i][j].coords.x-IsometricView.globalAnchor.x ,MapObjects[i][j].coords.y-IsometricView.globalAnchor.y , null); 

      } 
     return tempBitmap; 
    } 

} 
+0

いくつかのコードを入れてください... –

+0

私はコード – gingray

答えて

1

andEngineまたはlibgdxのようなゲームエンジンを使用してください。彼らは通常、はるかに高速なOpenGLレンダリングを使用します。

更新:OpenGL /ゲームエンジンを使用しない場合は、タイルをより大きなビットマップに結合するようにしてください。より大きなビットマップを作成し、新しいキャンバス(新しいCanvas(largeBitmap))を作成して、それにタイルを描画します。 1つ大きい描画は、複数の小さな描画よりも高速です。私のゲームではK'UMPA私は同様のアプローチを使用しました。これは、画面上の小さな部分だけが画面に表示されるため、より複雑です。

+0

を投稿しましたか?パフォーマンスを向上させる別の方法があるのでしょうか? – gingray

+0

drawBitmapを使用してソフトウェアレンダリングをしたい場合に備えて、答えを更新しました。 –

関連する問題