Results 1 to 5 of 5

Thread: ChangeImage Function Not Working??

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    32

    Angry ChangeImage Function Not Working??

    Thank you to the people who helped me in my previous threads, i have managed to fix the imgarray is nothing error. However, i am running into problems with my animations. In my character selection screen, even though each character should have a stand animation, they are idle. Also, in my level 1, when i press an arrow key, it switches to the first picture in the walk animation and stays there. the changeimage function seems to not be properly moving to the next image.

    This is my level 1 code:

    Code:
     
    Public Class frmLevel1
    
        Private Walls(7)
    
        Private Sub frmLevel1_KeyPress(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
    
            If intcharacter = 1 Then
                If Keys.Left OrElse Keys.A Then
                    charDirection = WEST
                    PicCharacter = Character1WalkWEST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X - 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Right OrElse Keys.D Then
                    charDirection = EAST
                    PicCharacter = Character1WalkEAST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X + 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Up OrElse Keys.W Then
                    charDirection = NORTH
                    PicCharacter = Character1FlyUp
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y - 1)
                ElseIf Keys.Down OrElse Keys.S Then
                    charDirection = SOUTH
                    PicCharacter = Character1FlyDown
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y + 1)
                End If
            ElseIf intcharacter = 2 Then
                If Keys.Left OrElse Keys.A Then
                    charDirection = WEST
                    PicCharacter = Character2WalkWEST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X - 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Right OrElse Keys.D Then
                    charDirection = EAST
                    PicCharacter = Character2WalkEAST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X + 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Up OrElse Keys.W Then
                    charDirection = NORTH
                    PicCharacter = Character2FlyUp
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y - 1)
                ElseIf Keys.Down OrElse Keys.S Then
                    charDirection = SOUTH
                    PicCharacter = Character2FlyDown
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y + 1)
                End If
            ElseIf intcharacter = 3 Then
                If Keys.Left OrElse Keys.A Then
                    charDirection = WEST
                    PicCharacter = Character3WalkWEST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X - 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Right OrElse Keys.D Then
                    charDirection = EAST
                    PicCharacter = Character3WalkEAST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X + 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Up OrElse Keys.W Then
                    charDirection = NORTH
                    PicCharacter = Character3FlyUp
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y - 1)
                ElseIf Keys.Down OrElse Keys.S Then
                    charDirection = SOUTH
                    PicCharacter = Character3FlyDown
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y + 1)
                End If
            ElseIf intcharacter = 4 Then
                If Keys.Left OrElse Keys.A Then
                    charDirection = WEST
                    PicCharacter = Character4WalkWEST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X - 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Right OrElse Keys.D Then
                    charDirection = EAST
                    PicCharacter = Character4WalkEAST
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X + 1, PicCharacterLvl1.Location.Y)
                ElseIf Keys.Up OrElse Keys.W Then
                    charDirection = NORTH
                    PicCharacter = Character4FlyUp
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y - 1)
                ElseIf Keys.Down OrElse Keys.S Then
                    charDirection = SOUTH
                    PicCharacter = Character4FlyDown
                    PicCharacterLvl1.Location = New Point(PicCharacterLvl1.Location.X, PicCharacterLvl1.Location.Y + 1)
                End If
            End If
    
            If WallCollision() Then
                PicCharacterLvl1.Location = New Point(643, 387)
            End If
        End Sub
    
        Private Sub frmLevel1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Walls(0) = lblLvl1Wall1
            Walls(1) = lblLvl1Wall2
            Walls(2) = lblLvl1Wall3
            Walls(3) = lblLvl1Wall4
            Walls(4) = lblLvl1Wall5
            Walls(5) = lblLvl1Wall6
            Walls(6) = lblLvl1Wall7
            Walls(7) = lblLvl1Wall8
    
            intScore = 1000
    
        End Sub
    
        Private Function WallCollision() As Boolean
    
            For i As Integer = 0 To Walls.GetUpperBound(0)
                If PicCharacterLvl1.Bounds.IntersectsWith(Walls(i).Bounds) Then
                    Return True
                End If
            Next
            Return False
    
        End Function
    
        Private Sub tmrScore_Tick(sender As Object, e As EventArgs) Handles tmrScore.Tick
    
            intScore = intScore - 1
            lblScore.Text = "Score:" & intScore.ToString()
    
        End Sub
    
        Private Sub tmrMove_Tick(sender As Object, e As EventArgs) Handles tmrMove.Tick
    
            PicCharacterLvl1.Image = ChangeIMage(PicCharacter, 0.5)
    
        End Sub
    End Class
    Last edited by rparikh10; Jun 4th, 2017 at 11:23 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width