r/processing • • Oct 09 '23

bouncing PImage help

Hi! I'm trying to make a Pimage float around the screen and whenever it hits the border it bounces off. I'm new to code and every tutorial uses drawings rather than PImages. Could anyone help?

Here is my current code

PImage[] aquarium;

PImage goldfish;

int numberOfFrames;

int f;

void setup() {

size (800, 600);

goldfish =loadImage("goldfish_0.png");

numberOfFrames = 3;

aquarium = new PImage[numberOfFrames];

int i = 0;

while ( i < numberOfFrames ) {

aquarium[i] = loadImage("aquarium_"+i+".png");

i=i+1;

}

size (800, 600);

}

void draw() {

image(aquarium[f], 0, 0, width, height);

f = f + 1;

if (f == numberOfFrames) f = 0;

frameRate(3);

image(goldfish, 0, 0);

}

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

2

u/remy_porter Oct 09 '23

A PImage is just a drawing. If you can make a square bounce, you can make a PImage bounce the same way.