Animation Via Images and a For Loop

wardy484

New member
Joined
Dec 30, 2010
Messages
3
Programming Experience
1-3
Hey Guys, I'm having trouble drawing an animation using a for loop. The image source is definately changing however for some reason it isn't being drawn properly I just can't seem to see why they aren't be drawn. It appears to be keeping the original image. Anyway here's the code I'd really appreciate it if you could take a look and advise me as to whether I'm doing something wrong or maybe have just missed something that I can't seem to spot.

VB.NET:
Imports RPG_Game_System.Menu

Public Class Battle
    Dim running As Boolean
    Public monster As New Enemy

    Private Sub Battle_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Required in Order to Draw Graphics
        Me.Show()
        Me.Focus()
        Me.BackColor = Color.CadetBlue

        'Draw Graphics and Double Buffer
        BattleDrawing.G = Me.CreateGraphics
        bufferImage = New Bitmap(Me.Width, Me.Height)
        buffer = Me.CreateGraphics
        G = Graphics.FromImage(bufferImage)

        'Declares New Monsters
        monster.Enemy()
        bomb()

        'Activate the game loop
        running = True
        Call gameLoop()
    End Sub

    Private Sub gameLoop()
        'Creates loop in which everything will run
        Do While running = True
            Application.DoEvents()

            playerAnimation()
            monsterAnimation()

            'Draws Battle Scene
            drawBattle()

        Loop
    End Sub

    Private Sub NewButton1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class

VB.NET:
Module BattleDrawing
    'Graphics Variables, including Double Buf
    Public G As Graphics
    Public buffer As Graphics
    Public bufferImage As Bitmap

    'Message String
    Public MessageString As String = "Select a move!"
    Public strname As String

    'Font Used for Drawing Strings
    Dim fnt As New Font("Arial", 12)

    Public Sub drawBattle()
        'Drawing Player and Enemy names
        drawString("Player: " & Menu.character.name, 10, 10, Brushes.Black)
        drawString("Enemy: " & Battle.monster.name, Battle.Width - 250, 10, Brushes.Black)

        playerAnimation()
        monsterAnimation()

        'Draws Status Bars
        allBars()

        'Draws Message
        messagebox(5, Battle.Height - 130, Battle.Width - 200, 87, MessageString)

        'Draw Player and Enemy Sprites
        BattleObj(Menu.character.Sprite, 10, Battle.Height - 383, 150, 250)
        BattleObj(Battle.monster.Sprite, Battle.Width - 175, Battle.Height - 383, 150, 250)

        'Double Buffer Things
        buffer.DrawImage(bufferImage, 0, 0, Battle.Width, Battle.Height)
        G.Clear(Color.CadetBlue)

    End Sub

    Public Sub allBars()
        'Player Bars

        'Draw HP Status Bars
        BattleBars(Brushes.Red, 60, 32, 150, "HP:")
        BattleBars(Brushes.LimeGreen, 60, 32, Menu.character.HPVar, "HP:")

        'Draws MP Status Bar
        BattleBars(Brushes.Red, 60, 52, 150, "MP:")
        BattleBars(Brushes.Blue, 60, 52, Menu.character.MPVar, "MP:")

        'Draws EXP Bar
        BattleBars(Brushes.Red, 60, 72, 150, "EXP:")
        BattleBars(Brushes.Yellow, 60, 72, Menu.character.EXPvar, "EXP:")

        'Enemy Bars

        'Draw HP Status Bars
        BattleBars(Brushes.Red, Battle.Width - 200, 32, 150, "HP:")
        BattleBars(Brushes.LimeGreen, Battle.Width - 200, 32, Battle.monster.HPVar, "HP:")

        'Draws MP Status Bar
        BattleBars(Brushes.Red, Battle.Width - 200S, 52, 150, "MP:")
        BattleBars(Brushes.Blue, Battle.Width - 200, 52, Battle.monster.MPVar, "MP:")

    End Sub

    Public Sub drawString(ByVal text As String, ByVal x As Integer, ByVal y As Integer, ByVal colour As Brush)
        'Draws any text required.
        G.DrawString(text, fnt, colour, x, y)

    End Sub

    Public Sub BattleObj(ByVal sprite As Bitmap, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
        'This Sub can be used to draw any image onto a form, E.g. player avatar, shop or cave.
        G.DrawImage(sprite, x, y, width, height) 'Draws Players Avatar

    End Sub

    Public Sub BattleBars(ByVal color As Brush, ByVal x As Integer, ByVal y As Integer, ByVal length As Integer, ByVal str As String)
        'Draws Strings E.g. HP, MP, EXP, Etc.
        G.DrawString(str, fnt, Brushes.Black, x - 50, y - 3)

        'Draws Lower Status Bar
        G.FillRectangle(color, x, y, 154, 13)

        'Draws Upper Status Bar
        G.FillRectangle(color, x, y, length, 13)

    End Sub

    Public Sub messagebox(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal str As String)
        'Draws Messagebox
        G.FillRectangle(Brushes.Black, x, y, width, height)
        drawString(str, 13, y + 5, Brushes.White)
    End Sub

    Public Sub playerAnimation()
        Dim x As Integer

        For x = 1 To 16
            Menu.character.Sprite = Image.FromFile("C:\Users\Kim\Desktop\Game Folder\Town Graphics\Avatar Graphics\Avatar" & x & ".png")
            x = x + 1

            If x = 17 Then
                x = 1
            End If
        Next

    End Sub

    Public Sub monsterAnimation()
        'Once Testing is complete use & monster.name
        Dim x As Integer
        Dim str As String

        For x = 1 To 16
            str = "C:\Users\Kim\Desktop\Game Folder\Town Graphics\Avatar Graphics\Avatar" & x & ".png"
            Battle.monster.Sprite = Image.FromFile(str)
            x = x + 1

            If x = 17 Then
                x = 1
            End If
        Next

    End Sub

End Module
 
Back
Top