me muevo a los lados y si salto el evento keydown cancela la tecla sostenida y da lugar a la nueva pulsada, eso lo comprendo pero no se como emular una solución, si alguien me puede tirar alguna idea me seria de gran ayuda!
Dejo lo que tengo por ahora...
Código
Código:
Public Class Form1
Dim jumpLimit As Short = 100
Dim charGround As Short = 200
Private charSize As New Size(30, 30)
Private charPos As New Point(200, charGround)
Private character As Rectangle
Private WithEvents tmrRefresh As New Timer
Private GameRefresh As Short = 60 ' ms.
Private counterTimer As Short = 0
Private _jumpAction As Byte = 0
Public Property JumpAction() As Byte
Get
Return _jumpAction
End Get
Set(ByVal value As Byte)
_jumpAction = value
Select Case value
Case Is = 0 ' De pie.
' *****
Case Is = 1 ' Ascendiendo.
Call JumpUp()
Case Is = 2 ' Descendiendo.
Call JumpDown()
End Select
End Set
End Property
Public Sub New()
' Llamada necesaria para el diseñador.
InitializeComponent()
' Agregue cualquier inicialización después de la llamada a InitializeComponent().
Me.SetStyle(ControlStyles.UserPaint, True)
Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Me.DoubleBuffered = True
tmrRefresh.Interval = GameRefresh
tmrRefresh.Start()
End Sub
Private Sub Form1_KeyDown(sender As Object,
e As KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Is = Keys.Left
charPos.X -= 2
Case Is = Keys.Right
charPos.X += 2
Case Is = Keys.Space
JumpAction = 1
End Select
End Sub
Private Sub JumpUp()
If charPos.Y = jumpLimit Then JumpAction = 2 : Exit Sub
If charPos.Y > jumpLimit And JumpAction = 1 Then
charPos.Y -= 5
End If
End Sub
Private Sub JumpDown()
If charPos.Y = charGround Then JumpAction = 0 : Exit Sub
charPos.Y += 5
End Sub
Private Sub tmrRefresh_Tick(sender As Object,
e As EventArgs) Handles tmrRefresh.Tick
' Contador de tiempo.
If counterTimer < 99 Then
counterTimer += 1 : Else : counterTimer = 0
End If
If JumpAction = 1 Then JumpUp()
If JumpAction = 2 Then JumpDown()
Me.Refresh()
End Sub
Private Sub draw(e As PaintEventArgs)
character = New Rectangle(charPos, charSize)
e.Graphics.FillRectangle(Brushes.Red, character)
End Sub
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Call draw(e)
End Sub
End Class