Hagan lo mismo k en el otro codigo es decir:
Cita:
Ahora la imagen de c0olor negro i otro colo tiene k cerrar con el color negro a la imagen picpac.Copien este codigo y creen una picturebox que se llame "picture1".En picture cargan una imagen con una parte negra i otra de otro color.
Creen una Image dentro del picture que se llame "picpac", procurenle ponerla en la parte que no esta negra del picture1.
Creen un timer i nombrenlo "tmrtimer" ponganle en las opciones enabled FALSE y interval 1.
Creen una Image dentro del picture que se llame "picpac", procurenle ponerla en la parte que no esta negra del picture1.
Creen un timer i nombrenlo "tmrtimer" ponganle en las opciones enabled FALSE y interval 1.
El nuevo codigo:
Cita:
Pruebenlo y diganme como puedo solucionar el problema k antes he comentado.Dim k As Variant
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Sub picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
tmrtimer.Enabled = False
Call moure
k = 0
End If
If KeyCode = vbKeyRight Then
tmrtimer.Enabled = False
Call moure
k = 1
End If
If KeyCode = vbKeyUp Then
tmrtimer.Enabled = False
Call moure
k = 2
End If
If KeyCode = vbKeyLeft Then
tmrtimer.Enabled = False
Call moure
k = 3
End If
End Sub
Private Sub tmrtimer_Timer()
Select Case k
Case 0:
picpac.Top = (picpac.Top + 1)
Call MOVIM1
Call MOVIM2
Case 1:
picpac.Left = (picpac.Left + 1)
Call MOVIM1
Call MOVIM2
Case 2:
picpac.Top = (picpac.Top - 1)
Call MOVIM1
Call MOVIM2
Case 3:
picpac.Left = (picpac.Left - 1)
Call MOVIM1
Call MOVIM2
End Select
End Sub
Function moure()
tmrtimer.Enabled = True
End Function
Function MOVIM1()
Dim XX As Long, YY As Long, A As Long
XX = picpac.Left - 1
YY = picpac.Top - 1
If vbBlack = GetPixel(Picture1.hdc, XX, YY) Then
tmrtimer.Enabled = False
End If
End Function
Function MOVIM2()
XX = picpac.Left + picpac.Width
YY = picpac.Top + picpac.Height
If vbBlack = GetPixel(Picture1.hdc, XX, YY) Then
tmrtimer.Enabled = False
End If
End Function
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Public Sub picture1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
tmrtimer.Enabled = False
Call moure
k = 0
End If
If KeyCode = vbKeyRight Then
tmrtimer.Enabled = False
Call moure
k = 1
End If
If KeyCode = vbKeyUp Then
tmrtimer.Enabled = False
Call moure
k = 2
End If
If KeyCode = vbKeyLeft Then
tmrtimer.Enabled = False
Call moure
k = 3
End If
End Sub
Private Sub tmrtimer_Timer()
Select Case k
Case 0:
picpac.Top = (picpac.Top + 1)
Call MOVIM1
Call MOVIM2
Case 1:
picpac.Left = (picpac.Left + 1)
Call MOVIM1
Call MOVIM2
Case 2:
picpac.Top = (picpac.Top - 1)
Call MOVIM1
Call MOVIM2
Case 3:
picpac.Left = (picpac.Left - 1)
Call MOVIM1
Call MOVIM2
End Select
End Sub
Function moure()
tmrtimer.Enabled = True
End Function
Function MOVIM1()
Dim XX As Long, YY As Long, A As Long
XX = picpac.Left - 1
YY = picpac.Top - 1
If vbBlack = GetPixel(Picture1.hdc, XX, YY) Then
tmrtimer.Enabled = False
End If
End Function
Function MOVIM2()
XX = picpac.Left + picpac.Width
YY = picpac.Top + picpac.Height
If vbBlack = GetPixel(Picture1.hdc, XX, YY) Then
tmrtimer.Enabled = False
End If
End Function
MaxExtreme ahora probare de hacerlo como tu dices

