예제 #1
0
    // Transitions between states are controlled by events
    @Override
    public boolean onGameEvent(GameEvent event) {
      switch (event.type) {
        case TouchedText:
          Log.d("Touched the text!");
          startAnimation();
          return true;

        case AnimationStarted:
          Log.d("AnimationStarted!");
          return true;

        case AnimationEnded:
          Log.d("AnimationEnded!");
          postUp(GameEvent.obtain(ResetStarted));
          return true;

        case ResetStarted:
          Log.d("ResetStarted!");
          reset();
          state = WaitForTouch;
          return true;

        case GameEvent.SEQUENCE_END:
          if (event.object == animation) endAnimation();
          return true;

        default:
          return false;
      }
    }
예제 #2
0
    // Choose the next animation sequence and start it
    void startAnimation() {
      Vec3 from = new Vec3();
      Vec3 to = new Vec3();

      int which = GameController.random.nextInt(6);
      Log.d("Picking animation %d", which);

      switch (which) {
        case 0:
          // Scale the text down to nothing
          animation = textNode.animateScale(2f, 0, 1000);
          break;
        case 1:
          // Scale the text up, and fade out at the same time
          animation = GameSequence.Parallel.obtain();
          animation.addNode(textNode.animateScale(1f, 5f, 1000));
          animation.addNode(textNode.animateAlpha(1f, 0f, 1000));
          break;
        case 2:
          // Rotate clockwise
          animation = textNode.animateAngle(0f, 360f, 1000);
          break;
        case 3:
          // Rotate counter-clockwise
          animation = textNode.animateAngle(360f, 0f, 1000);
          break;
        case 4:
          // Move the text to the top of the screen, and shrink it down
          // Once it's there, pause for a bit
          animation = GameSequence.Series.obtain();
          GameSequence par = GameSequence.Parallel.obtain();
          animation.addNode(par);
          to.set(center.x, (renderContext.height - 30), 0);
          par.addNode(textNode.animatePosition(to, 500));
          par.addNode(textNode.animateScale(1f, 0.5f, 500));

          GameSequence seq = GameSequence.obtain();
          seq.duration = 500;
          animation.addNode(seq);
          break;
        case 5:
          // Shake side to side
          animation = GameSequence.Series.obtain();
          float offset = 30f;
          to.set(center);

          from.set(center);
          to.x = center.x - offset;
          animation.addNode(textNode.animatePosition(from, to, 50));

          from.set(to);
          to.x = center.x + offset;
          animation.addNode(textNode.animatePosition(from, to, 70));

          from.set(to);
          to.x = center.x - offset;
          animation.addNode(textNode.animatePosition(from, to, 70));

          from.set(to);
          to.x = center.x + offset;
          animation.addNode(textNode.animatePosition(from, to, 70));

          break;
      }

      // Make the animation a child of this node, so this node
      // gets the notification.  Initially the animation is added as
      // a child of the TextNode (because of how the
      // TextNode.animate*() shortcut methods are defined), but TextNode
      // is a RenderNode and RenderNodes don't propogate events, so the
      // notification would never get here.
      addNode(animation);

      postUp(GameEvent.obtain(AnimationStarted));
    }