Esempio n. 1
0
  @Override
  public void draw(Batch batch, float parentAlpha) {
    validate();

    Color color = getColor();

    Drawable handle = style.handle;
    applyTransform(batch, computeTransform());
    Matrix4 transform = batch.getTransformMatrix();
    if (firstWidget != null) {
      getStage().calculateScissors(firstWidgetBounds, firstScissors);
      if (ScissorStack.pushScissors(firstScissors)) {
        if (firstWidget.isVisible()) firstWidget.draw(batch, parentAlpha * color.a);
        batch.flush();
        ScissorStack.popScissors();
      }
    }
    if (secondWidget != null) {
      getStage().calculateScissors(secondWidgetBounds, secondScissors);
      if (ScissorStack.pushScissors(secondScissors)) {
        if (secondWidget.isVisible()) secondWidget.draw(batch, parentAlpha * color.a);
        batch.flush();
        ScissorStack.popScissors();
      }
    }
    batch.setColor(color.r, color.g, color.b, parentAlpha * color.a);
    handle.draw(batch, handleBounds.x, handleBounds.y, handleBounds.width, handleBounds.height);
    resetTransform(batch);
  }
Esempio n. 2
0
  private void drawRecursive(Actor actor) {
    if (!invisibleActors && !actor.isVisible()) return;

    if (allActors) actor.debug();

    if (actor.getDebug()) {
      actor.getDebugRects(debugRects);
      for (DebugRect debugRect : debugRects) drawRect(actor, debugRect);
      debugRects.clear();
      debugRectPool.freeAll(usedRects);
      usedRects.clear();
    }

    boolean draw = true;
    Rectangle scissorBounds = null;
    if (actor instanceof Group) scissorBounds = ((Group) actor).getScissorBounds();
    if (scissorBounds != null) {
      shapes.flush();
      draw = ScissorStack.pushScissors(scissorBounds);
    }
    if (draw) {
      // Children are still rendered, even if the group has no debugging enabled.
      if (actor instanceof Group) {
        Group group = (Group) actor;
        for (Actor child : group.getChildren()) drawRecursive(child);
      }

      if (scissorBounds != null) {
        shapes.flush();
        ScissorStack.popScissors();
      }
    }
  }
Esempio n. 3
0
  @Override
  public void renderContent(@NtN Batch batch, @NtN Vector2 pos, @NtN Vector2 size) {
    batch.flush();
    ScissorStack.pushScissors(new Rectangle(pos.x, pos.y, size.x, size.y));

    checkGlyphLayout(size);
    float yOffset =
        (font.getLineHeight() - font.getAscent() - font.getCapHeight() - font.getDescent()) / 2;
    font.draw(
        batch, glyphLayout, pos.x, pos.y + size.y - yOffset + currentLine * font.getLineHeight());

    batch.flush();
    ScissorStack.popScissors();
  }
Esempio n. 4
0
  protected void renderGame() {

    Gdx.gl.glClearDepthf(1f);
    Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);

    // Clearing screen, positioning camera, rendering map and entities
    // Positioning camera to the player
    Specular.camera.zoom = 1;
    Camera.setPosition();
    Specular.camera.update();

    // Rendering map and entities
    game.batch.setProjectionMatrix(Specular.camera.combined);
    game.batch.begin();

    game.batch.setColor(1, 1, 1, 1);
    game.batch.draw(
        currentMap.getParallax(),
        -1024 + Camera.getCameraX() / 2,
        -1024 + Camera.getCameraY() / 2,
        4096,
        4096);
    game.batch.setColor(1, 1, 1, 1);

    Camera.setZoom();
    BoardShock.setZoom();

    Specular.camera.update();
    game.batch.setProjectionMatrix(Specular.camera.combined);

    currentMap.render(game.batch, true);

    ScissorStack.calculateScissors(
        Specular.camera, game.batch.getTransformMatrix(), clipBounds, scissors);
    ScissorStack.pushScissors(scissors);

    if (tutorialOnGoing && tutorial.getCurrentWave().getEvent() == TutorialEvent.POWER_UPS_SHOWN) {
      if (!tutorial.enemiesHasSpawned()) {
        Util.writeCentered(
            game.batch,
            tutorial.getFont(),
            "these are power-ups",
            tutorial.getTextX(),
            tutorial.getTextY() + 200);

        if (tutorial.allPowerUpsActivated())
          Util.writeCentered(
              game.batch,
              tutorial.getFont(),
              "some can be combined",
              tutorial.getTextX(),
              tutorial.getTextY());
      }
    }

    for (Entity ent : entities) {
      if (!(ent instanceof Enemy)) ent.render(game.batch);
    }

    game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

    for (UpgradeOrb orb : orbs) orb.render(game.batch);

    for (Particle p : particles) p.render(game.batch);

    game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    for (Entity ent : enemies) {
      ent.render(game.batch);
    }

    if (!gameMode.isGameOver()) player.render(game.batch);

    game.batch.flush();
    ScissorStack.popScissors();

    // Re-positioning camera for HUD
    Specular.camera.position.set(0, 0, 0);
    Specular.camera.zoom = 1;
    Specular.camera.update();
    game.batch.setProjectionMatrix(Specular.camera.combined);

    if (isPaused) { // Pause menu
      game.batch.draw(
          greyPixel,
          -Specular.camera.viewportWidth / 2,
          -Specular.camera.viewportHeight / 2,
          Specular.camera.viewportWidth,
          Specular.camera.viewportHeight);
      game.batch.draw(pauseTex, -pauseTex.getWidth() / 2, 100);
      pauseInputProcessor.getResumeButton().render();
      pauseInputProcessor.getToMenuButton().render();
    } else {
      if (!gameMode.isGameOver()) {
        // Drawing HUD
        hud.render(game.batch, scoreMultiplierTimer);
        gameInputProcessor.getShootStick().render(game.batch);
        gameInputProcessor.getMoveStick().render(game.batch);

        // Tutorial
        if (tutorialOnGoing && !showTutorialEnd) tutorial.render(game.batch);

        // Drawing SCORE in the middle top of the screen
        Util.writeCentered(
            game.batch,
            scoreFont,
            player.getFormattedScore(),
            0,
            Specular.camera.viewportHeight / 2 - 36);
        // Drawing MULTIPLIER on screen
        Util.writeCentered(
            game.batch,
            multiplierFont,
            "x" + Math.round(scoreMultiplier),
            0,
            Specular.camera.viewportHeight / 2 - 98);

        // Tutorial end
        if (showTutorialEnd) {
          tutorialTicks++;

          if (tutorialTicks > 120) {
            scoreFontAlpha = (tutorialTicks - 120) / 180f;
            scoreFontAlpha = scoreFontAlpha > 1 ? 1 : scoreFontAlpha;

            game.batch.setColor(1, 1, 1, scoreFontAlpha);
            game.batch.draw(
                greyPixel,
                -Specular.camera.viewportWidth / 2,
                -Specular.camera.viewportHeight / 2,
                Specular.camera.viewportWidth,
                Specular.camera.viewportHeight);
            game.batch.setColor(Color.WHITE);

            scoreFont.setColor(1, 0, 0, scoreFontAlpha);
            Util.writeCentered(game.batch, scoreFont, "tap to continue", 0, -100);
          }
        }

        gameMode.render(game.batch);
      } else if (gameMode.isGameOver()) { // Game over screen
        // Manual camera shake
        Specular.camera.position.set(0, 0, 0);
        Specular.camera.position.add(
            rand.nextFloat() * 100 * Camera.getShakeIntensity(),
            rand.nextFloat() * 100 * Camera.getShakeIntensity(),
            0);
        Specular.camera.update();
        game.batch.setProjectionMatrix(Specular.camera.combined);

        game.batch.draw(
            greyPixel,
            -Specular.camera.viewportWidth / 2,
            -Specular.camera.viewportHeight / 2,
            Specular.camera.viewportWidth,
            Specular.camera.viewportHeight);
        game.batch.draw(gameOverTex, -gameOverTex.getWidth() / 2, -gameOverTex.getHeight() / 2);

        // Game Over effects [fade in, camera shake]
        if (gameOverScoreFont.getScaleX() > 1f) {
          gameOverScoreFont.scale(-0.1f);
          gameOverScoreFont.setColor(
              1, 0, 0, Math.max((10 - gameOverScoreFont.getScaleX()) / 10f, 0));
        } else {
          gameOverScoreFont.setScale(1);
          if (!shaken) {
            Camera.shake(0.5f, 0.02f);
            shaken = true;
          }

          if (player.getScore() >= lastHighscore) {
            Util.drawCentered(game.batch, newHighscore, 0, 0, 0);
            lastHighscore = player.getScore();
          }
        }

        // Drawing final score and buttons
        if (music != null) music.setVolume(0.25f);
        if (gameOverTicks == GAMEOVERSOUND_TIMER && isSoundEnabled()) {
          gameOverSound.play(1f, 1, 0);
        }
        Util.writeCentered(game.batch, gameOverScoreFont, player.getFormattedScore(), 0, 100);

        game.batch.setColor(Color.WHITE);
        ggInputProcessor.getRetryBtn().render();
        ggInputProcessor.getMenuBtn().render();
        ggInputProcessor.getHighscoreBtn().render();

        if (player.getUpgradePoints() >= 1) {
          if (!ggInputProcessor.isTouchingUpgradeBtn()) {
            if (gameOverTicks % 90 < 40) {
              ggInputProcessor.getUpgradeBtn().setScale(1.00f);
              ggInputProcessor.getUpgradeBtn().setTouch(true);
            } else {
              ggInputProcessor.getUpgradeBtn().setScale(1.0f);
              ggInputProcessor.getUpgradeBtn().setTouch(false);
            }
          }
        }

        ggInputProcessor.getUpgradeBtn().render();
      }
    }

    game.batch.end();
  }
Esempio n. 5
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    if (widget == null) return;

    validate();

    // Setup transform for this group.
    applyTransform(batch, computeTransform());

    if (scrollX)
      hKnobBounds.x =
          hScrollBounds.x + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
    if (scrollY)
      vKnobBounds.y =
          vScrollBounds.y
              + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));

    // Calculate the widget's position depending on the scroll state and available widget area.
    float y = widgetAreaBounds.y;
    if (!scrollY) y -= (int) maxY;
    else y -= (int) (maxY - visualAmountY);

    if (!fadeScrollBars && scrollbarsOnTop && scrollX) {
      float scrollbarHeight = 0;
      if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
      if (style.hScroll != null)
        scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
      y += scrollbarHeight;
    }

    float x = widgetAreaBounds.x;
    if (scrollX) x -= (int) visualAmountX;
    widget.setPosition(x, y);

    if (widget instanceof Cullable) {
      widgetCullingArea.x = -widget.getX() + widgetAreaBounds.x;
      widgetCullingArea.y = -widget.getY() + widgetAreaBounds.y;
      widgetCullingArea.width = widgetAreaBounds.width;
      widgetCullingArea.height = widgetAreaBounds.height;
      ((Cullable) widget).setCullingArea(widgetCullingArea);
    }

    // Caculate the scissor bounds based on the batch transform, the available widget area and the
    // camera transform. We need to
    // project those to screen coordinates for OpenGL ES to consume.
    getStage().calculateScissors(widgetAreaBounds, scissorBounds);

    // Draw the background ninepatch.
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight());
    batch.flush();

    // Enable scissors for widget area and draw the widget.
    if (ScissorStack.pushScissors(scissorBounds)) {
      drawChildren(batch, parentAlpha);
      ScissorStack.popScissors();
    }

    // Render scrollbars and knobs on top.
    batch.setColor(
        color.r,
        color.g,
        color.b,
        color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds));
    if (scrollX && scrollY) {
      if (style.corner != null) {
        style.corner.draw(
            batch,
            hScrollBounds.x + hScrollBounds.width,
            hScrollBounds.y,
            vScrollBounds.width,
            vScrollBounds.y);
      }
    }
    if (scrollX) {
      if (style.hScroll != null)
        style.hScroll.draw(
            batch, hScrollBounds.x, hScrollBounds.y, hScrollBounds.width, hScrollBounds.height);
      if (style.hScrollKnob != null)
        style.hScrollKnob.draw(
            batch, hKnobBounds.x, hKnobBounds.y, hKnobBounds.width, hKnobBounds.height);
    }
    if (scrollY) {
      if (style.vScroll != null)
        style.vScroll.draw(
            batch, vScrollBounds.x, vScrollBounds.y, vScrollBounds.width, vScrollBounds.height);
      if (style.vScrollKnob != null)
        style.vScrollKnob.draw(
            batch, vKnobBounds.x, vKnobBounds.y, vKnobBounds.width, vKnobBounds.height);
    }

    resetTransform(batch);
  }
Esempio n. 6
0
  @Override
  public void draw(Batch batch, float parentAlpha) {
    oldPro.set(batch.getProjectionMatrix());
    oldView.set(batch.getTransformMatrix());

    Rectangle temp = null;
    if (useFbo) {
      batch.end();
      try {
        // problem with libgdx, should'nt need try catch.
        temp = ScissorStack.popScissors();
      } catch (IllegalStateException ignored) {
      }
      fbo.begin();
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    }

    // camera.setX(camera.getX()+1);
    // camera.setRotation(camera.getRotation()+2);

    camera.track(view);
    camera.apply(ortho);
    ortho.update();
    batch.setProjectionMatrix(ortho.projection);
    batch.setTransformMatrix(ortho.view);

    if (useFbo) {
      batch.begin();
    }

    Iterator<PObject> iter = view.getIterator();
    while (iter.hasNext()) {
      PSprite sprite = (PSprite) iter.next();
      sprite.draw(batch, spriteReference);
    }

    if (useFbo) {
      batch.end();
      fbo.end();
    }

    batch.setProjectionMatrix(oldPro);
    batch.setTransformMatrix(oldView);

    if (useFbo) {
      if (temp != null) {
        ScissorStack.pushScissors(temp);
      }

      Color oldColor = batch.getColor();
      batch.setColor(tint);
      batch.begin();

      batch.draw(
          fbo.getColorBufferTexture(),
          0,
          0,
          getWidth(),
          getHeight(),
          0,
          0,
          fbo.getWidth(),
          fbo.getHeight(),
          false,
          true);

      batch.setColor(oldColor);
    }
  }