I currently have a form with a panel on it and then 100 pictureboxes inside the panel. I was using the keydown event to 'move' my map, which worked. I was doing something like this:
The problem came when the user would just hold down the keys. It created really bad jumping, which is why I added the player.IsMoving = False, but that doesn't matter if the user holds the key down as the player wasn't moving when the key was origionally down. I've tried moving it to the keypress thinking that will solve my problem, and it looks almost identical to the key-down:
The problem is I set a breakpoint at the key_press, but it never fires. Any ideas as to why?
Edit - I do indeed have keypreview set to true.
vb.net Code:
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Left AndAlso map(current_possition.X - 1, current_possition.Y).IsPassable AndAlso player.IsMoving = False Then current_possition.X -= 1 player.CurrentLocation = current_possition player.player_move() Call load_view() ElseIf e.KeyCode = Keys.Right AndAlso map(current_possition.X + 1, current_possition.Y).IsPassable AndAlso player.IsMoving = False Then current_possition.X += 1 Call load_view() ElseIf e.KeyCode = Keys.Up AndAlso map(current_possition.X, current_possition.Y - 1).IsPassable AndAlso player.IsMoving = False Then current_possition.Y -= 1 Call load_view() ElseIf e.KeyCode = Keys.Down AndAlso map(current_possition.X, current_possition.Y + 1).IsPassable AndAlso player.IsMoving = False Then current_possition.Y += 1 Call load_view() End If End Sub
vb.net Code:
Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress If e.KeyChar = ChrW(Keys.Left) AndAlso map(current_possition.X - 1, current_possition.Y).IsPassable AndAlso player.IsMoving = False Then current_possition.X -= 1 player.CurrentLocation = current_possition player.player_move() Call load_view() ElseIf e.KeyChar = ChrW(Keys.Right) AndAlso map(current_possition.X + 1, current_possition.Y).IsPassable AndAlso player.IsMoving = False Then current_possition.X += 1 Call load_view() ElseIf e.KeyChar = ChrW(Keys.Up) AndAlso map(current_possition.X, current_possition.Y - 1).IsPassable AndAlso player.IsMoving = False Then current_possition.Y -= 1 Call load_view() ElseIf e.KeyChar = ChrW(Keys.Down) AndAlso map(current_possition.X, current_possition.Y + 1).IsPassable AndAlso player.IsMoving = False Then current_possition.Y += 1 Call load_view() End If End Sub
The problem is I set a breakpoint at the key_press, but it never fires. Any ideas as to why?
Edit - I do indeed have keypreview set to true.