Hi,
I hope I've put this in the right forum..
I'm attempting to make something with processing & OpenCV that has 4 objects, which appear at random at set corners of the screen.
The problem is I also need an arraylist to contain all of the data of each individual class so that a point system can be used.
(So 4 different coins in 4 separate corners that pop up at different intervals, and then when it is hit by the user via. webcam, the points will be added to the arraylist.)
They need to be in classes though, because each time one of them is hit - I want a different effect to happen. i.e. when the top left coin is hit, the screen is flipped vertically and when the bottom left coin is hit the screen is flipped both vertically and horizontally etc.
Is there any way around this? The problem is my code won't let the array acknowledge 2 different classes:
(the 2 classes I have are called winterCoin and summerCoin)
import hypermedia.video.*; // Imports the OpenCV library
OpenCV opencv; // Creates a new OpenCV object
winterCoin winterCoin;
summerCoin summerCoin;
PImage movementImg;
int hitCoin; // Creates a variable to hold the total number of coins hit
ArrayList coins;
PImage wCoin;
PImage sCoin;
void setup()
{
size ( 640, 480 );
opencv = new OpenCV( this );
opencv.capture( 640, 480 );
movementImg = new PImage( 640, 500 );
hitCoin = 0;
coins = new ArrayList();
wCoin = loadImage("winterCoin.png");
sCoin = loadImage("summerCoin.png");
}
coins.add(new winterCoin (40,40,40,40)); //ADDS THE NEW COIN
coins.add(new summerCoin (440,40,40,40)); //ADDS THE NEW COIN
opencv.read();
opencv.flip(OpenCV.FLIP_HORIZONTAL);
image( opencv.image(), 0, 0 );
opencv.absDiff();
opencv.convert(OpenCV.GRAY);
opencv.blur(OpenCV.BLUR, 3);
opencv.threshold(20);
movementImg = opencv.image();
for ( int i = 0; i < coins.size(); i++ ){
winterCoin _coin = (winterCoin) coins.get(i);
if(_coin.update() == 1){
coins.remove(i);
_coin = null;
i--;
}
else{
coins.set(i, _coin);
_coin = null;
}
}
opencv.remember(OpenCV.SOURCE, OpenCV.FLIP_HORIZONTAL);
text("Points: " + hitCoin, 20, 40);
}
-------------
after this code, I'm usually greeted with the error message:
ClassCastException: $summerCoin cannot be cast to $winterCoin
highlighting:
winterCoin _coin = (winterCoin) coins.get(i);
as where the error occurs - so I'm guessing that there is an issue in joining the
coins arraylist to two different classes. Any ideas/help would be really appreciated!
Also, if i'm just going on a completely wrong path in doing this, please let me know - I'm quite new to processing & can't think of a solution.
1