View Single Post
Old 07-12-2013, 06:16 AM
ephestion ephestion is offline
Join Date: Aug 2006
Posts: 10

Sorted it out partially.

With this class module I am able to store and restore the grid background. I do this just before applying the sprite changes. Because I am drawing to the form and then updating a picture box, I seem to be getting a buffering without need to apply masks.

Case Keys.Down
                'DownKey = True
                gPlayerWalking = True
                piX = (aGrid.TileColumn(gPlayerLoc) * gTileWidth) - gTileWidth
                piY = (aGrid.TileRow(gPlayerLoc) * gTileHeight) - gTileHeight + 1
                gPlayerDest = gPlayerLoc + 30
                gPlayerLoc = gPlayerLoc + 30
                'Restore the Grid as it was initially saved
                'Update the sprite, Fog and redraw screen
                'Set the picture box to use the image in buffer.
                picMap.Image = aGrid.Bitmap
Because I am using a Grid class all the drawing and stuff is based on a Tile count left to right. eg 0,0 px position is actually a rectangle at point 0,0 but called Tile number 1. The Grid I use is 30 tiles wide and 30 tiles high, so the Global variable gPlayerLoc needs to add 30 (30 tiles from current position) to drop to the next row of tiles.

This is all good and working. But now I want to animate the sprite. I want to press key down for example, then the sprite does goes through some walking frames and also moves 1 pixel at a time to the required destination. I know with BiBlt API it is easily done, but what I want to explore VB.Net managed code without getting into full blown DirectX or XNA programming.

How can I animate an object in VB.Net using its Graphics managed code? But at the same time make use of my Grid system. I want the Sprite to move to the next Grid in animated fashion but when they arrive to destination to update the Grid. Best example I can think of is like the way the Civilization games work. You press a key, the sprite animates and moves to the required location and stops. I don't want to stack calls when the key is pressed either ie some kind of lock while moving. Otherwise if a player keeps the button pressed and the move hasn't finished, they may likely make another move based on some Windows que.

If this forum is dead, can someone please tell me since it was about a week since my last post and I had no reply.


This is the sample code that plugs into a normal Windows Forms Application Form.
Public Class Form1

    Dim aTileSheet As New DynamicBitmap
    Dim aGrid As New DynamicBitmap
    Dim aSprite As New DynamicBitmap
    Dim aBlackSquare As New DynamicBitmap
    Dim gPlayerLoc As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        gPlayerLoc = 1
        aGrid.CreateBitmap(960, 960)
        aSprite.CreateBitmap(19, 32)
        aSprite.LoadBitmap("C:\temp\tilesets\sprite.png", 19, 32)
        aTileSheet.LoadBitmap("C:\temp\tilesets\test5.bmp", 32, 32)
        aBlackSquare.CreateBitmap(32, 32)

        aGrid.CreateBitmap(960, 960)
        aGrid.CreateGrid(32, 32, 30, 30)
        For i As Integer = 1 To aGrid.TileCount
            aGrid.DrawOnSurface(aTileSheet.Bitmap, aTileSheet.Rectangle(1), aGrid.Rectangle(i))

        If aGrid.Exists Then MessageBox.Show(aGrid.TileCount)

    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Dim intX As Integer
        Dim intY As Integer
        intX = aGrid.TileColumn(gPlayerLoc)
        intY = aGrid.TileRow(gPlayerLoc)
        gPlayerLoc = gPlayerLoc + 30
        aGrid.FillTile(aGrid.Tile(e.X, e.Y), Color.Red, True)
        PictureBox1.Image = aGrid.Bitmap

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint


    End Sub

    Public Sub DrawScreen()

        Dim G As Graphics = Me.CreateGraphics
        G.DrawImage(aGrid.Bitmap, New Point(0, 0))

    End Sub

    Sub DrawSprite()
        aGrid.DrawOnSurface(aSprite.Bitmap, aSprite.Rectangle(5), aGrid.Rectangle(gPlayerLoc), False, True)
    End Sub
End Class
Reply With Quote