Jump to content

Drawing layers that move.


Recommended Posts

So I actually got this on my own for once.  When the player moves this moves in the inverse direction slightly to provide a parallax effect. For this purpose I am going to refer to our Fog rendering that moves:

Public Sub DrawFog()
        If Map.Moral = MapMoralIndoors Then Exit Sub

        Dim horz As Integer = 0
        Dim vert As Integer = 0

        For x = TileView.left To TileView.right + 1
            For y = TileView.top To TileView.bottom + 1
                If IsValidMapPoint(x, y) Then
                    horz = -x
                    vert = -y
                End If

        Dim tmpSprite As Sprite
        tmpSprite = New Sprite(FogGfx)
        tmpSprite.TextureRect = New IntRect(0, 0, frmMainGame.GameScreen.Width + 200, frmMainGame.GameScreen.Height + 200)
        tmpSprite.Color = New SFML.Graphics.Color(255, 255, 255, 150)
        tmpSprite.Position = New Vector2f((horz * 2.5) + 50, (vert * 3.5) + 50)
        GameWindow.Draw(tmpSprite) '

    End Sub

The original image was 256x256 and I Photoshopped it to 3200x2400.  It's really big but now it won't be clipped off on the edges of the screen, else I would have to draw this 9 times to account for different resolutions.  This moves in a somewhat jotty movement, and not very smooth, but it is not noticeable on fog.

This only moves along with the players movement as long as the player is in the middle of the X,Y coordinates.  If the player reaches those boundaries then this just ceases to move.  Also, on something like fog or clouds it would be neat to have a slowly scrolling image that moves across the screen...I'm at a loss on that one though, because I have no clue how to loop a moving image.

I'm hoping to get some advice so I don't have such static values for the image, and instead can use better calculations in moving the image.

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