Hi all! I want to do an animation using a drawable and a surface view. I've tried with a View, but actually it runs really slow, so i tested with surface view, but i can see no changes (as slow as using a view). What i do is:
set a PolyToPoly matrix concat that matrix draw a bitmap and repeat that until the animation has stopped. This is the code: private void doDraw(Canvas canvas) { Paint paint = mPaint; canvas.drawColor(Color.BLACK); canvas.save(); canvas.translate(getWidth() / 2, 20); canvas.restore(); if (isTurningLeft) { doDrawLeft(canvas, new float array); flipLeft(); } else if (isTurningRight) { doDrawRight(canvas, new float array); flipRight(); } else { doDrawStable(canvas); } } private void doDrawStable(Canvas canvas) { canvas.save(); canvas.drawBitmap(_bd, null, new RectF(0, 0, 160, 240), mPaint); canvas.restore(); } private void doDrawLeft(Canvas canvas, float dst[]) { canvas.save(); mMatrix.setPolyToPoly(initPos, 0, dst, 0, dst.length >> 1); canvas.concat(mMatrix); canvas.drawBitmap(_bd, null, new RectF(0, 0, 160, 240), mPaint); canvas.restore(); } private void doDrawRight(Canvas canvas, float dst[]) { canvas.save(); mMatrix.setPolyToPoly(initPos, 0, flippedPos, 0, dst.length >> 1); canvas.concat(mMatrix); mMatrix.setPolyToPoly(flippedPos, 0, dst, 0, dst.length >> 1); canvas.concat(mMatrix); canvas.drawBitmap(_bd, null, new RectF(0, 0, 160, 240), mPaint); canvas.restore(); } public void flipLeft() { //set new values to x,y,i //stop the animation if we have finished } public void flipRight() { //set new values to x,y,i //stop the animation if we have finished } Finally, we have this inside the thread: @Override public void run() { while (mRun) { Canvas c = null; try { c = mSurfaceHolder.lockCanvas(null); synchronized (mSurfaceHolder) { doDraw(c); } } finally { // do this in a finally so that if an exception is thrown // during the above, we don't leave the Surface in an // inconsistent state if (c != null) { mSurfaceHolder.unlockCanvasAndPost(c); } } } } It runs really slow!! Am I missing something? Any help is much appreciated :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---