Learning OOP with Processing
in
Programming Questions
•
2 years ago
Hi everyone,
im trying to learn OOP and giving my first try with processing.
My goal is to make a falling image affected by gravity. However im trying to make it generic enough so i can make anything fall, be it an image or a video.
So i made:
a "Container" class that will receive an object
a "Image" class that will receive a directory and some other arguments
a "Video" class (yet to be implemented).
My problem is, i dont know how to send an Object to the Container class.
Im also getting token errors on all the arguments of the constructors of each class.
heres the code:
- void setup(){
- size(800,800);
- background(0);
- content = new Image("image.jpg", width/2, height/2, 400, 400);
- block = new Container(content, width/2, height/2, tempW, tempH);
- }
- void draw(){
- block.display();
- }
- class Container {
- int containerPosX, containerPosY, containerW, containerH;
- Object tempItem; (????????????????????)
- Container(tempItem, tempPosX, tempPosY, tempW, tempH){
- containerPosX = temPosX;
- containerPosY = temPosY;
- containerW = tempW;
- containerH = tempH;
- }
- void display (){
- Item.setPosX = containerPosX;
- Item.setPosY = containerPosX;
- Item.setW = containerW;
- Item.setH = containerH;
- }
- }
- class Image {
- String dir;
- int imagePosX, imagePosY, imageW, imageY;
- Image(){
- PImage img;
- img = loadImage(dir);
- }
- void setPosX(tempPosX){
- imagePosX = tempPosX;
- }
- void setPosY(tempPosY){
- imagePosY = tempPosX;
- }
- void setW(tempW){
- imageW = tempW;
- }
- void setH(tempH){
- imageH = tempH;
- }
- }
- /*
- Class Video {
- Video(){
- }
- void setPosX(){}
- void setPosY(){}
- void setW(){}
- void setH(){}
- }
- */
Maybe someone can shed a light on this :)
The gravity and other stuff isn't programmed yet, for not i'm just trying to display a video / image inside a container.
Thank you!
1