Ver Mensaje Individual
  #2  
Antiguo 23-02-2005
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is online now
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 19.438
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
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;
 
     { Private declarations }
     procedure caminar2(x, y:integer);
 
 ... antes de la implementación
 const
   NUM_MOV = 20;
 
 ... en la implementacion
 
 procedure TForm1.caminar2(x, y: integer);
 begin
 
   // Deinimos posiciones
   _PosXInicial := img.Left;
   _PosYInicial := img.Top;
   _PosXFinal := X;
   _PosYFinal := y;
   // debfinimos Deltas de "avance"
   _DeltaX := (_PosXFinal - _PosXInicial) div NUM_MOV;
   _DeltaY := (_PosYFinal - _PosYInicial) div NUM_MOV;
   // Actibvamos el movimiento
   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
 
   // X positiva
   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  // X negaiva
     if ((img.Left + _DeltaX) <= _PosXFinal) then begin
       XFin := True;
     end
     else begin
       img.Left := img.Left + _DeltaX;
     end;
   end;
 
   // Y positiva
   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  // Y negaiva
     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;
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita