Autor Beitrag
Clemens L.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 18:49 
Hallo,

hoffe ihr könnt mir helfen. Ich schaff es einfach nicht, eine einfache Shape in richtung des Mauszeigers zu bewegen. Kann mir einer von euch helfen?


Mfg.

HT
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 30.12.06 19:03 
Soll er immer sofort beim Mauszeiger sein oder soll er nachrutschen? Bei resterem einfach OnMouseMove des Forms nehmen oder gleich ein eigenes Icon definieren. Bei zweiterem übern Timer...
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 19:11 
an einen timer hatte ich auch schon gedacht, aber ich glaub ich hab mich falsch ausgedrückt. Er soll, wenn ich eine Prozedur aufrufe, mit einer vorgegebenen Geschwindigkeit zum mauszeiger fahren.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 30.12.06 19:17 
Dann brauchste nen Timer ;). Die CursorPosition bekommste mithilfe von Mouse.CursorPos raus. Der Rest dürfte dann ja klar sein ;).
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 19:27 
Danke für deine Hilfe, aber es ist ja so, ich schaffe es nicht die Shape einmal in Richtung maus fahren zu lassen. Ich wollte ja eine Prozedur dafür schreiben, weiss aber nicht so recht weiter... :oops:
rey003
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP
BDS 2006
BeitragVerfasst: Sa 30.12.06 19:37 
du musst in dem Timer schauen wo die Maus und das shape ist! Und dann vergleichen und die position des shaps anpassen! :wink:

_________________
Daniel S.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 30.12.06 19:40 
Timer aufs Form klatschen, Enabled auf true und Zeit einstellen.

Im Timerereignis dann:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  tmp: Integer;
begin
  tmp:=Mouse.CursorPos.X-Image1.Left;
  if abs(tmp)>10 then tmp:=10//abs=Betrag (Unit Math)
  Image1.Left:=Image1.Left+tmp;

  tmp:=Mouse.CursorPos.Y-Image1.Top;
  if abs(tmp)>10 then tmp:=10;
  Image1.Top:=Image1.Top+tmp;


Könnte so funzen. ICh habe jetzt der einfachheit halber den Timer angelassen ;).
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 19:44 
:?: Habe deinen Code ausprobiert Heiko, leider geht das Object immer nach rechts unten, egal was ich mache! :shock:
rey003
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP
BDS 2006
BeitragVerfasst: Sa 30.12.06 19:45 
Glaube nicht das das funzt! was ist denn wenn die Maus über dem Shape ist?? Da wandert das Shape aber trotzdem nach unten :?

_________________
Daniel S.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 30.12.06 19:55 
Jaja, Vorzeichen vergessen ;).



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  tmp: Integer;
begin
  tmp:=Mouse.CursorPos.X-Image1.Left;
  if abs(tmp)>10 then tmp:=10*sign(tmp); //abs=Betrag (Unit Math)
  Image1.Left:=Image1.Left+tmp;

  tmp:=Mouse.CursorPos.Y-Image1.Top;
  if abs(tmp)>10 then tmp:=10*sign(tmp);
  Image1.Top:=Image1.Top+tmp;


Könnte jetzt funzen ;).
rey003
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP
BDS 2006
BeitragVerfasst: Sa 30.12.06 20:00 
kleiner zusatz:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm2.Timer1Timer(Sender: TObject);
var
  tmp: Integer;
  point: TPoint;
begin
  point:=ScreenToClient(Mouse.CursorPos);
  tmp:= point.X-Shape1.Left;
  if abs(tmp)>10 then tmp:=10*sign(tmp); //abs=Betrag (Unit Math)
  Shape1.Left:=Shape1.Left+tmp;


  tmp:=point.Y-Shape1.Top;
  if abs(tmp)>10 then tmp:=10*sign(tmp);
  Shape1.Top:=Shape1.Top+tmp;
end;

Jetzt muss nur noch die Breite und Höhe mit ins Spiel dann geht's :wink:

_________________
Daniel S.
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 20:01 
Nun ja, wenn ich deinen Code ausprobiere, folgt das Objekt meinem Mauszeiger immer mit etwas abstand. Aber das ist nicht das was ich brauche ... :cry: Ich kriegs einfach nicht hin, eine Prozedur zu schreiben, die z.B. ein TShape-Objekt zur Position des Mauszeigers fährt.
rey003
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP
BDS 2006
BeitragVerfasst: Sa 30.12.06 20:08 
Willst du das das Shape den kürzesten Weg zur Maus nimmt? dann musst du erst eine Linie zwischen den beiden Pukten berechnen und das Shape dann die linie lang schicken! :?

//Edit: Oder nur das es sich mal in Richtung der Maus begibt?

_________________
Daniel S.
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 20:13 
@rey : egal, hauptsache es kommt bei der Maus an! :P

Aber ich habs geschafft, wenn auch umständlich :
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.GotoMouse;
 var isFinish : boolean;
begin

  isFinish := false;
while not isFinish do   begin
 application.ProcessMessages;
if mouse.CursorPos.X > SP.Left then sp.Left := sp.Left +1 else sp.Left := sp.left -1;
     application.ProcessMessages;
if mouse.CursorPos.Y > SP.Top then sp.Top := sp.Top +1 else sp.top := sp.top -1;
 application.ProcessMessages;
 if mouse.CursorPos.X = sp.Left then if mouse.CursorPos.Y = sp.Top then isFinish := true;
 end;


end;


Ich denke das kann man sehr umständlich nennen.

Und nochmal danke an alle die mir geholfen haben! :D




EDIT : Der Code geht nur, wenn das Fenster maximiert ist!
rey003
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP
BDS 2006
BeitragVerfasst: Sa 30.12.06 20:21 
Irgendwie geht das bei mir nicht :cry:

_________________
Daniel S.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Sa 30.12.06 20:26 
@hackerTreff: Erfüllt nicht deine Fragestellung, du wolltest eine vorgegeben Geschwindigkeit haben ;).

@rey003: Mitm kürzesten Weg haste recht. Daran hatte ich auch gedacht, hatte aber in dem Moment keine Lust mein Gehirn in
dieser Richtung zu Martern

@hackerTreff: Wie speziell meinst du das mit dem Abstand? Liegt es bei dir vlt. daran, dass dein Timer-Intervall zu groß ist (1000 ist definitiv zu groß ;) )? Oder was meinst du jetzt? Denn du wolltest es ja so, dass das Bild hinterhergerutscht kommt.
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 20:29 
@heiko : Mann kann ja mit Sleep() das schneller oder langsamer machen .. @heiko (2.) :

Ne, interval war normal ... es blieb nur so 5 - 6 cm davor einfach stehen, aber das lag daran, das es nicht maximiert war das fenster, und du kein ScreenToClient() benutzt hast!

Aber trotzdem danke für die Hilfe!


Zuletzt bearbeitet von Clemens L. am Sa 30.12.06 20:34, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 30.12.06 20:30 
Der heißt immer noch Heiko und nicht Heike :lol:

Sleep ist nicht gut, denn dann hängt dein ganzes Programm. Wenn du ScreenToClient und ein kleines Intervall beim Timer benutzt, ist das viel besser.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Clemens L. Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 158

Win Xp SP3
D6 Enterprise, Turbo Delphi Explorer
BeitragVerfasst: Sa 30.12.06 20:34 
huch, stimmt! habe eben in der shoutbox mitgelesen und bin mit den Namen durcheinandergeommen!