Sniper Scope view (no zoom)

Hey guys I was wondering how I could go about making the map only visible through the players “sniper scope” the game is top down, so they would only see through a circle that they can move around, as if they are looking through the scope searching for players.

Any ideas on how to implement this? I just cant figure out how to black out everything outside of the “scope”/circle.

Thanks in advance!

Well if you aren’t gonna allow the game window to be resized then you could just have an image that you draw over everything. If you want to allow resizing then you could create the image of the “scope” everytime the window is resized. I’m not entirely sure if either of these are the best way though since I’ve never tried doing that, and it’s about 4am here xD

Good luck, I hope my suggestions at least help you think of something.
Z-Man

thanks for the response, I was actually thinking about implementing it the way you are saying but my problem is I dont want the scope to stay in the center of the screen, I want it to move with the mouse you know what I mean? so if I were to just draw an image, the scope would always be in the middle which is not exactly what I am going for…but once again thanks for the idea!

You could try drawing the scope in white on a full-screen black image and then using a multiply blending mode to composite over your background image. If you’re working directly with arrays of pixels you could check out this recent thread http://www.java-gaming.org/index.php/topic,24529.0.html, or if you’re just using Java2D then have a look at http://filthyrichclients.org/ -> Examples -> Chapter 6 which has a lot of additional blend modes for use with Graphics2D.setComposite(). The straight array mode will be faster, but the FRC code might be easier.

You might also try (less sure about this one) drawing your scope on a full screen transparent image and then setting the composite to AlphaComposite.DestIn before drawing it on top of your background.

Or you could create an java.awt.geom.Area, subtract a java.awt.geom.Ellipse and then draw it filled across the screen in black, it’d probably quite cheap.

Kev

Oh yeah! For some reason I was expecting the scope to be an image rather than just a plain circle, despite the fact the OP distinctly used the word “circle” ::slight_smile:

Depending on the other drawing you’re doing it might also be worth clipping the background rendering to the bounding rectangle of the Area / scope as well - seems pointless to draw things that are going to end up black.

Thanks! I was thinking about this but thought it might be too much, however I will definitely take your word for it!

**Implemented it and it worked beautifully! Thank you very much once again to everyone that responded, and to KevGlass for the solution that worked out best for me.