We are about to switch to a new forum software. Until then we have removed the registration on this forum.
im learning class materials and trying to load a jumping image in circle shape using class, but its not working. any help? here is the code:
PImage img;
void setup() { size(400, 400); img=new PImage(); }
void draw() { background(0); img.move(); img.display(); }
class PImage{ float posX, posY; float speedX, speedY;
PImage() { posX=width/2; posY=height/2; speedX=random(2, 5); speedY=random(4, 7); }
void move() { posX=posX+speedX; posY=posY+speedY;
if (posX<0|posX>width) {
speedX=-speedX;
}
if (posY<0|posY>height) {
speedY=-speedY;
}
}
void display() { img=loadImage("P4151136.jpg"); PImage(img, posX, posY); } }
Answers
You shouldn't redefine PImage. You have your own PImage class but the loadImage() method returns an instance of Processing's PImage class which is different. Rename your class.
In addition, don't use loadImage() in your display() as this will attempt to load an image 60 times a second. Instead use it in the constructor of the class which is currently named PImage