|
-
May 30th, 2017, 09:45 AM
#1
Thread Starter
Member
animation not working???
i am doing a maze game for a project for class. I have character selection, so the code is very extensive. I am not sure why but when i press an arrow key, the character flickers between two characters. i am not sure why this is happening. this is my code:
Code:
Public PicCharacter As Image
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
PicCharacterLvl1.Image = ChangeImage(Character1WalkWEST, 0.1)
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 = Character4FlyDown
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 = Character4FlyDown
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 = Character3WalkWEST
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
Private Sub frmLevel1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If intCharacter = 1 Then
If charDirection = WEST Then
PicCharacter = Character1StandWEST
ElseIf charDirection = EAST Then
PicCharacter = Character1StandEAST
End If
ElseIf intCharacter = 2 Then
If charDirection = WEST Then
PicCharacter = Character2StandWEST
ElseIf charDirection = EAST Then
PicCharacter = Character2StandEAST
End If
ElseIf intCharacter = 3 Then
If charDirection = WEST Then
PicCharacter = Character3StandWEST
ElseIf charDirection = EAST Then
PicCharacter = Character3StandEAST
End If
ElseIf intCharacter = 4 Then
If charDirection = WEST Then
PicCharacter = Character4StandWEST
ElseIf charDirection = EAST Then
PicCharacter = Character4StandEAST
End If, it will
End If
End Sub
Private Sub tmrMove_Tick(sender As Object, e As EventArgs) Handles tmrMove.Tick
PicCharacterLvl1.Image = ChangeImage(PicCharacter, 0.1)
End Sub
The first is where my piccharacter is declared. the next is my keypress function. I am saying that if the character is the first, and you press left, the direction changes to west, the animation changes to walk west and the picture box moves to the left. I have this for every possible character and direction. the next is what i put in the key up function, saying that if i let go of the key, it will go back to stand. this standing works, but when i press a key to walk, it flickers between two characters. the last is just the line i have in the timer tick function, saying that every tick, the change image function runs. please note this is my first year in vb, so i am not that educated and if i could get a detailed explanation on my mistake, i would greatly appreciate it. Thanks so much.
Last edited by dday9; May 30th, 2017 at 09:50 AM.
Reason: Added Code Tags
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|