示例#1
0
  /**
   * @param x1 #start
   * @param y1 #start
   * @param x2 #end
   * @param y2 #end
   * @param numParticles #density
   */
  public void MakeFrontFire(int x1, int y1, int x2, int y2, int numParticles) {

    final Timeline fronttimeline = new Timeline();

    y2 = (int) (y2 - ((y2 - y1) * .8));
    for (int i = 0; i < numParticles; i++) {
      int size = CoreMath.rand(15, 20);
      int duration = (100 - size) * 10;
      int moveDistance = CoreMath.rand(1, 4 * size);
      double moveDirection = 180; // CoreMath.rand(0,5);
      int startX = x1 + i * (x2 - x1) / numParticles;
      int startY = y1 + i * (y2 - y1) / numParticles;
      int goalX = startX + (int) (moveDistance * Math.cos(moveDirection));
      int goalY = startY + (int) (moveDistance * Math.sin(moveDirection));

      CoreImage image = flame[CoreMath.rand(flame.length - 1)];
      Sprite sprite = new ImageSprite(image, startX, startY);
      sprite.setAnchor(.5, .5);

      sprite.setSize(size * 6, size * 2);
      sprite.alpha.set(50);
      scene.add(sprite);
      fronttimeline.animate(
          sprite.height, sprite.height.get(), sprite.width.get(), duration, Easing.REGULAR_OUT);
      fronttimeline.animateTo(sprite.x, goalX, duration, Easing.REGULAR_OUT);
      fronttimeline.animateTo(sprite.y, goalY, duration, Easing.REGULAR_OUT);
      fronttimeline.at(100).animateTo(sprite.alpha, 0, duration - 100, Easing.REGULAR_OUT);
      fronttimeline.add(new RemoveSpriteEvent(scene.getMainLayer(), sprite, duration));
    }

    scene.addTimeline(fronttimeline);
  }
示例#2
0
  /**
   * @param x1 #start
   * @param y1 #start
   * @param x2 #end
   * @param y2 #end
   */
  public void MakeFire(int x1, int y1, int x2, int y2) {

    final Timeline backtimeline = new Timeline();

    for (int i = 0; i < 1; i++) {
      int size = CoreMath.rand(25, 50);
      int duration = (100 - size) * 10;
      if (duration < 0) {
        duration = 10;
      }
      int moveDistance = CoreMath.rand(70, 150 - size);
      double moveDirection = 180; // CoreMath.rand(0);

      int startX = x1 + i * (x2 - x1);
      int startY = y1 + i * (y2 - y1);
      int goalX = startX + (int) (moveDistance * Math.cos(moveDirection));
      int goalY = startY + (int) (moveDistance * Math.sin(moveDirection));

      CoreImage image = flame[CoreMath.rand(flame.length - 1)];
      Sprite sprite = new ImageSprite(image, startX, startY);
      sprite.setAnchor(.5, .5);

      sprite.setSize(size, size);
      scene.add(sprite);
      scene.getMainLayer().moveToBottom(sprite);
      scene.getMainLayer().moveUp(sprite);
      backtimeline.animateTo(sprite.x, goalX, duration, Easing.REGULAR_OUT);
      backtimeline.animateTo(sprite.y, goalY, duration, Easing.REGULAR_OUT);
      backtimeline.at(100).animateTo(sprite.alpha, 0, duration - 100, Easing.REGULAR_OUT);
      backtimeline.add(new RemoveSpriteEvent(scene.getMainLayer(), sprite, duration));
    }

    scene.addTimeline(backtimeline);

    MakeFrontFire(x1, y1, x2, y2, 1);
  }
  @Override
  public void load() {
    // Add background and set up blend mode
    FilledSprite background;
    Group particleLayer = new Group();
    if (nextBlendMode == BlendMode.Add()) {
      background = new FilledSprite(prevBackgroundColor);
      background.fillColor.animateTo(BLACK, 500);
      particleLayer.setBlendMode(nextBlendMode);
      prevBackgroundColor = BLACK;
      nextBlendMode = BlendMode.Multiply();
    } else {
      background = new FilledSprite(prevBackgroundColor);
      background.fillColor.animateTo(WHITE, 500);
      particleLayer.setBlendMode(nextBlendMode);
      prevBackgroundColor = WHITE;
      nextBlendMode = BlendMode.Add();
    }
    add(background);
    particleLayer.alpha.set(0);
    addLayer(particleLayer);

    // Add particles
    for (int i = 0; i < particles; i++) {
      int[] x = new int[moves];
      int[] y = new int[moves];
      for (int j = 0; j < moves; j++) {
        x[j] = rand(border, Stage.getWidth() - border * 2);
        y[j] = rand(border, Stage.getHeight() - border * 2);
      }

      Timeline moveTimeline = new Timeline();
      Sprite sprite = makeParticle();
      particleLayer.add(sprite);

      int startTime = 0;
      for (int j = 0; j < moves; j++) {
        int lastX = x[j];
        int lastY = y[j];
        int newX = x[(j + 1) % moves];
        int newY = y[(j + 1) % moves];

        int dx = newX - lastX;
        int dy = newY - lastY;
        int moveDur = (int) (Math.sqrt(dx * dx + dy * dy) * 50);
        moveTimeline
            .at(startTime)
            .move(sprite, lastX, lastY, newX, newY, moveDur, Easing.ELASTIC_IN_OUT);
        startTime += moveDur;
      }
      moveTimeline.loopForever();
      addTimeline(moveTimeline);

      // Create 3 mirror objects
      Sprite mirror = makeParticle();
      mirror.x.bindTo(mirrorX(sprite));
      mirror.y.bindTo(mirrorY(sprite));
      particleLayer.add(mirror);

      mirror = makeParticle();
      mirror.x.bindTo(mirrorX(sprite));
      mirror.y.bindTo(sprite.y);
      particleLayer.add(mirror);

      mirror = makeParticle();
      mirror.x.bindTo(sprite.x);
      mirror.y.bindTo(mirrorY(sprite));
      particleLayer.add(mirror);
    }

    // Transition to the next blend mode
    int changeTime = 30000;
    Timeline timeline = new Timeline();
    timeline.at(500).animate(particleLayer.alpha, 0, 255, 2000);
    timeline.at(changeTime - 2500).animate(particleLayer.alpha, 255, 0, 2000);
    timeline.add(
        new TimelineEvent(changeTime) {
          public void run() {
            reload();
          }
        });
    addTimeline(timeline);
  }