Exemplo n.º 1
0
  @Override
  public void render() {
    Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    if (Gdx.input.isTouched()) {
      stage.screenToStageCoordinates(stageCoords.set(Gdx.input.getX(), Gdx.input.getY()));
      Actor actor = stage.hit(stageCoords.x, stageCoords.y, true);
      if (actor instanceof Image)
        ((Image) actor)
            .setColor(
                (float) Math.random(),
                (float) Math.random(),
                (float) Math.random(),
                0.5f + 0.5f * (float) Math.random());
    }

    Array<Actor> actors = stage.getActors();
    int len = actors.size;
    if (rotateSprites) {
      for (int i = 0; i < len; i++) actors.get(i).rotateBy(Gdx.graphics.getDeltaTime() * 10);
    }

    scale += vScale * Gdx.graphics.getDeltaTime();
    if (scale > 1) {
      scale = 1;
      vScale = -vScale;
    }
    if (scale < 0.5f) {
      scale = 0.5f;
      vScale = -vScale;
    }

    len = images.size();
    for (int i = 0; i < len; i++) {
      Image img = images.get(i);
      if (rotateSprites) img.rotateBy(-40 * Gdx.graphics.getDeltaTime());
      else img.setRotation(0);

      if (scaleSprites) {
        img.setScale(scale);
      } else {
        img.setScale(1);
      }
      img.invalidate();
    }

    stage.draw();

    renderer.begin(ShapeType.Point);
    renderer.setColor(1, 0, 0, 1);
    len = actors.size;
    for (int i = 0; i < len; i++) {
      Group group = (Group) actors.get(i);
      renderer.point(group.getX() + group.getOriginX(), group.getY() + group.getOriginY(), 0);
    }
    renderer.end();

    fps.setText(
        "fps: "
            + Gdx.graphics.getFramesPerSecond()
            + ", actors "
            + images.size()
            + ", groups "
            + actors.size);
    ui.draw();
  }
Exemplo n.º 2
0
  public HandGroup(GameEventNotifier notifier) {
    super(notifier);

    cards = new Group();
    cards.setBounds(0, 0, UIConstants.WORLD_WIDTH, UIConstants.WORLD_HEIGHT / 2);

    addActor(cards);

    // set up the images and buttons for the zoom menu
    selectButton = new Image(selectTexture);
    selectButton.setScale(1.5f);
    selectButton.setPosition(220, 700);
    cancelButton = new Image(cancelTexture);
    cancelButton.setScale(1.5f);
    cancelButton.setPosition(220, 100);
    cancelButton.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            // return the zoomed card
            unzoom();
            return true;
          }
        });
    nextCardImage = new Image(arrowTexture);
    nextCardImage.setScale(2f);
    nextCardImage.setPosition(1200, 300);
    nextCardImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            changeZoomedCard(1);
            return true;
          }
        });

    previousCardImage = new Image(arrowTexture);
    previousCardImage.rotateBy(180);
    previousCardImage.setScale(2f);
    previousCardImage.setPosition(500, 400);
    previousCardImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            changeZoomedCard(-1);
            return true;
          }
        });
    rotateImage = new Image(rotateTexture);
    rotateImage.setScale(0.5f);
    rotateImage.setPosition(350, 500);
    rotateImage.addListener(
        new InputListener() {
          @Override
          public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            zoomCard.rotate();
            return true;
          }
        });
    zoomGroup = new Group();
    zoomGroup.addActor(selectButton);
    zoomGroup.addActor(cancelButton);
    zoomGroup.addActor(nextCardImage);
    zoomGroup.addActor(previousCardImage);
    zoomGroup.addActor(rotateImage);
    zoomGroup.setTouchable(Touchable.disabled);
    zoomGroup.setVisible(false);

    addActor(zoomGroup);
  }