Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sniper Scope view (no zoom)  (Read 1808 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« Posted 2011-07-25 10:09:57 »

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!
Offline Z-Man

Senior Member


Medals: 8



« Reply #1 - Posted 2011-07-25 11:29:37 »

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
Offline Swattkidd7

Junior Member





« Reply #2 - Posted 2011-07-25 11:38:00 »

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!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nsigma

JGO Knight


Medals: 37



« Reply #3 - Posted 2011-07-25 12:18:19 »

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/topics/some-new-blendmodes-add-multiply-overlay-etc/24529/view.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.

Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #4 - Posted 2011-07-25 12:22:03 »

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

Offline nsigma

JGO Knight


Medals: 37



« Reply #5 - Posted 2011-07-25 12:48:50 »

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"  Roll Eyes

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.

Offline Swattkidd7

Junior Member





« Reply #6 - Posted 2011-07-25 13:03:14 »

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

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.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (70 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (136 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.1 seconds with 21 queries.