First off all, I made a "Game-Renderer".
My problem is that, when I need to draw the current Element: I need to know if it's a Rectangle, Circle, or an Image and so on.
My Classes (Rectangle, Circle,...) are extending from Graphic.
public class Rectangle extends Graphic {...}
And if I want to draw them I look in the List ArrayList<Graphic>
for(index = 0;index < graphicObjects.size();index++){
currentElement = graphicObjects.get(index);
if(currentElement instanceof Rectangle) { // Here is an error.
Rectangle r = (Rectangle) currentElement;
// here the drawing.
}
}
Thanks for helping (Goggle wasn't helpful) :)
Edit:
Error is: "Incompatible conditional operand types Graphic and Rectangle"
And why I need to know the type: My code:
public static Image getImage(Graphics g,int width, int height) {
int imgWidth = width;
int imgHeight = height;
BufferedImage bfImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = bfImage.getGraphics();
for (int index = 0; index < grObjList.size(); index++) {
Graphic gr = grObjList.get(index);
if(gr instanceof Rectangle){
graphics.setColor(gr.color);
graphics.fillRect(gr.x, gr.y, gr.width, gr.height);
}
}
return bufferedImagetoImage(bfImage);
}