Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 24.08.05 20:11 
Einen Typewriter Texteffekt erstellen

Ich habe zur Darstellung (un)DelphiX benutzt, ein normales Canvas oder ein Label reichen aber völlig aus.

Hier zuerst 2 globale Variablen.
ausblenden Delphi-Quelltext
1:
2:
3:
var
  tick: integer = 0;
  str: string = '';


Dann brauchen wir noch einen Timer und ein Anzeigefeld.
Mein Timer sieht dann so aus:
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:
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
  DXDraw1.Surface.Fill(clblack);
  inc(tick);
  if tick = 1 then
    str := str + 'T';
  if tick = 2 then
    str := str + 'h';
  if tick = 3 then
    str := str + 'i';
  if tick = 4 then
    str := str + 's ';
  if tick = 5 then
    str := str + 'S';
  if tick = 6 then
    str := str + 'o';
  if tick = 7 then
    str := str + 'f';
  if tick = 8 then
    str := str + 't';
  if tick = 9 then
    str := str + 'w';
  if tick = 10 then
    str := str + 'a';
  if tick = 11 then
    str := str + 'r';
  if tick = 12 then
    str := str + 'e ';
  if tick = 13 then
    str := str + 'w';
  if tick = 14 then
    str := str + 'a';
  if tick = 15 then
    str := str + 's ';
  if tick = 16 then
    str := str + 'c';
  if tick = 17 then
    str := str + 'r';
  if tick = 18 then
    str := str + 'e';
  if tick = 19 then
    str := str + 'a';
  if tick = 20 then
    str := str + 't';
  if tick = 21 then
    str := str + 'e';
  if tick = 22 then
    str := str + 'd ';
  if tick = 23 then
    str := str + 'b';
  if tick = 24 then
    str := str + 'y ';
  if tick = 25 then
    str := str + '.';
  if tick = 26 then
    str := str + '.';
  if tick = 27 then
    str := str + '.';
  with DXDraw1.Surface.Canvas do
    begin
      brush.Color := clblack;
      Font.Color := clwhite;
      Font.Name := 'Times New Roman';
      Font.Size := 16;
      TextOut(1010, str);
      Release;
    end;
  DXDraw1.Flip;
end;

jetzt denkt bestimmt jeder, boah das ist mühselig, unübersichtlich und schwer zu bearbeiten, RICHTIG ! Denn das geht auch kürzer!
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function TypeWriter(str: string; tick: integer): string;
begin
  if (tick > 0and (tick <= length(str) then 
    result := copy(str, 0, tick);
end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
var
  strtext: string = 'This Software was created by Seth 2005';

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
  DXDraw1.Surface.Fill(clblack);
  if tick < length(strtext) then
    inc(tick);
  str := typewriter(strtext, tick);
  with DXDraw1.Surface.Canvas do
    begin
      brush.Color := clblack;
      Font.Color := clwhite;
      Font.Name := 'Times New Roman';
      Font.Size := 16;
      TextOut(1010, str);
      Release;
    end;
  DXDraw1.Flip;
end;

Ds ganze kann man natürlich auch mit einem Label machen ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var
  strtext: string = 'This Software was created by Seth 2005';

procedure TForm1.Timer1Timer(Sender: TObject; LagCount: Integer);
begin
  if tick < length(strtext) then
    inc(tick);
  str := typewriter(strtext, tick);
  Label1.Caption := str;
end;

Viel Spass damit ;)

MFG Seth 8)
Moderiert von user profile iconjasocul: Beitrag geprüft am 05.05.2006
[meta]Typewriter[/meta]


Zuletzt bearbeitet von F34r0fTh3D4rk am Do 25.08.05 15:29, insgesamt 5-mal bearbeitet