Hey I need help with this code. Im a beginner.
in
Programming Questions
•
2 years ago
I'm trying to get my background (a png file) to appear on the background of this file and it doesnt seem to work with my moving ball animation. here is my code so far.
import processing.opengl.*;
float xpos;
float ypos;
int ballWth ;
int ballHgt ;
float xspeed ;
float yspeed ;
PImage bg;
void setup(){
size(800, 600, OPENGL);
save("background.png");
bg = loadImage("background.png");
noStroke();
frameRate(200);
smooth();
xpos = width/2.0;
ypos = height/2.0;
xspeed = .3+random(2.5);
yspeed = .3+random(2.5);
ballWth = 80;
ballHgt = 80;
}
void draw(){
background(bg);
fill(0, 162, 142);
ellipse(xpos, ypos, ballWth, ballHgt);
xpos += xspeed;
ypos += yspeed;
if (xpos >= width || xpos <=0){
xspeed *= -1;
}
if (ypos >= height || ypos <= 0){
yspeed *=-1;
}
}
1