0
표면 뷰에서 프레임 별 애니메이션을 수행하는 올바른 방법은 무엇입니까?Surfaceview의 프레임 별 애니메이션
여기
class MySurfaceView extends SurfaceView implements Runnable{
Thread thread = null;
SurfaceHolder surfaceHolder;
volatile boolean running = false;
Bitmap bitMap;
int i = 1;
public MySurfaceView(Context context)
{
super(context);
surfaceHolder = getHolder();
bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y1);
final CountDownTimer t = new CountDownTimer(75000,50)
{
@Override
public void onFinish() {
}
@Override
public void onTick(long millisUntilFinished) {
i++;
if (i >= 26) { i = 1; }
if (i == 1) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y1); }
else if (i == 2) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y2); }
else if (i == 3) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y3); }
else if (i == 4) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y4); }
else if (i == 5) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y5); }
else if (i == 6) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y6); }
else if (i == 7) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y7); }
else if (i == 8) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y8); }
else if (i == 9) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y9); }
else if (i == 10) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y10); }
else if (i == 11) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y11); }
else if (i == 12) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y12); }
else if (i == 13) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y13); }
else if (i == 14) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y14); }
else if (i == 15) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y15); }
else if (i == 16) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y16); }
else if (i == 17) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y17); }
else if (i == 18) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y18); }
else if (i == 19) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y19); }
else if (i == 20) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y20); }
else if (i == 21) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y21); }
else if (i == 22) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y22); }
else if (i == 23) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y23); }
else if (i == 24) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y24); }
else if (i == 25) { bitMap = BitmapFactory.decodeResource(getResources(), R.drawable.y25); }
}
}.start();
running = true;
thread = new Thread(this);
thread.start();
}
//////////////////////////////////////////////////////////
public void run() {
while(running){
if(surfaceHolder.getSurface().isValid()){
Canvas canvas = surfaceHolder.lockCanvas();
if (canvas == null) { Log.e("null","n"); } else
{
/////
canvas.drawBitmap(bitMap, 0, 0, null);
/////
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
//////////////////////////////////////////////////////////
...
는 적어도 그것은 충돌 또는 VM 버퍼를 초과하지 않고 재생하지만, 프레임 속도는 아마 약 5 ~ 10 FPS, 매우 낮은 ... 내가 지금까지 무슨 짓을했는지. 속도를 높이는 방법이 있습니까?
감사합니다.
아니, 좋지 않은 아이디어 :) java.lang.OutOfMemoryError : 비트 맵 크기가 VM 예산을 초과합니다. –
당신은 약간의 해상도를 희생해야하거나 당신이 가진 것보다 당신의 프레임 속도를 향상시킬 배치 (예 : 4 개의 Atlases)에 대해 언급 한 것을 할 수 있습니다. 또한 사이드 노트, 에뮬레이터에서 프레임 속도를 측정하지 마십시오. 매우 느립니다. –
각 프레임은 480x800 크기의 전체 화면이므로 제안한대로 배치에 대해 생각해야합니다. 나는 전화로 테스트하고 있는데 여전히 꽤 느리다. –