I am making a 2d game and i want to make 2d visibility. So my idea is to make the map and then mask it with another black (for example) polygon so that the player can see through the black polygon the map. So my idea is to draw some kind of a hole(polygon) trough the black polygon in order to see the map which is below the black polygon. I have already made the visibility but i have no idea how to make the mask.
This is what the program looks so far http://prntscr.com/7y36ev
but the problem is that if there are any objects in the dark they would still be rendered and the player could see them. I can shoot a ray and see if they are in line of sight but it would be a bit buggy because the rays will be shot in the center of the objects and if for example only their shoulder is showing up the object will not be rendered. Can somebody help ?
Edit - for anyone who wants to do the same I made it with Path2D. First I make the outside polygon with Path2D, then make the inside polygon(the hole) and append the hole to the outside polygon. This is sample code:
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.red);
Path2D.Double poly = new Path2D.Double();
Path2D.Double hole = new Path2D.Double();
hole.moveTo(40,40);
hole.lineTo(40,60);
hole.lineTo(60,60);
hole.lineTo(60,40);
hole.lineTo(40,40);
poly.moveTo(80,2);
poly.lineTo(80,80);
poly.lineTo(2,80);
poly.lineTo(2,2);
poly.lineTo(80,2);
poly.append(hole, true);
g2d.fill(poly);
}