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.

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

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.

  • 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 '12 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 '12 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 '12 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 '12 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.