Help!-Replacing ellipse with a image once hit edge
in
Programming Questions
•
5 months ago
I need to write a program so that a ball rises upwards and once it hits the top the ellipse is replaced by a image.
The ball needs to be no longer visible.
The message "cannot convert Pimage to float" appears I run the program.
color orange = color(255, 140, 0);
color white = color(255, 255, 255);
float y; // y is vertical position of ball
float r; // r is radius of ball
// Image of fish
PImage fish;
void setup() {
size(500, 500);
smooth();
frameRate(70);
y = 450; // the ball starts near bottom of screen
r = 25; // the ball has radius of 25
}
void draw() {
// re-draw white background
background(white);
// draw ball
noStroke();
fill(orange);
ellipse(250, y, r * 2, r * 2);
// substract 1 to y to make ball move upwards
y -= 1;
if (y - r <= 0) {
//uh oh: the ball has gone off the edge of screen
y = loadImage("fish.png"); // start at bottom again
}
}
Thanks for your help.
1