Cita:
|
Empezado por estebanx
...pero solo logro que dicha imagen se mueva de izquierda a derecha con un procedimiento.
|
Bueno es llógico que sólo se mueva con la X, porque no modificas para nada la Y. Otra cosa, es mejor que en lugar de utilizar Sleep, utilices un Timer.
Prueba con lo siguiente; coloca un Timer en el form y utiliza lo siguiente:
Código Delphi
[-]
... en la parte privada
private
_PosXInicial, _PosYInicial, _PosXFinal, _PosYFinal:Integer;
_DeltaX, _DeltaY:Integer;
procedure caminar2(x, y:integer);
... antes de la implementación
const
NUM_MOV = 20;
... en la implementacion
procedure TForm1.caminar2(x, y: integer);
begin
_PosXInicial := img.Left;
_PosYInicial := img.Top;
_PosXFinal := X;
_PosYFinal := y;
_DeltaX := (_PosXFinal - _PosXInicial) div NUM_MOV;
_DeltaY := (_PosYFinal - _PosYInicial) div NUM_MOV;
Timer1.Enabled := True;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Caminar2(x,y);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
XFin, YFin:Boolean;
begin
if (_DeltaX > 0) then begin
if ((img.Left + _DeltaX) >= _PosXFinal) then begin
XFin := True;
end
else begin
img.Left := img.Left + _DeltaX;
end;
end
else begin if ((img.Left + _DeltaX) <= _PosXFinal) then begin
XFin := True;
end
else begin
img.Left := img.Left + _DeltaX;
end;
end;
if (_DeltaY > 0) then begin
if ((img.Top + _Deltay) >= _PosYFinal) then begin
YFin := True;
end
else begin
img.tOP := img.Top + _DeltaY;
end;
end
else begin if ((img.Top + _DeltaY) <= _PosYFinal) then begin
YFin := True;
end
else begin
img.Top := img.Top + _DeltaY;
end;
end;
if (XFin and YFin) then begin
Timer1.Enabled := False;
end;
end;