Jump to content

Draw black tiles all over screen.


Recoil

Recommended Posts

I would like to try and draw just black tiles on the screen to see if that will help with my lighting issue.  Currently this draws 1 tile at the top left.  When I maximize my window it stretches slightly, but not much.  How do I correctly render black tiles all across the game screen?

For X = TileView.left To TileView.right + 1
            For Y = TileView.top To TileView.bottom + 1
                If IsValidMapPoint(X, Y) Then
                    DrawNight(X, Y)
                    
                End If
            Next
        Next

Dim tmpSprite As Sprite
        tmpSprite = New Sprite(NightGfx)
        tmpSprite.TextureRect = New IntRect(0, 0, 32, 32)
        tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
        tmpSprite.Position = New Vector2f(x, y)

        
        If IsValidMapPoint(x, y) Then
            
                GameWindow.Draw(tmpSprite, New RenderStates(BlendMode.None))
            
        End If

Link to comment
Share on other sites

Add * 32 when setting your position.

tmpSprite.Position = New Vector2f(x * 32, y * 32)

If that doesn't work completely you may have to wrap them in ConvertMapX() and ConvertMapY()

tmpSprite.Position = New Vector2f(ConvertMapX(x * 32), ConvertMapY(y * 32))

Link to comment
Share on other sites

That worked perfectly, yet it didn't LOL.

It did not have the outcome I was trying to achieve.  So I am going to try this another way.  Using the above code, how would I offset the image being drawn?  Like instead of drawing at point x, y...offset that by an amount of say -64 so it would be 2 squares off?

Dim tmpSprite As Sprite
        tmpSprite = New Sprite(NightGfx)
        tmpSprite.TextureRect = New IntRect(0, 0, 32, 32)
        tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
        tmpSprite.Position = New Vector2f(ConvertMapX(x * 32), ConvertMapY(y * 32))

       
        If IsValidMapPoint(x, y) Then
           
                GameWindow.Draw(tmpSprite, New RenderStates(BlendMode.None))
           
        End If

Edit to add: I got it:

tmpSprite.Origin = New Vector2f(tmpSprite.Texture.Size.X / 2 - 32, tmpSprite.Texture.Size.Y / 2 - 32)

Link to comment
Share on other sites

Sub DrawNight()

        If Map.Moral = MapMoralIndoors Then Exit Sub
   
        Dim tmpSprite As Sprite
        tmpSprite = New Sprite(NightGfx) '32, 32) ' 
        tmpSprite.TextureRect = New IntRect(0, 0, frmMainGame.GameScreen.Width, frmMainGame.GameScreen.Height)
        tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
        tmpSprite.Position = New Vector2f(0, 0)
        
        Dim tmpBuffer As New RenderTexture(frmMainGame.GameScreen.Width, frmMainGame.GameScreen.Height)
       
        tmpBuffer.Clear() 'SFML.Graphics.Color.Black)
        
        tmpSprite.Draw(tmpBuffer, New RenderStates(BlendMode.Alpha))

        For X = TileView.left To TileView.right + 1
            For Y = TileView.top To TileView.bottom + 1
                If IsValidMapPoint(X, Y) Then
                    If Map.Tile(X, Y).Type = TileTypeLight Then
                        
                        Dim tmpLight As Sprite
                        tmpLight = New Sprite(LightGfx)
                        tmpLight.TextureRect = New IntRect(0, 0, tmpLight.Texture.Size.X, tmpLight.Texture.Size.Y)
                        tmpLight.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
                        tmpLight.Origin = New Vector2f(tmpLight.Texture.Size.X / 2 - 32, tmpLight.Texture.Size.Y / 2 - 32)
                        tmpLight.Position = New Vector2f(ConvertMapX(X * 32), ConvertMapY(Y * 32))
                      
                        tmpLight.Draw(tmpBuffer, New RenderStates(BlendMode.Add))
                        
                    End If

                End If
            Next
        Next

        tmpBuffer.Display()

        'Dim tmpBuff As Sprite - declared at top

        tmpBuff = New Sprite(tmpBuffer.Texture) '32, 32) ' 
        tmpBuff.TextureRect = New IntRect(0, 0, frmMainGame.GameScreen.Width, frmMainGame.GameScreen.Height)
        'tmpBuff.Color = New SFML.Graphics.Color(255, 255, 255, CurrLevel)
        tmpBuff.Position = New Vector2f(0, 0)

        GameWindow.Draw(tmpBuff, New RenderStates(BlendMode.Multiply))

    End Sub

Link to comment
Share on other sites

Sorry my bad. Okay, render tmpSprite as BlendMode.Alpha (or just no blend mode).

And draw your lights to the RenderTexture

GameWindow.Draw(tmpLight, New RenderStates(BlendMode.Add))

Should be

tmpBuffer.Draw(tmpLight, New RenderStates(BlendMode.Add))

Also, define the rendertexture ourside of the sub at the top of your module. You really don't want to recreate it every frame.

Link to comment
Share on other sites

Okay guys and gals...for those of you who have been looking at this post to find out how to do the lighting in VB.NET, the code that is posted only works partially and does not provide a full lighting render like we all want.  That being said I finally was able to figure out how to do the lighting.  I had done it previously, except the image I was using was not good.

I plan on releasing yet another update to our Orion Revamped engine.  It will have the updated lighting render subs in it so it will be easier to understand.  I'll put links up here and in my sig so hopefully it will show.

Stay tuned!

width=1000http://i62.tinypic.com/311vrbk.jpg[/img]

Link to comment
Share on other sites

Um, yeah...thinks for bringing that up because I totally failed to check.  I am running 18-19 right now :(

Edit: Damian is running fine, but outside I am running 19-20 FPS after a restart.  Inside I am running 97 so I will have to look into.

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...