0

現在、私はライブ壁紙に取り組んでおり、ある時点で立ち往生しています。実際、私のライブ壁紙は画面をタッチしたときだけ機能しますが、連続して変化するわけではありません。私のループに問題があります。

class Diwali extends Engine  {
    private boolean mVisible;

    private final Runnable diwaliImg = new Runnable() {
        public void run() {
            drawFrame();
        }
    };

    int i=0;
    int[] pirates = {
        R.drawable.a1, R.drawable.a2,
        R.drawable.a3, R.drawable.a4,
        R.drawable.a5, R.drawable.a6,
        R.drawable.a7, R.drawable.a8,
        R.drawable.a9, R.drawable.a10,
        R.drawable.a11, R.drawable.a12,
        R.drawable.a13, R.drawable.a14
    };

    @Override
    public void onCreate(SurfaceHolder holder){
        super.onCreate(holder);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mHandler.removeCallbacks(diwaliImg);
    }

    @Override
    public void onVisibilityChanged(boolean visible) {
        mVisible = visible;
        if (visible) {
            drawFrame();
        } else {
            mHandler.removeCallbacks(diwaliImg);
        }
    }

    @Override
    public void onSurfaceChanged(SurfaceHolder holder, int format,
            int width, int height) {
        super.onSurfaceChanged(holder, format, width, height);
        drawFrame();    
    }

    @Override
    public void onSurfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        super.onSurfaceCreated(holder);
    }

    @Override
    public void onSurfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
        super.onSurfaceDestroyed(holder);
        mVisible = false;
        mHandler.removeCallbacks(diwaliImg);
    }


    @Override
    public void onOffsetsChanged(float xOffset, float yOffset, float xStep,float yStep, int xPixels, int yPixels) {
        drawFrame();
    }

    @Override
    public void onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
    }

    private void drawFrame() {
        // TODO Auto-generated method stub
        final SurfaceHolder holder = getSurfaceHolder();
        Canvas c = null;
        try {
            c = holder.lockCanvas();
            if (c != null) {
                drawPirate(c);
            }
        } finally {
            if (c != null)
                holder.unlockCanvasAndPost(c);
        }
        mHandler.removeCallbacks(diwaliImg);
    }

    private void drawPirate(Canvas c) {
        // TODO Auto-generated method stub
        Bitmap icon = BitmapFactory.decodeResource(getResources(),pirates[i]);

        i++;

        if (i == 13) {
            i = 0;
        }
        Matrix matrix = new Matrix();

        c.drawBitmap(icon, matrix, null);
        icon.recycle();
    }
}
4

2 に答える 2