Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with drawing HUD. #38

Open
unlishema opened this issue Aug 12, 2020 · 0 comments
Open

Bug with drawing HUD. #38

unlishema opened this issue Aug 12, 2020 · 0 comments

Comments

@unlishema
Copy link

unlishema commented Aug 12, 2020

Everything works great except if you resize the window. When you resize the window, it doesn't update the viewport width and height. This causes an issue when writing a HUD that is resizable based on window size. This isn't a hard fix but I don't know about for fixing in PeasyCam exactly.

Running the following:
OS: Windows 7 Professional 32 bit
Processing Version: 3.5.4
Processing Mode: java

Here is an example showing the issue as well as the fix. It opens with the bug and then if you resize you will see what the bug does. Then just press the "f" to apply or remove the fix.

import peasy.*;

PeasyCam camera;

int w = 0, h = 0;
boolean fixApplied = false;

void setup() {
  size(600, 600, P3D);
  surface.setResizable(true);
  this.camera = new PeasyCam(this, 500);
  registerMethod("pre", this);
}

void pre() {
  // HUD Fix... When fix is applied and width or height has changed
  if (this.fixApplied && (this.w != this.width || this.h != this.height)) {
    this.w = this.width;
    this.h = this.height;
    this.camera.setViewport(0, 0, this.w, this.h);
    this.camera.reset();
  }
}

void draw() {
  background(100);
  fill(255);
  box(10);

  // Draw GUI
  this.camera.beginHUD();

  // Hardcode fix for hud not resizing correctly (old) new way is to set viewport ourselves
  //ortho(0, width, -height, 0, -Float.MAX_VALUE, +Float.MAX_VALUE);

  // Darken Game
  fill(25, 25, 25, 180);
  stroke(0);
  strokeWeight(1.5);
  rectMode(RADIUS);
  rect(width / 2, height / 2, width * 0.375, height * 0.375, max(width, height) / 30);

  // Draw HUD
  textSize(21);
  fill(180, 180, 180);
  text("GUI", width * 0.125 + 20, height * 0.125 + 30);
  // TODO

  this.camera.endHUD();
}

void keyPressed() {
  if (key == 'f')
    this.fixApplied = !this.fixApplied;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant