Move background

Hi
I try to make a little game where the background has to move.

I´ve made an own background with photohop beforehand, which has a larger width than the sketch.

Now I wanted to know HOW can I insert an photo,which has not the same sizes as the sketch.
And if my figure moves too far to the right, the background moves as well

Can somebody help?

Thank you.

Hi Nati, welcome to the forum.

You can use loadImage to load images in your sketch. In the example on that page they use 0, 0 to indicate the image’s location. You could replace these with global variables.

Without seeing any code it’s hard to give good advice however, so if you already made a start on your sketch don’t be shy to share it with us (or a minified version of it). Keep in mind that if you share the code and it uses an image, is that you add the image so we can test it.

Hello,
i know the problem, because i often developed small scroll games, and for normal you give your class, which represents the whole ‘level’ an PVector ‘shift’. If you aren’t working with classes, it should be possible to create a global variable for this.
A little example what i mean:

PVector shift;
PImage background;

void setup() {
  shift = new PVector(0, 0); // The start of the background (upper-left corner)
  background = loadImage("background.png"); // Or whatever your background is
}

void draw() {
  background(255); // Is actually not needed because you have an image.
  image(background, shift.x, shift.y);
}

void keyPressed() {
  if (key == 'a') {
    shift.x += 1;
  } else if(key == 'd') {...
}
1 Like

The keyword is panning. Here are some relevant posts:

Kf