Two-level lighting

I am adding lighting to my XNA 2D tile game.

I found this article useful, but its execution method does not support collision. What I would like is a method for doing the following

  • Dots always shone
  • Collision (if a light ray hits a block, then lower the next block by any amount to dark to simulate shadows).

I searched for a long time, but no luck (I found the Catalin directory, but for me it seemed a bit advanced and not applicable to tiles due to redrawing the entire game for each point)

+5
source share
3 answers

2D-. ClassicThunder answer .

, , . , , .

Lighting

, , , , CurrentLight , , CurrentLight "" CurrentLight. , , CurrentLight, . , .

, . 3 , , . .

if (tile.Light > CurrentLight) //If this tile is brighter than the last, set the current light to the tiles light
    CurrentLightR = tile.Light;
else if (CurrentLight != 0f) //If it is less, and isnt dark, then set the tile to the current light
    tile.Light = CurLightR;
if (tile.Light == CurLightR) //If it is the same, subtract absorb values
    CurrentLight -= tile.Absorb;

, . , "" , gamedev .

+1

Catalin. , .

+4

, , - , .

SpriteBatch.draw, . Color.White, , SpriteBatch, .

Use color multiplication by creating a new color (Color.yourcolor.r * float, Color.yourcolor.y * float, Color.yourcolor.z * float, 255)

Basically, to get a float, try finding a formula that calculates the brightness of a block due to close lights (probably stored in an array or list). Since there are no normals for 2D games, this formula should be relatively easy.

0
source

All Articles