2014-06-15 2 views
0

캐릭터 워킹 애니메이션의 프레임과 동일한 크기의 17 비트 맵을 가지고 있으며 코드에 루프를 넣길 원합니다. 나는 같은 비트 맵을 재사용하고 있기 때문에 inBitmap을 사용할 수 있기를 원한다. 그래서 어떻게하면Android java : 효율적인 비트 맵 애니메이션 할당

  1. 내가/I는 비트 맵을 캐시하고해야 할 수 있습니다 나는이 일에 대해 몇 가지 질문이?

  2. 더 효율적인 메모리 사용 방법은 무엇입니까?

내 코드는 다음과 같습니다 (나는 사용자 정의보기를 그릴 사용하고 있습니다)

에서 onCreate :

 bitmapOptions.inJustDecodeBounds = true; 
     BitmapFactory.decodeResource(getResources(), R.drawable.walk0, bitmapOptions); 
     aBitmap = Bitmap.createBitmap(bitmapOptions.outWidth, 
       bitmapOptions.outHeight, Bitmap.Config.ARGB_8888); 
     bitmapOptions.inJustDecodeBounds = false; 
     bitmapOptions.inBitmap = aBitmap; 
     bitmapOptions.inSampleSize = 1; 
     BitmapFactory.decodeResource(getResources(), R.drawable.walk0, bitmapOptions); 
     ship = Bitmap.createBitmap(aBitmap, 0, 0, aBitmap.getWidth(), aBitmap.getHeight(), shipMatrix, true); 

된 onDraw :

@Override 
protected void onDraw(Canvas canvas) 
{ 
shipRectf.right = ship.getWidth(); 
shipRectf.left = 0; 
shipRectf.top = 0; 
shipRectf.bottom = ship.getHeight(); 
canvas.drawBitmap(ship, null, shipRectf, null); 
} 

에 애니메이션 :

Runnable walkData = new Runnable() 
    { 
     public void run(){ 
      try{  

       BitmapFactory.Options shipOptions = null; 
       shipOptions = bitmapOptions; 

       if(shipOptions != null){ 
       shipOptions.inBitmap = aBitmap; 
       } 
      if(walkAnim==true) 
       { 
        walkNum = (walkNum + 1) % imageIDs.length; 
        //walknum = index, imageids = int[] {R.drawables} 
        aBitmap = BitmapFactory.decodeResource(getResources(), imageIDs[walkNum], shipOptions); 
        ship = Bitmap.createBitmap(aBitmap, 0, 0, aBitmap.getWidth(), aBitmap.getHeight(), shipMatrix, true); 
              invalidate(); 

       } 
       if(walkAnim==false) 
       { 
        walkNum = 0; 
        ship = BitmapFactory.decodeResource(getResources(), imageIDs[walkNum], shipOptions); 
       } 


      handler3.postDelayed(this, 50); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
    }; 
+0

애니메이션 드로어 블을 사용해 보셨습니까 ?? –

+0

은 imageviews에 해당하지 않습니까? – stegrd

+0

예 이미지 뷰 용 –

답변

0

런타임에 비트 맵을로드하면 결국 속도가 느려집니다.

내가하는 일은 게임을 만들 때 모든 비트 맵을로드하고 배열에 저장하는 것입니다. 그리기 할 때 비트 맵 배열을 참조하고 현재 프레임의 올바른 이미지를 얻습니다. 더 많은 메모리를 사용하지만 더 빠른 런타임을 위해서는 항상 트레이드 오프입니다.

+0

각 비트 맵을로드하기 위해 inbitmap을 사용할 수 없습니까? – stegrd

+0

나는 당신이 어떻게 의미하는지 정확하게 모르겠습니다. 이렇게하면 이전 비트 맵을 덮어 쓰게되므로 다음 프레임을 원할 때 리소스에서 다시로드해야합니다. –