|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 2007
Messaggi: 648
|
[VB6] Due movimenti in contemporanea
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 Codice:
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
|
|
|
|
|
|
#2 | |
|
Member
Iscritto dal: Dec 2005
Messaggi: 44
|
Quote:
If (KeyAscii = 119) Then ... poi esci subito... End if quindi: If (KeyAscii = 119) Then 'se tocchi barra entra a=true:b=true:while (b)'ciclo infinito fino a chè... if a=true then Sleep 120 pg.Top <20 then pg.Top = pg.Top + 5 'sali if pg.Top >=20 then a =false else Sleep 120 if pg.Top >0 then pg.Top = pg.Top - 5 'scendi if pg.Top <=0 then b=false 'esci dal while endif end while End if edit: <...Volevo sapere come posso fare per potermi comunque muovere a destra o a sinistra duranet il salto...> avevo interpretato male (anche se quello postato potrebbe esserti utile). Per l'edit sopra puoi usare i tasti frecce ovvero right e left salto avanti e indietro come direzione. ciao Ultima modifica di Tesinevb : 12-09-2009 alle 09:07. |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 13:25.




















