Jump to content

Drawing fog of war layer


Recoil

Recommended Posts

I have turned the fringe2 layer into my fog of war layer.  Instead of displaying the tiles on that layer, I am replacing them with a 32 pixel black image instead.  Any tiles drawn to this layer will render the black tile regardless of which one is selected.

tmpSprite2 is used for displaying a fog texture on top of the black tiles.  I don't really want the fog displaying all the time, and I only want it to display over the black tiles on this layer, so I am doing the following:

Private Sub DrawFogOfWarTile(ByVal x As Long, ByVal y As Long)

        Dim srcrect As New Rectangle(0, 0, 0, 0)
        Dim tmpSprite As Sprite
        Dim tmpSprite2 As Sprite
        
        With Map(CurrentMap).Tile(x, y)

            If .Layer(MapLayer.FogOfWar).Tileset > 0 And .Layer(MapLayer.FogOfWar).Tileset <= NumTileSets Then

                ' render
                With srcrect
                    .X = Map(CurrentMap).Tile(x, y).Layer(MapLayer.FogOfWar).X * 32
                    .Y = Map(CurrentMap).Tile(x, y).Layer(MapLayer.FogOfWar).Y * 32
                    .Width = 32
                    .Height = 32
                End With

                tmpSprite = New Sprite(_fowGfx)
                tmpSprite.TextureRect = New IntRect(srcrect.X, srcrect.Y, srcrect.Width, srcrect.Height)
                tmpSprite.Position = New Vector2f(ConvertMapX(x * PicX), ConvertMapY(y * PicY))
                tmpSprite.Color = New Color(255, 255, 255, 255)


                tmpSprite2 = New Sprite(_fogGfx)
                tmpSprite2.TextureRect = New IntRect(srcrect.X, srcrect.Y, srcrect.Width, srcrect.Height)
                tmpSprite2.Position = New Vector2f(ConvertMapX(x * PicX), ConvertMapY(y * PicY)) '(x * PicX, y * PicY)
                tmpSprite2.Color = New Color(255, 255, 255, 255)


                ' Draw the FoW layer at full opacity so players cannot see
                ' underneath while the DM can view at half opacity to make changes.
                If UpdateSecondary = True Then
                    _tmpPlayerWindow.Draw(tmpSprite)
                    _tmpPlayerWindow.Draw(tmpSprite2)
                End If

                ' Set the opacity for the DM.
                tmpSprite.Color = New Color(255, 255, 255, DmEditor.scrlFogOfWar.Value)
                tmpSprite2.Color = New Color(255, 255, 255, DmEditor.scrlFogOfWar.Value)

                DmWindow.Draw(tmpSprite, New RenderStates(BlendMode.Alpha))
                DmWindow.Draw(tmpSprite2, New RenderStates(BlendMode.Alpha))

                tmpSprite.Dispose()
                tmpSprite2.Dispose()
            End If

        End With

    End Sub

This is creating the same greyish looking texture from the fog image, not like I had imagined.

So here I am going through all the tiles on the Fringe2/FogOfWar layer, and if there is one anywhere on there, then display the fog over the whole screen:

Public Sub DrawFog()

        Dim ShowFog As Boolean = False
        Dim currOpacity As Integer = DmEditor.scrlFogOfWar.Value

        ' Check all the tiles on FogOfWar layer.
        ' If there is a tile there then this needs to draw fog.
        For x = TileView.Left To TileView.Right
            For y = TileView.Top To TileView.Bottom
                If IsValidMapPoint(x, y) Then
                    If Map(CurrentMap).Tile(x, y).Layer(MapLayer.FogOfWar).Tileset > 0 And Map(CurrentMap).Tile(x, y).Layer(MapLayer.FogOfWar).Tileset <= NumTileSets Then

                        ShowFog = True

                    End If
                End If
            Next
        Next

        If ShowFog = True Then

            Dim tmpSprite As Sprite = New Sprite(_fogGfx)
            tmpSprite.TextureRect = New IntRect(0, 0, tmpSprite.Texture.Size.X, tmpSprite.Texture.Size.Y) 'frmMainGame.GameScreen.Width + 128, frmMainGame.GameScreen.Height
            tmpSprite.Position = New Vector2f(((DmEditor.picDmScreen.Width / 2) - (tmpSprite.Texture.Size.X / 2)), 0) ' horz - 64
            tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, 255)

            If UpdateSecondary = True Then
                _tmpPlayerWindow.Draw(tmpSprite, New RenderStates(BlendMode.Alpha))
            End If

            tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, currOpacity)

            DmWindow.Draw(tmpSprite, New RenderStates(BlendMode.Alpha))
            tmpSprite.Dispose()

        End If

    End Sub

I have tried ripping my lighting code to use for this, and instead of checking for attributes I check for tiles, then display the fog.  However, the results are horrendous, and each time I place a new tile, the fog displays again, and again, making the screen darker and darker.

I'm open to suggestions of how to logically do this because I am out of options that have worked this far.

(Please don't say use a render texture, because I have tried that).

Link to comment
Share on other sites

I'm really sleepy so I can't really have a look at it tonight since its 1am here.. However what engine is that? Orion mod?

No, I fixed my own issue.  That one line was preventing me from drawing the fog to the whole screen, except where the tiles were.  Now the fog goes across the entire screen like it is supposed to.

And that is my new Orion Tabletop app.  It is an offline vanilla Orion mod, used for playing tabletop games.  Figures can be placed on the screen (with plexi glass) and moved around maps on the secondary screen, controlled by a DM on the primary screen (laptop).  Pretty much it is a glorified battlemap to use at a table, and not online...there are a few free online apps already for playing online.

I think I am done with it though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...