Simple Clipping

Hello all,

I implemented my own simple windowing system for my game. Since I only want to render the window when something has changed, I need to ensure that when my underlying tile system does not draw over my window. I was thinking of doing it this way: Start with a clipping region that is the same dimensions as the JFrame that holds the game, and have each of my game windows “cookie-cut” out where they are drawn. This solution seems simple enough, yet when looking at the Graphics and Shape API it seems that I cannot create an arbitrary shape without explicitly specifying the points (like with a polygon).

In other words, I can’t figure out how to do this robustly. I know there are some other simple design patterns out there, so if someone could tell me how to implement the solution I explained or point me in the right direction it would be much appreciated!

Thanks!
-Mike :slight_smile:

Actually, you can create an arbitrary shape with java.awt.geom.Area


        Area shape = new Area();
        shape.add(new Area(new Rectangle2D.Double(-50, -50, 100, 100)));        
        shape.add(new Area(new Rectangle2D.Double(-70, -10, 20, 20)));
        ...
        //adjust shape here 

But if this is a tile absed system you might well get better performance by limiting the tiles you draw to the ones being updated.

Thanks Jeff and Rolz! I got it working.

-Mike :slight_smile: