Autor Beitrag
Herr Bananerama
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 130



BeitragVerfasst: So 30.12.07 18:05 
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  a,v: Real;
  t: Integer;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key = VK_RETURN then
  begin
  Timer1.Enabled:= true;
  v:= a*t;
  Shape1.Left:= Shape1.Left+Round(v); // wieso nochmal - a 
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
t:= 0;
a:= 15; // Das war doch falsch von mir wenn der nicht bremsen soll
v:= 0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
t:= t+1;
a:= a-0.3;
Timer1.Enabled:= false;
exit; // Das hier ist unnötig, kannste streichen
end;

end.
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: So 30.12.07 18:58 
Mal euren Source anguck :lupe:

Was bewirkt der Timer ? :gruebel:

der timer wird bei tastendruck gestartet und berechnet nach gewisser zeit die neue position und wird wieder gestoppt.
das shape wird aber sofort bei tastendruck bewegt.
die berechnung könnte man genausogut in die prcedure wo das shape verschoben wird setzen. (warum dafür nen timer quälen ?

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.


Zuletzt bearbeitet von DrRzf am So 30.12.07 19:01, insgesamt 2-mal bearbeitet
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 18:59 
Weil der Timer t erhöhen muss, damit man v ausrechnen kann.

lg
marc
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 19:01 
Zitat:
Shape1.Left:= Shape1.Left+Round(v); // wieso nochmal - a

weiß ich ehrlich gesagt auch nicht mehr ^^



Zitat:
a:= 15; // Das war doch falsch von mir wenn der nicht bremsen soll

Achso okl.


Zitat:
exit; // Das hier ist unnötig, kannste streichen


Jo, da hatte ich was auprobiert.

lg
marc
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: So 30.12.07 19:03 
was nützts wenn dus aber nicht anzeigst ?
du stoppst den Timer wieder, also führt er nur eine berechnung durch, da kann ichs gleich beim tastendruck machen :think:
Wenn dann im OnKeyDown den Timer bei VK_Left starten.
In der Timerprocedure jedesmal neue Position berechnen und das Shape schieben.
Wenn beschleunigung <= 0 dann den Timer wieder stoppen.

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 19:14 
Ja klaro er erhöht die Zeit, damit die Formel in OnKeyDown (v:= a*t;) wieder stimmt und dann wird im OnKeyDown die Ausgabe gemacht... Weiß jetzt nicht so genau was du meinst. Sorry.


lg
marc

// Und wieso VK_Left???
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: So 30.12.07 19:39 
irgendwie iss das nicht logisch....

im OnKeyDown wird der Timer gestartet damit die neue Position nach xxxms neu berechnet wird.
aber das shape wird bei OnKeyDown neu gezeichnet.

wie soll das funzen ?
ich drück die taste, das shape bewegt sich nicht, da immer noch selbe position.
nach ner gewissen zeit wird die position berehcnet, dann drück ich left und da shape bewegt sich um eine position weiter.

VK_LEFT
meinte eigentlich VK_RETURN ^^


Edit
habs grad mal angetestet.
das shape bewegt sich zuerst kurz bei festhalten der taste, dann wirds schneller, und fetzt dann über den rand raus.
hängt damit zusammen, dass die OnKeyPress immer wieder aufgerufen wird, daher ist der timer für die katz so wie er eingesetzt wird.

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 19:57 
Stimmt, aber ich habe so ziemlich den Faden verloren, wie du es meinst.
Paar Posts vornedran hab ich mal noch geschrieben, wie sich das Shape bewegen soll.

Paar Zeilen Code von dir wie du es machen würdest, könnten mir sicher erheblich weiterhelfen :)

lg
marc
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: So 30.12.07 20:00 
ich baus dir um, tu mir zuerst aber noch einen lukullisches mahl einnehmen :puke:

_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 20:40 
Ok, bin schon gespannt :)


LG
Marc
DrRzf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 260

Win XP Prof
D7 Enterprise
BeitragVerfasst: So 30.12.07 21:25 
hab da mal was gebastelt.
linkes edit = intervall timer
mittleres edit = beschleunigungmultiplikator
rechtes edit = beschleunigungsfaktor (100 = linear; >100 beschleunigungszuwachs nimmt zu, <100 beschleunihgungsf nimmt ab)

Starten kannste das ganze mit dem StartButton ^^

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:
var
  Form1: TForm1;
  b,a,v,e: Real;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  a := a + b;
  v := Power(a,e);
  Shape1.Left:= Shape1.Left+Round(v);
  if (Shape1.Left + Shape1.Width) > Form1.Width then ButtonStartPosClick(Self);
  Label3.Caption := FloatToStrf(v,ffFixed,10,2);
  Form1.Repaint;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ButtonStartPosClick(Self);
end;

procedure TForm1.ButtonStartPosClick(Sender: TObject);
begin
  Timer1.Enabled := false;
  Shape1.Left := 5;
  Timer1.Interval := StrToInt(Edit1.Text);
  b := StrToInt(Edit2.Text) / 1000;
  e := StrToInt(Edit3.Text) / 100;
  a := 0;
  v := 0;
end;

procedure TForm1.ButtonStartClick(Sender: TObject);
begin
  ButtonStartPosClick(Self);
  if Timer1.Enabled then Timer1.Enabled := false
    else Timer1.Enabled := true;
end;
Einloggen, um Attachments anzusehen!
_________________
rein statistisch gesehen darf man keiner statistik trauen die man nicht selbst gefälscht hat.
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: So 30.12.07 21:32 
Wow, danke :)

Jetzt versteh ich auch was du meintest mit dem Timer...
Ok damit ist das Problem gelöst.

Thanks@all

LG
Marc