-
Jun 3rd, 2017, 01:42 PM
#1
Thread Starter
Member
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.
-
Jun 3rd, 2017, 01:43 PM
#2
Thread Starter
Member
Re: ChangeImage Function Not Working??
Code:
Public Class frmCharacter
Private Sub frmCharacter_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Character1StandWEST(0) = New Bitmap(My.Resources.stand1_0)
Character1StandWEST(1) = New Bitmap(My.Resources.stand1_1)
Character1StandWEST(2) = New Bitmap(My.Resources.stand1_2)
Character1StandWEST(3) = New Bitmap(My.Resources.stand1_3)
Character1StandWEST(4) = New Bitmap(My.Resources.stand1_4)
Character2StandWEST(0) = New Bitmap(My.Resources.stand1_01)
Character2StandWEST(1) = New Bitmap(My.Resources.stand1_11)
Character2StandWEST(2) = New Bitmap(My.Resources.stand1_21)
Character2StandWEST(3) = New Bitmap(My.Resources.stand1_31)
Character2StandWEST(4) = New Bitmap(My.Resources.stand1_41)
Character3StandWEST(0) = New Bitmap(My.Resources.stand1_03)
Character3StandWEST(1) = New Bitmap(My.Resources.stand1_13)
Character3StandWEST(2) = New Bitmap(My.Resources.stand1_23)
Character3StandWEST(3) = New Bitmap(My.Resources.stand1_33)
Character3StandWEST(4) = New Bitmap(My.Resources.stand1_43)
Character4StandWEST(0) = New Bitmap(My.Resources.stand1_02)
Character4StandWEST(1) = New Bitmap(My.Resources.stand1_12)
Character4StandWEST(2) = New Bitmap(My.Resources.stand1_22)
Character4StandWEST(3) = New Bitmap(My.Resources.stand1_32)
Character4StandWEST(4) = New Bitmap(My.Resources.stand1_42)
Character1WalkEAST(0) = New Bitmap(My.Resources.walk1_03)
Character1WalkEAST(1) = New Bitmap(My.Resources.walk1_13)
Character1WalkEAST(2) = New Bitmap(My.Resources.walk1_23)
Character1WalkEAST(3) = New Bitmap(My.Resources.walk1_33)
Character2WalkEAST(0) = New Bitmap(My.Resources.walk1_02)
Character2WalkEAST(1) = New Bitmap(My.Resources.walk1_12)
Character2WalkEAST(2) = New Bitmap(My.Resources.walk1_22)
Character2WalkEAST(3) = New Bitmap(My.Resources.walk1_32)
Character3WalkEAST(0) = New Bitmap(My.Resources.walk1_0)
Character3WalkEAST(1) = New Bitmap(My.Resources.walk1_1)
Character3WalkEAST(2) = New Bitmap(My.Resources.walk1_2)
Character3WalkEAST(3) = New Bitmap(My.Resources.walk1_3)
Character4WalkEAST(0) = New Bitmap(My.Resources.walk1_01)
Character4WalkEAST(1) = New Bitmap(My.Resources.walk1_11)
Character4WalkEAST(2) = New Bitmap(My.Resources.walk1_21)
Character4WalkEAST(3) = New Bitmap(My.Resources.walk1_31)
Character1StandEAST(0) = New Bitmap(My.Resources.stand1_0)
Character1StandEAST(1) = New Bitmap(My.Resources.stand1_1)
Character1StandEAST(2) = New Bitmap(My.Resources.stand1_2)
Character1StandEAST(3) = New Bitmap(My.Resources.stand1_3)
Character1StandEAST(4) = New Bitmap(My.Resources.stand1_4)
Character2StandEAST(0) = New Bitmap(My.Resources.stand1_01)
Character2StandEAST(1) = New Bitmap(My.Resources.stand1_11)
Character2StandEAST(2) = New Bitmap(My.Resources.stand1_21)
Character2StandEAST(3) = New Bitmap(My.Resources.stand1_31)
Character2StandEAST(4) = New Bitmap(My.Resources.stand1_41)
Character3StandEAST(0) = New Bitmap(My.Resources.stand1_03)
Character3StandEAST(1) = New Bitmap(My.Resources.stand1_13)
Character3StandEAST(2) = New Bitmap(My.Resources.stand1_23)
Character3StandEAST(3) = New Bitmap(My.Resources.stand1_33)
Character3StandEAST(4) = New Bitmap(My.Resources.stand1_43)
Character4StandEAST(0) = New Bitmap(My.Resources.stand1_02)
Character4StandEAST(1) = New Bitmap(My.Resources.stand1_12)
Character4StandEAST(2) = New Bitmap(My.Resources.stand1_22)
Character4StandEAST(3) = New Bitmap(My.Resources.stand1_32)
Character4StandEAST(4) = New Bitmap(My.Resources.stand1_42)
Character1WalkWEST(0) = New Bitmap(My.Resources.walk1_03)
Character1WalkWEST(1) = New Bitmap(My.Resources.walk1_13)
Character1WalkWEST(2) = New Bitmap(My.Resources.walk1_23)
Character1WalkWEST(3) = New Bitmap(My.Resources.walk1_33)
Character2WalkWEST(0) = New Bitmap(My.Resources.walk1_02)
Character2WalkWEST(1) = New Bitmap(My.Resources.walk1_12)
Character2WalkWEST(2) = New Bitmap(My.Resources.walk1_22)
Character2WalkWEST(3) = New Bitmap(My.Resources.walk1_32)
Character3WalkWEST(0) = New Bitmap(My.Resources.walk1_0)
Character3WalkWEST(1) = New Bitmap(My.Resources.walk1_1)
Character3WalkWEST(2) = New Bitmap(My.Resources.walk1_2)
Character3WalkWEST(3) = New Bitmap(My.Resources.walk1_3)
Character4WalkWEST(0) = New Bitmap(My.Resources.walk1_01)
Character4WalkWEST(1) = New Bitmap(My.Resources.walk1_11)
Character4WalkWEST(2) = New Bitmap(My.Resources.walk1_21)
Character4WalkWEST(3) = New Bitmap(My.Resources.walk1_31)
Character1FlyUp(0) = New Bitmap(fly_0)
Character1FlyUp(1) = New Bitmap(fly_1)
Character2FlyUp(0) = New Bitmap(fly_03)
Character2FlyUp(1) = New Bitmap(fly_13)
Character3FlyUp(0) = New Bitmap(fly_01)
Character3FlyUp(1) = New Bitmap(fly_11)
Character4FlyUp(0) = New Bitmap(fly_02)
Character4FlyUp(1) = New Bitmap(fly_12)
Character1FlyDown(0) = New Bitmap(fly_0)
Character1FlyDown(1) = New Bitmap(fly_1)
Character2FlyDown(0) = New Bitmap(fly_03)
Character2FlyDown(1) = New Bitmap(fly_13)
Character3FlyDown(0) = New Bitmap(fly_01)
Character3FlyDown(1) = New Bitmap(fly_11)
Character4FlyDown(0) = New Bitmap(fly_02)
Character4FlyDown(1) = New Bitmap(fly_12)
End Sub
Private Sub tmrStand_Tick(sender As Object, e As EventArgs) Handles tmrStand.Tick
PicCharacter1.Image = ChangeIMage(Character1StandWEST, 0.1)
PicCharacter2.Image = ChangeIMage(Character2StandWEST, 0.1)
PicCharacter3.Image = ChangeIMage(Character3StandWEST, 0.1)
PicCharacter4.Image = ChangeIMage(Character4StandWEST, 0.1)
End Sub
Private Sub PicCharacter1_Click(sender As Object, e As EventArgs) Handles PicCharacter1.Click
PicCharacter = Character1StandWEST
intcharacter = 1
Me.Close()
Level1SplashScreen.Show()
End Sub
Private Sub PicCharacter2_Click(sender As Object, e As EventArgs) Handles PicCharacter2.Click
PicCharacter = Character2StandWEST
intcharacter = 2
Me.Close()
Level1SplashScreen.Show()
End Sub
Private Sub PicCharacter3_Click(sender As Object, e As EventArgs) Handles PicCharacter4.Click
PicCharacter = Character3StandWEST
intcharacter = 3
Me.Close()
Level1SplashScreen.Show()
End Sub
Private Sub PicCharacter4_Click(sender As Object, e As EventArgs) Handles PicCharacter3.Click
PicCharacter = Character4StandWEST
intcharacter = 4
Me.Close()
Level1SplashScreen.Show()
End Sub
End Class
This is my frmcharacter (character selection form) code.
Last edited by rparikh10; Jun 4th, 2017 at 11:24 AM.
-
Jun 3rd, 2017, 01:51 PM
#3
Thread Starter
Member
Re: ChangeImage Function Not Working??
Code:
Option Strict On
Module Animation
Public Character1StandWEST(4) As Image
Public Character2StandWEST(4) As Image
Public Character3StandWEST(4) As Image
Public Character4StandWEST(4) As Image
Public Character1StandEAST(4) As Image
Public Character2StandEAST(4) As Image
Public Character3StandEAST(4) As Image
Public Character4StandEAST(4) As Image
Public Character1WalkWEST(3) As Image
Public Character2WalkWEST(3) As Image
Public Character3WalkWEST(3) As Image
Public Character4WalkWEST(3) As Image
Public Character1WalkEAST(3) As Image
Public Character2WalkEAST(3) As Image
Public Character3WalkEAST(3) As Image
Public Character4WalkEAST(3) As Image
Public Character1FlyUp(1) As Image
Public Character2FlyUp(1) As Image
Public Character3FlyUp(1) As Image
Public Character4FlyUp(1) As Image
Public Character1FlyDown(1) As Image
Public Character2FlyDown(1) As Image
Public Character3FlyDown(1) As Image
Public Character4FlyDown(1) As Image
Public PicCharacter() As Image
Public intcharacter As integer
Public intScore As Integer = 0
Public Const EAST As Integer = 0
Public Const NORTH As Integer = 90
Public Const WEST As Integer = 180
Public Const SOUTH As Integer = 270
Public charDirection As Integer = WEST
Public charSpeed As Integer = 5
Public imgCounter As Integer = 0
Public Function ChangeIMage(ByVal imgArray() As Image, ByVal imgIncrement As Integer) As Image
imgCounter += imgIncrement
If imgCounter > imgArray.Length() Then
imgCounter = 0
End If
Return imgArray(imgCounter)
End Function
End Module
This is my animation module code
Last edited by rparikh10; Jun 4th, 2017 at 11:25 AM.
-
Jun 4th, 2017, 10:56 AM
#4
Re: ChangeImage Function Not Working??
I'd say that by now you should be using the [CODE][/CODE] tags, so edit those posts and add them, please.
My usual boring signature: Nothing
-
Jun 4th, 2017, 11:25 AM
#5
Thread Starter
Member
Re: ChangeImage Function Not Working??
sure, done. sorry about that.
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
|