Autor Beitrag
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 26.01.09 21:36 
das problem ist das der timer die patrone immerwieder zeichnet in seinem intervall
wenn ich nun den timer in der procedure TForm1.PaintBox1MouseDown auf false mache geht es, dann ist die patrone weg.
aber das ist ja nicht mein ziel, es soll trotz timer:= true weg gehen
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:
111:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    PaintBox1: TPaintBox;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure Zeichnen;
    procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
    procedure FormActivate(Sender: TObject);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
   Hg:TBitmap;
    patrone:TBitmap;
   Puffer:TBitmap;
    xAkt,yAkt,Geschwindigkeit,AnzDurchgange:integer;
    SummandX,SummandY,xAktExt,yAktExt:extended;
x,y:integer;
  StreckeX,StreckeY:integer;
  StreckeC:extended;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
xAkt:=0;
yAkt:=0;
 { ...und Anfangshöhe zuweisen }
patrone:=TBitmap.Create;
Hg:=TBitmap.Create;
Hg.LoadFromFile('Hg.bmp');
patrone.LoadFromFile('patrone.bmp');
patrone.Width:=100;
patrone.Height:=100;
patrone.Transparent:=false;
Puffer:=TBitmap.Create;
hg.Width := form1.Width; { Anfangsbreite... }
hg.Height := form1.Height;
Puffer.Width:=hg.Width;
Puffer.height:=hg.Height;
 Geschwindigkeit:=5;

end;

procedure TForm1.Zeichnen;
begin
  Puffer.Canvas.Draw(0,0,Hg);
  Puffer.Canvas.Draw(xAkt,yAkt,patrone);
  paintbox1.Canvas.Draw(0,0,Puffer);

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin
xAkt:=xAkt+5;
  Zeichnen;
  end  ;



procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  Zeichnen;
end;



procedure TForm1.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Zeichnen;

end;

procedure TForm1.FormActivate(Sender: TObject);
begin
paintbox1.width:=form1.width;
paintbox1.height:=form1.Height;
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (X >= Xakt) and (X <= Xakt + patrone.Width)
    and (Y >= Yakt) and (Y <= Yakt + patrone.Height) then
  begin
    Puffer.Canvas.Draw(0, 0, Hg);
    PaintBox1.Canvas.Draw(0, 0, Puffer);
  end;
end;
end.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 26.01.09 21:41 
Dann musst du dir eben merken, ob du die Patrone noch zeichnen musst oder nicht. Dafür kannst du ja eine Variable vom Typ Boolean nehmen und dann prüfen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  Form1: TForm1;
  PatroneSichtbar: Boolean = true;

// Unsichtbar setzen
PatroneSichtbar := false;

// Nur zeichnen wenn sichtbar
Puffer.Canvas.Draw(0, 0, Hg);
if PatroneSichtbar then
  Puffer.Canvas.Draw(xAkt, yAkt, patrone);
PaintBox1.Canvas.Draw(0, 0, Puffer);

Nebenbei:
ausblenden Delphi-Quelltext
1:
2:
Hg.LoadFromFile('Hg.bmp');
patrone.LoadFromFile('patrone.bmp');
Relative Pfade sind eine schlechte Idee, siehe hier:
www.delphi-library.d...ewtopic.php?p=499701
ultraz06 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 84



BeitragVerfasst: Mo 26.01.09 21:53 
danke du bist der beste ;)