Airwaito
Airwaito

Reputation: 3

Monogame|XNA Draw a black screen with a transparent circle at a specific location

I try for some time to create a game. But at the very beginning, I am stuck. I just want to draw a black screen with a transparent circle overlaying it. I have searched a solution on a lot of french sites, but no responses

I drew you two images to show you what I want.

http://i.imgur.com/eKJ2Ni9.png?1 http://i.imgur.com/2RA0NWa.png?1

** Thank you for taking the time to read, and your help**

Upvotes: 0

Views: 443

Answers (1)

Falgantil
Falgantil

Reputation: 1310

You (physically) can't have a PNG with a transparent hole that moves around.

I mean, try it yourself. Take a piece of paper, cut out a hole in the paper. While you can do that, you can't move the hole around. You'd need a new piece of paper.

You'll need to use a shader for this, that renders everything on the screen black, apart from a circle at the players position. Pretty basic post-processing shader.

Pseudo code (in C#, needs to be translated to HLSL):

foreach (var pixel in allPixels)
{
    bool drawAsBlack = pixel.Position.DistanceFrom(player.PositionCenter) > RANGE_RADIUS;
    if (drawAsBlack)
        return Color.Black;
    else
        return pixel.Color;
}

Something like that, obviously translated into HLSL, but you get the idea.

Upvotes: 1

Related Questions