how to move a image (ofImage) to a new position and if it intersects with another image then the other image would disappear like in chess.
Hi, when you draw an ofImage you have to pass the position where you want to draw it, so in order to move it just change the passed parameter.
ofImage img;
img.draw(10, 10);// this two numbers are the position of the top left corner of the image.
As for the second, pass an ofRectangle instance to the ofImage’s draw function instead of the position. An ofRectangle represents a rectangle defined by its top left corner coordinates, width and height. Besides this it has a lot of handy functions, like to check for intersections.
So,
ofImage img1, img2;//I assume you loaded an image into these.
ofRectangle rect1(10,10, img1.getWidth(), img1.getHeight());
ofRectangle rect2(100,100, 50, 10);
if(rect1.inside(rect2)){// inside checks that the whole rect2 is inside rect1. If this condition is met the it returns true.
//do something
}else if (rect1.intersects(rect2)){//this returns true if any part of rect2 is over rect1. There's no need for the whole rect2 to be over rect1, just any overlap will return true.
//do somethign else.
}
Check the ofRectangle class documentation. It is a really helpful class.
Hope it helps.
best