Autor Beitrag
mathias
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 58
Erhaltene Danke: 3



BeitragVerfasst: Mi 12.06.02 21:24 
Ideal geeignet für die Spieleprogrammierung.
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:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

Type
  TSprite = record
    a, b : TBitmap;
  end;

const
  anz = 100;

var
  Sprite : array[1..anz] of TSprite;
  HGBit  : TBitmap;
  ShadowBit : TBitmap;

  spos : array[1..anz] of TPoint;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  i, x, y : Integer;
begin
  Timer1.Interval := 10;
  HGBit := TBitmap.Create;
  ShadowBit := TBitmap.Create;
  for i := 1 to anz do begin
    spos[i].X := Random(ClientWidth);
    spos[i].Y := Random(ClientHeight);
    Sprite[i].a := TBitmap.Create;
    Sprite[i].b := TBitmap.Create;
    Sprite[i].a.Width  := 32;
    Sprite[i].a.Height := 32;
    Sprite[i].b.Width  := 32;
    Sprite[i].b.Height := 32;
    Sprite[i].a.Canvas.Create.Brush.Color := $00;
    Sprite[i].a.Canvas.FillRect(Rect(003232));
    for x := 1 to 4 do begin     // Pseudo Sprites erzeugen
      Sprite[i].a.Canvas.Pen.Color := $BF shl x;
      Sprite[i].a.Canvas.Rectangle(x * 3, x * 332 - x * 332 - x * 3);
    end;
    // Es kann auch eine Bmp Datei genommen werden, wichtig ist das die Umrandung schwarz ist.
    for x := 0 to 32 do begin
      for y := 0 to 32 do begin
        if Sprite[i].a.Canvas.Pixels[x, y] = 0 then Sprite[i].b.Canvas.Pixels[x, y] := $FFFFFF else
          Sprite[i].b.Canvas.Pixels[x, y] := $000000;
      end;
    end;
  end;
  HGBit.LoadFromFile('d:\winnt\angler.bmp');
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  i : Integer;
begin
  for i := 1 to anz do begin
    Sprite[i].a.Free;
    Sprite[i].b.Free;
  end;
  HGBit.Free;
  ShadowBit.Free;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  ReFresh;
  ShadowBit.Width := ClientWidth;
  ShadowBit.Height := ClientHeight;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  i : Integer;
begin
  ShadowBit.Canvas.StretchDraw(Rect(00, ClientWidth, ClientHeight), HGBit);
  for i := 1 to anz do begin
    Inc(spos[i].X); if spos[i].x > ClientWidth  then spos[i].x := 0;
    Inc(spos[i].Y); if spos[i].y > ClientHeight then spos[i].y := 0;
    StretchBlt(ShadowBit.Canvas.Handle, spos[i].x, spos[i].y, 3232, Sprite[i].b.Canvas.Handle, 003232, SRCAND);
    StretchBlt(ShadowBit.Canvas.Handle, spos[i].x, spos[i].y, 3232, Sprite[i].a.Canvas.Handle, 003232, SRCPAINT);
  end;
  canvas.StretchDraw(Rect(00, ClientWidth, ClientHeight), ShadowBit);
end;

end.
:D
Dirk
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Do 13.06.02 16:54 
Canvas.Pixels wuerde ich nicht nehmen, das ist ziemlich langsam. Ich glaube, Canvas.ScanLine ist besser geeignet.
Pit
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Do 20.06.02 19:52 
Dirk hat folgendes geschrieben:
Ich glaube, Canvas.ScanLine ist besser geeignet.

Dürfte schwierig werden, ein Gerätekontext hat keine solche Eigenschaft. Eine Bitmap hingegen schon.

MfG Pit.
Dirk
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mi 26.06.02 10:00 
Sprite[n].a ist doch ein Bitmap. Oder hab ich jetzt was falsch verstanden?
mathias Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 58
Erhaltene Danke: 3



BeitragVerfasst: Mi 26.06.02 20:30 
ja ist es. :)