1

分数是可绘制的图像

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){}
  }

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

4

1 回答 1

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

于 2013-08-15T05:49:26.700 回答