6
\$\begingroup\$

So I'm making a basic 2D game in C# XNA. I want it so wherever my character is facing there is a cone of light and only that part of the level is visible while the right of the screen is dark. Please excuse my ignorance, I haven't been working with C# too long.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Have you done any reading on 2D lighting in general? That would be a good place to start. \$\endgroup\$
    – ashes999
    Dec 13, 2012 at 23:05
  • \$\begingroup\$ Take a look at Catalin's Game Development Blog catalinzima.com/samples/dynamic-2d-shadows \$\endgroup\$ Dec 14, 2012 at 16:36

1 Answer 1

8
\$\begingroup\$

Well the simplest approach to this would be to simply overlay a dark mask over the right side of the screen. You could do this with a completely opaque black image that covers stuff from view, but I think what would look better is a semi-transparent black image so that you can still see the background and then hide the enemy graphics on that side of the screen.

\$\endgroup\$
4
  • 3
    \$\begingroup\$ With the modification of rotating the cone to follow the view of the character, this is going to be the best solution. \$\endgroup\$
    – House
    Dec 13, 2012 at 23:36
  • \$\begingroup\$ I imagined a solution with multiplication against a lighting map, but this is actually simple and very effective. +1 \$\endgroup\$
    – ashes999
    Dec 14, 2012 at 0:54
  • \$\begingroup\$ I'm a little confused about what you mean. Are you saying that I should lay a semi transparent black image for the entire screen? How would the cone vision with this method? \$\endgroup\$
    – Ady
    Dec 14, 2012 at 1:48
  • 2
    \$\begingroup\$ @Ady yes, that's what he's saying. The cone would be a transparent area in the black image; rotate and position it to always point from the player to wherever he's looking. \$\endgroup\$
    – ashes999
    Dec 14, 2012 at 3:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .