Question: Hello, I have a code for processing of a code that shows a scrolling bacground of mountains. I have 8 sprite pose files and I

Hello, I have a code for processing of a code that shows a scrolling bacground of mountains. I have 8 sprite pose files and I need help adding them in the code. they are called run-1.png, run-2.png, run-3.png, run-4.png, run-5.png, run-6.png, run-7.png, run-8.png. The sprite should run in the middle on the same spot as the background moves with them. It is better if the code is long and functional than short and has syntax errors and does not run. This is processing software for creating sketches, it uses java not java script. I will leave the code of my scrolling background:
ArrayList mountain1= new ArrayList();
ArrayList mountain2= new ArrayList();
ArrayList mountain3= new ArrayList();
float m1y;
float m2y;
float m3y;
float m1s =100;
float m2s =50;
float m3s =25;
void setup(){
size(1080,720);
m1y = height/2;
m2y = height/4;
m3y = height/6;
generate(mountain1, m1y, m1s);
generate(mountain2, m2y, m2s);
generate(mountain3, m3y, m3s);
noStroke();
}
void draw(){
background(100,200,255);
move(mountain1,4, m1y, m1s);
move(mountain2,2, m2y, m2s);
move(mountain3,1, m3y, m3s);
fill(0,100,50);
show(mountain3);
fill(0,125,25);
show(mountain2);
fill(0,155,0);
show(mountain1);
}
void move(ArrayList mountain, float speed, float y, float size){
for(int i =0; i < mountain.size(); i ++){
mountain.get(i).x -= speed;
}
if(mountain.get(1).x <0){
mountain.remove(0);
}
while(mountain.get(mountain.size()-1).x < width +2* size){
mountain.add(new PVector(mountain.get(mountain.size()-1).x + size + random(-size/2, size/2), y + random(-size, size)));
}
}
void generate(ArrayList mountain, float y, float size){
mountain.add(new PVector(0, y + random(-size, size)));
while(mountain.get(mountain.size()-1).x < width){
mountain.add(new PVector(mountain.get(mountain.size()-1).x + size + random(-size/2, size/2), y + random(-size, size)));
}
}
void show(ArrayList mountain){
beginShape();
vertex(width, height);
vertex(0, height);
for(int i =0; i < mountain.size(); i ++){
vertex(mountain.get(i).x, mountain.get(i).y);
}
endShape(CLOSE);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!