Scrolling background program and resolution of screen

I use these codes for scrolling background:

class Background {
  private float y;
  private float speed;
  private PImage image; 

  Background(PImage tempImage) {
    image = tempImage;
    y = 1;
    speed = 1; 
  }

  void displayAndScrolling() {
    y += speed;
    y %= height;
    image(image, 0, int(y));
    image(image.get(0, image.height - int(y), image.width, int(y)), 0, 0); 
  }

  void setY(float tempY) {
    y = tempY;
  }

  void setSpeed(float tempSpeed) {
    speed = tempSpeed;
  }

  void setImage(PImage tempImage) {
    image = tempImage; 
  }

  float getY() {
    return y;
  }

  float getSpeed() {
    return speed;
  }

  PImage getImage() {
    return image;
  }
}

My background image is 1920x1080. The game works only when the size of the window is 1920x1080. But when the screen resolution is not that size, the game cannot show correctly. Moreover, I can't just add displayWidth and displayHeight behind the two image methods to change the size of the image as the background is not shown correctly. What can I do to make multiple resolution possible?

Sign In or Register to comment.