error 404
11-09-2009, 22:55
Ho creato un piccolo quadrato in un form e lo muovo tramite tastiera, niente di straordinario fin qui.
Il problema è che ho incluso una specie di "salto" ovvero un movimento rallentato tramite la funzione sleep che parte da una posizione x,y per raggiungere x2,y2 per poi tornare dove prima. Volevo sapere come posso fare per potermi comunque muovere a destra o a sinistra duranet il salto. Insomma stile Super Mario, no?
Grazie ciao
Private Sub Form_KeyPress(KeyAscii As Integer)
If (KeyAscii = 119) Then
pg.Top = pg.Top - 10 'movimento in ALTO
End If
If (KeyAscii = 115) Then 'movimento in BASSO
pg.Top = pg.Top + 10
End If
If KeyAscii = 97 Then 'movimento a SINISTRA
pg.Left = pg.Left - 10
End If
If KeyAscii = 100 Then 'movimento a DESTRA
pg.Left = pg.Left + 10
End If
If (KeyAscii = 32) Then 'SALTO
Sleep 130
pg.Top = pg.Top - 5
Sleep 140
pg.Top = pg.Top - 5
Sleep 150
pg.Top = pg.Top - 5
Sleep 120
pg.Top = pg.Top + 5
Sleep 110
pg.Top = pg.Top + 5
Sleep 100
pg.Top = pg.Top + 5
End if
End Sub
Il problema è che ho incluso una specie di "salto" ovvero un movimento rallentato tramite la funzione sleep che parte da una posizione x,y per raggiungere x2,y2 per poi tornare dove prima. Volevo sapere come posso fare per potermi comunque muovere a destra o a sinistra duranet il salto. Insomma stile Super Mario, no?
Grazie ciao
Private Sub Form_KeyPress(KeyAscii As Integer)
If (KeyAscii = 119) Then
pg.Top = pg.Top - 10 'movimento in ALTO
End If
If (KeyAscii = 115) Then 'movimento in BASSO
pg.Top = pg.Top + 10
End If
If KeyAscii = 97 Then 'movimento a SINISTRA
pg.Left = pg.Left - 10
End If
If KeyAscii = 100 Then 'movimento a DESTRA
pg.Left = pg.Left + 10
End If
If (KeyAscii = 32) Then 'SALTO
Sleep 130
pg.Top = pg.Top - 5
Sleep 140
pg.Top = pg.Top - 5
Sleep 150
pg.Top = pg.Top - 5
Sleep 120
pg.Top = pg.Top + 5
Sleep 110
pg.Top = pg.Top + 5
Sleep 100
pg.Top = pg.Top + 5
End if
End Sub