聞きたかったのですが、サーフェスビューでフレームごとのアニメーションを行う正しい方法は何ですか?
これが私がこれまでにしたことです...
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 程度です。それをスピードアップする方法はありますか?
ありがとう!