如何使用android中的运动动画化Bitmap图像

时间:2013-08-15 05:40:20

标签: android

  

分数是一个可绘制的图像

private Bitmap Scores;
private boolean running =true;
private SurfaceView mySurfaceHolder;
Scores.decodeResource(myContext.getResource(), R.drawable.score);

//this is just the run procedure
@Override 
public void onRun()
{
   while(running){

       Canvas c = null;
     try{
         c = mySurfaceHolder.lockCanvas(null);
              synchronize(mySurfaceHolder){           
                        drawScore(c);  //here is where i call my method..
              }
      }finally{
         mySurfaceHolder.unlockCanvasAndPost(c);

  }

}

  //the pontsGain and onTitle are both boolean variables so please don't get confuse
  //and pointScoreAtY is an integer that will allocate my specific position in screen
  private void drawScore(Canvas c)
  {
      try{
          if(pointsGain && !onTitle)
        {
              pointScoreAtY = (int)(FingerY -(Scores.getHeight()/2)-100);

              int i=100;
            do{
            try{

                c.drawBitmap(Scores, (FingerX -(Scores.getWidth()/2))+200,pointScoreAtY, null);
                invalidate();
                 pointScoreAtY -=i;

            }catch(Exception e){}
            }while(i-->0);
            pointsGain = false;
        }
      }catch(Exception e){}
  }
  

这个特定的功能是在当前位置的屏幕上绘制位图,但它不是我想要做的...例如我的主要目标是当我的游戏中的角色被击中时我想要显示得分点和动画它,使它可以上升并从屏幕上消失。

1 个答案:

答案 0 :(得分:0)

您可以像这样添加动画到imageview:

TranslateAnimation anim = new TranslateAnimation( 0, xDest - originalPos[0] , 0, yDest - originalPos[1] );
    anim.setDuration(1000);
    anim.setFillAfter( true );
    view.startAnimation(anim);

有关更多动画详情,请查看android开发者网站: http://developer.android.com/training/animation/index.html