Looping background
in
Programming Questions
•
1 year ago
Hello everyone,
I have a question about looping backgrounds. I'm making a top down shooter with a single background that repeats. Top and bottom connect seamlessly, I'd like to know if it is possible to let it scroll down, making it basically one huge infinite background. It scrolls down currently, the problem is that nothing is drawn until the top of the image hits the bottom of the screen, only then it draws a new background.
This is the code I have for the background:
I have a question about looping backgrounds. I'm making a top down shooter with a single background that repeats. Top and bottom connect seamlessly, I'd like to know if it is possible to let it scroll down, making it basically one huge infinite background. It scrolls down currently, the problem is that nothing is drawn until the top of the image hits the bottom of the screen, only then it draws a new background.
This is the code I have for the background:
- float bgrepeat;
float y = 1;
float x;
float speed = 1;
void setup() {
size(400,600);
frameRate(25);
smooth();
oscP5 = new OscP5(this,"239.0.0.1",7777);
}
void draw() {
rectMode(CENTER);
noStroke();
y = y + speed;//scrollspeed
PImage d; // image object
d = loadImage("back.png"); //laadt background in als image
image(d,0,y); //scrollt bg naar beneden
if(y >= height){
x = bgrepeat;
y = 0;}
}
1