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



BeitragVerfasst: So 24.02.08 16:41 
Hi!

Ich lass ein TImage so Bewegen:

ausblenden Delphi-Quelltext
1:
2:
Image1.left := image1.left + 1;
refresh;


damit es sich fortbewegt. Nun will ich das es schneller geht aber immer noch nur ein Pixel pro schritt,
damit es fließend aussieht. Wie kann ich das machen?
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: So 24.02.08 16:44 
Dann musst du diesen Code eben öfter aufrufen.

Ohne mehr Code ausßenrum (wann wird das Aufgerufen?) kann man dir so nur relativ schlecht helfen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: So 24.02.08 16:49 
Indem du den gezeigten Code öfter aufrufst...
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 24.02.08 16:52 
ok hier der code für die bewegung als tastaturtaste

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
  VK_Right: RECHTS;
  VK_LEFT : LINKS;
end;
  if image2.Left <= 15 then
  image2.Left := 16;

  if image2.left >= 630 then
  image2.Left := 629;
 end;

das am ende ist die begrenzung des feldes

und hier die definition von RECHTS und LINKS
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Rechts;
begin
  image2.Picture.LoadFromFile(pfad+'BildR.bmp');
  image2.Left := image2.Left + 10;
  refresh;
end;

procedure TForm1.LINKS;
begin
  image2.Picture.LoadFromFile(pfad+ 'BildL.bmp');
  Image2.Left := Image2.Left - 10;
  refresh;
  end;
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 24.02.08 16:54 
Du lädst doch nicht allen ernstes jedesmal das Bild neu? :shock:
Ich würd eventuell beide Bilder einmal in eine Imagelist laden und gegenfalls entsprechend zuweißen.
Müsst IMHO Resourcen schonender sein.
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 24.02.08 16:59 
nein

wenn sich die figur nach links bewegt, dann soll sie ja nicht rückwärts laufen.
darum habe ich ein gespiegeltes bild damit es für die beweugung nach links und rechts
ein richtiges bild hat.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 24.02.08 17:04 
Ich bezog darauf, dass Du die LoadFromFile Routine bei jedem Links bzw Rechts Klick aufrufst. Ich denke nicht, dass das sehr effizient ist.
Ansonsten belehrt mich bitte eines besseren. ;)
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 24.02.08 17:06 
Wie kann ich das besser machen?
Und da ist ja immer noch das Problem mit der geschwindigkeit.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 24.02.08 17:24 
Geschwindigkeit ist Bewegung pro Zeit,
also verringerst du entweder die Zeit zwischen den einzelnen Bewegungsschritten, oder du erhöhst die Bewegung.
ausblenden Quelltext
1:
s = s0 + v * t					


mfg
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 24.02.08 17:31 
wie soll ich die zeit zwischen den schritten verringern?

wenn ich die bewegung erhöhe dann siehts nicht so fließend aus.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 24.02.08 17:31 
Hi,
user profile iconBlack Force hat folgendes geschrieben:
aber immer noch nur ein Pixel pro schritt, damit es fließend aussieht
Erfahrungsgemäß sieht es auch bei mehreren Pixeln realistisch aus.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: So 24.02.08 17:36 
Schon aber es ist mit 10 Pixel immer noch zu langsam und nicht mehr fließend.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: So 24.02.08 18:43 
stell trotzdem besser so viel ein wie ruckellos möglich ist...

user profile iconBlack Force hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Rechts;
begin
  image2.Picture.LoadFromFile(pfad+'BildR.bmp');
  image2.Left := image2.Left + 10;
  refresh;
end;

procedure TForm1.LINKS;
begin
  image2.Picture.LoadFromFile(pfad+ 'BildL.bmp');
  Image2.Left := Image2.Left - 10;
  refresh;
  end;
Das Laufzeitproblem dürfte wie oben erwähnt vom ständigen Laden kommen. Also zumindest merken, welches bild geladen ist und nur wenns falsche geladen ist neu laden wäre ja schonmal was^^

mfG,



Moderiert von user profile iconAXMD: Beiträge zusammengefasst

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 25.02.08 13:52 
Am besten nimmst du dir zwei Images, und lädst in das eine das linke Bild, und in das andere das rechte. Dann brauchst du folgenden Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  case Key of
    VK_Right:
      if X < 629 then           // Wenn Bild noch nicht rechts angekommen
      begin
        inc(X);                 // Laufvariable inkrementieren
        RechtesBild.Left := X;  // Bild-Position anpassen
        RechtesBild.Show;       // Richtiges Bild anzeigen
      end;
    VK_Left:
      if X > 15 then            // Wenn Bild noch nicht links angekommen
      begin
        dec(X);                 // Laufvariable dekrementieren
        LinkesBild.Left := X;   // Bild-Position anpassen
        LinkesBild.Show;        // Richtiges Bild anzeigen
      end;
  end;
end;

X ist eine globale Variable, die beim Programmstart auf die Startposition gesetzt wird.
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mo 25.02.08 14:35 
OK.
Vielen Dank für eure Antworten! :D
Dann mach ich mal weiter.
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 25.02.08 14:52 
Naja sowas würde ich halt nicht im OnKeyDown Event machen, da hast du halt ne begrenzte Geschwindigkeit. Mit einem Timer oder dem OnIdle Event sollte das schon eher funktionieren.

Schau dir am besten auch das hier an:

wiki.delphigl.com/in...nt#Kurz-Beschreibung

mfg
Black Force Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 27.02.08 15:55 
Hat schon früher Probleme mit GetTickCount(); :(
Muss das endlich mal lernen.
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Mi 27.02.08 17:24 
user profile iconF34r0fTh3D4rk hat folgendes geschrieben:
Naja sowas würde ich halt nicht im OnKeyDown Event machen, da hast du halt ne begrenzte Geschwindigkeit. Mit einem Timer oder dem OnIdle Event sollte das schon eher funktionieren.

Schau dir am besten auch das hier an:

wiki.delphigl.com/in...nt#Kurz-Beschreibung

mfg


Also in einer globalen Variable die richtung merken und eine weitere ob die Taste gedrückt ist. wenn die Taste gedrückt wird setzt du gedrueckt auf true, beim loslassen auf false.
beim drücken einer taste setzt du auch die richtung fest.

beim bewegen dann testen, welches bild geladen ist... ob dus jetzt neu lädtst oder beide lädtst und neu zuweist ist dabei egal.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
type
  TForm1 = class (TForm)
  private
    [...]
    Bewegen: Boolean;
    bildGeladen: (VK_LEFT,VK_RIGHT);
  [...]
  end;

implementation

{$R *.dfm}

procedure TForm1.onKeyPress(var Key: Char);
begin
  if Key in [VK_LEFT,VK_RIGHT] and
     (not Bewegen or (bildGeladen <> Key)) then begin
    Bewegen := true;
    bildGeladen := Key;
    self.ladeBild(Key);
  end;
end;


Das als kleiner Ansatz. Dazu eine TTimer-Komponente und im onTimer bewegen.

mfG,

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 28.02.08 17:30 
user profile iconHidden: Bei deiner Variante wird beim Tastendruck angefangen, das Bild zu bewegen. Beim Druck der anderen Taste fängt das Bild an, sich in die andere Richtung zu bewegen. Aufhören tut es auch nicht mehr.

Es empfiehlt sich hier, GetAsyncKeyState zu verwenden:

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:
var
  Last: Boolean;  // False: Linkes Bild wird angezeigt  |  True: Rechtes Bild

procedure TForm1.FormCreate(Sender: TObject);
begin
  Last := True;     // Standardmäßig Linkes Bild
  LeftImage.Hide;   // Linkes Bild ausblenden => Rechtes Bild wird angezeigt
end;

procedure TForm1.TimerTimer(Sender: TObject);
begin
  // Wenn Links, aber nicht rechts gedrückt
  if (GetAsyncKeyState(vk_Left) < 0) and (GetAsyncKeyState(vk_Right) >= 0) then
  begin
    // Wenn rechtes Bild noch angezeigt, linkes Bild anpassen
    if Last then
    begin
      LeftImage.Left := RightImage.Left;   // Position anpassen
      LeftImage.Show;
      RightImage.Hide;
      Last := False;
    end;
    LeftImage.Left := LeftImage.Left - 1;  // Bild bewegen
  end
  // Wenn Rechts, aber nicht links gedrückt
  else if (GetAsyncKeyState(vk_Right) < 0) and (GetAsyncKeyState(vk_Left) >= 0) then
  begin
    // Wenn linkes Bild noch angezeigt, rechtes Bild anpassen
    if not Last then
    begin
      RightImage.Left := LeftImage.Left;    // Position anpassen
      RightImage.Show;
      LeftImage.Hide;
      Last := True;
    end;
    RightImage.Left := RightImage.Left + 1;  // Bild bewegen
  end;
end;

user defined image In Delphi 7 getestet.