Exemplo n.º 1
0
 private void drawStatistic(Canvas canvas) {
   renderCount++;
   long diffTime = SystemClock.elapsedRealtime() - lastTime;
   if (diffTime > 1000) {
     speed = Math.round(renderCount * 1000f / diffTime);
     lastTime = SystemClock.elapsedRealtime();
     renderCount = 0;
   }
   canvas.drawText("FPS: " + speed, 30, 100, paintStatistics);
 }
Exemplo n.º 2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (moveAnimation.isActive() || explosionAnimation.isActive()) {
      return true;
    }
    if (event.getAction() != MotionEvent.ACTION_UP) {
      return true; // super.onTouchEvent(event);
    }
    int x = Math.round((event.getX() - dataHolder.getCellSize() / 2) / dataHolder.getCellSize());
    int y = Math.round((event.getY() - dataHolder.getCellSize() / 2) / dataHolder.getCellSize());
    if (x < 0
        || x >= dataHolder.getGameEngine().getGameField().getSizeX()
        || y < 0
        || y >= dataHolder.getGameEngine().getGameField().getSizeY()) {
      return super.onTouchEvent(event);
    } else {
      TouchResult results = dataHolder.getGameEngine().touchAction(x, y);
      switch (results) {
        case explode:
          startExplosion();
          break;

        case selected:
          startSelection();
          break;

        case no_action:
          if (selectionAnimation.isActive()) {
            selectionAnimation.stop();
            invalidate();
          }
          if (moveAnimation.isActive()) {
            moveAnimation.stop();
            invalidate();
          }
          break;
        default:
          break;
      }
    }
    return true;
  }