Autor Beitrag
Black Force
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 21:38 
Hallo, :D

Ich möchte gerne ein Bild zu einem bestimmten Punkt bewegen. Wie kann ich bewirken, dass er direkt zu diesem Punkt gelangt :?:
Bis jetzt muss mein Bild erst die y Achse entlang fahren und dann die x Achse bis es am Ziel ist.
Hoffe ihr könnt mir helfen.
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 10.12.07 21:55 
Zeig mal deinen Quelltext, am einfachsten geht es wenn du left und top des images gleichzeitig änderst.

Wenn du etwas Ahnung von Mathe hast (strahlensätze und satz des Pythagoras) kannse, dir auch eine relativ flüssige Bewegung basteln.
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 22:04 
das hab ich jetzt nur als Übung für bewegungen gemacht. Es ist ein kreis und wenn man drauf klickt bewegt er sich immer zu einem anderen Punkt:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
unit nix;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure Image1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x, y: integer;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Image1.Picture.LoadFromFile('c:\bob.bmp');
  color := clblack;
  Form1.DoubleBuffered:=True;
end;

procedure TForm1.Image1Click(Sender: TObject);
begin
 Application.ProcessMessages;
  x := random(550)+30;
  y := random(450)+30;
  if Image1.Left < x then
  repeat
  Image1.Left := Image1.Left + 1;
  repaint; sleep(1);
  Application.ProcessMessages;
  until
  Image1.Left >= x
  else if Image1.Left > x then
  repeat
  Image1.Left := Image1.Left - 1;
  repaint; sleep(1);
  Application.ProcessMessages;
  until
  Image1.Left <= x;


  if Image1.top < y then
  repeat
  Image1.top := Image1.top + 1;
  repaint; sleep(1);
  Application.ProcessMessages;
  until
  Image1.top >= y
  else if Image1.top > y then
  repeat
  Image1.top := Image1.top - 1;
  repaint; sleep(1);
  Application.ProcessMessages;
  until
  Image1.top <= y;
  end;

end.
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 10.12.07 22:13 
ja okay das problem ist, das du zwei verschiedene Schleifen für jeweils die X/Y Koordinate hast und natürlich zuerst die eine Schleife abgearbeitet wird und dann die andere, dein Code müsste ungefähr so aussehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
while (image1.left<>x) or (image1.top <>Y) do 
begin
 if image1.left<x then 
    image1.left:=image1.left+1;

 if image1.left>x then 
    image1.left:=image1.left-1;

//dasselbe machst du auch für Y und image1.top
//und rufst deine repaint und sleep prozeduren auf
end;
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 22:15 
OK
Ich probiers mal ...
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 22:20 
Cool 8)

hat geklappt, obwohl manchmal x schneller fertig ist als y oder umgekehrt. Aber das liegt wohl eher daran, dass die Wege unterschiedlich weit sind.

Danke :D
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 10.12.07 22:27 
user profile iconBlack Force hat folgendes geschrieben:
Aber das liegt wohl eher daran, dass die Wege unterschiedlich weit sind.
Du musst die Geradengleichung aufstellen und daraus dann für jeden x-Wert den y-Wert berechnen, dann klappt das auch.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 22:37 
Wie meinst du das, mit Geradengleichung?
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Mo 10.12.07 22:43 
hi

nehmen wir an, du willst das Objekt in einem Winkel von 45 Grad zum Ursprung des Koordinatensystems an einer gedachten Linie bewegen, dann wäre x = y, oder bei anderen Winkeln z.B. x = 2y oder 2 x = y

_________________
Gruß Aga
Jann1k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 866
Erhaltene Danke: 43

Win 7
TurboDelphi, Visual Studio 2010
BeitragVerfasst: Mo 10.12.07 22:44 
du hast zwei Punkte die gegenwärtigen koordinaten deines images und die koordinaten des zielpunktes, aus diesen kannst du eine Geradengleichugn aufstellen ( y = mx + b ). nun erhöhst/erniedrigst du die x-koordinate (=left) deines images um 1 und kannst dann wenn du die Geradengleichung hast, durch einsetzen von x die dazugehörige Y-koordinate ermitteln.
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 10.12.07 22:47 
achsooooo
jetzt hab ichs verstanden.

Danke für die Antworten