Autor Beitrag
MasterBilke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38

WIN XP
D3 Prof
BeitragVerfasst: Di 20.01.04 21:31 
OK ich bin dabei ein 2D game zu machen.
Folgendes Problem
alles wird ordentlich angezeigt (also bg, figur)
nur der hud will net

ich poste mal den code

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:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DXDraws, Menus, DXClass, DXSprite, DXInput, DXSounds, ExtCtrls;

type
  TForm1 = class(TDXForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Schlieen1: TMenuItem;
    DXDraw1: TDXDraw;
    BG: TDXImageList;
    DXSpriteEngine1: TDXSpriteEngine;
    HG: TDXTimer;
    Chara: TDXImageList;
    DXInput1: TDXInput;
    DXSound1: TDXSound;
    DXWaveList1: TDXWaveList;
    HUD: TDXImageList;
    procedure FormCreate(Sender: TObject);
    procedure HGTimer(Sender: TObject; LagCount: Integer);
    procedure Schlieen1Click(Sender: TObject);
    procedure DrawHud(HitP, AmmoP:Integer);
    procedure ErstelleHud;
  private
    { Private declarations }
    Hintergrund: Array[0..1] of TImageSprite;
    Character: TImageSprite;
    HudG: TImageSprite;
    HudA: Array[0..5] of TImageSprite;
    Nr:Integer;
    HitPoint: Integer;
    Ammo: Integer;
  public
    { Public declarations }
  end;

const
 Bewegung = 10;

var
  Form1: TDXForm;

implementation

{$R *.dfm}

procedure TForm1.ErstelleHud;
var j, k:Integer;
begin
    // Hud zeichnen
    HudG := TImageSprite.Create (DXSpriteEngine1.Engine);
    with HudG do
     begin
     Image := HUD.Items[10];
      X := DXDraw1.Width - Width; Y := DXDraw1.Height - Height; Z := 1;
      Width := Image.Width; Height := Image.Height;
     end;
     
     // Ziffern Malen
     for j:= 0 to 5 do
      begin
       HudA[j] := TImageSprite.Create (DXSpriteEngine1.Engine);
      end;

     with HudA[0] do
      begin
      Image := HUD.Items[0];
       X := HudG.X + 40; Y := HudG.Y + 50; Z := 2;
       Width := Image.Width;
       Height := Image.Height;
      end;

      // Restlichen Ziffern malen
      for k:=1 to 5 do
       begin
        with HudA[k] do
         begin
          Image := HUD.Items[k];
          X := HudA[k-1].X + HudA[k-1].Width;
          Y := HudA[k-1].Y;
          Z := 2;
          Width := Image.Width;
          Height := Image.Height;
         end;
        end;

end;

procedure TForm1.DrawHud(HitP, AmmoP:Integer);
var wert1, wert2:String;
begin

 wert1 := IntToStr(HitP);
 wert2 := IntToStr(AmmoP);
 if Length(wert2) = 2 then wert2 := '0' + wert2;
 if Length(wert2) = 1 then wert2 := '00' + wert2;
 if Length(wert1) = 2 then wert1 := '0' + wert1;
 if Length(wert1) = 1 then wert1 := '00' + wert1;

 HudA[0].Image := HUD.Items[StrToInt(wert1[1])];
 HudA[1].Image := HUD.Items[StrToInt(wert1[2])];
 HudA[2].Image := HUD.Items[StrToInt(wert1[3])];
 HudA[3].Image := HUD.Items[StrToInt(wert2[1])];
 HudA[4].Image := HUD.Items[StrToInt(wert2[2])];
 HudA[5].Image := HUD.Items[StrToInt(wert2[3])];

end;

procedure TForm1.Schlieen1Click(Sender: TObject);
begin
 Close;
end;


procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
    HitPoint := 100;
    Ammo := 49;
    ErstelleHud;
     DrawHud(HitPoint, Ammo);
// Der Hintergrund //
 for i:=0 to 1 do
  begin
   Hintergrund[i] := TImageSprite.Create (DXSpriteEngine1.Engine);
  end;
   with Hintergrund[0] do
   begin
    Image := BG.Items[0];
    X := 0; Y := 0; Z := -1;
    Width  := Image.Width;
    Height := Image.Height;
   end;

   with Hintergrund[1] do
   begin
    Image := BG.Items[0];
    X := hintergrund[0].Width + hintergrund[0].X; Y := 0; Z := -1;
    Width  := Image.Width;
    Height := Image.Height;
   end;
   // Hauptcharacter
    Character := TImageSprite.Create( DXSpriteEngine1.Engine);
     with Character do
     begin
      Image := Chara.Items[0];
    X := 50; Y := 300; Z := 0;
    Width  := Image.Width;
    Height := Image.Height;
     end;
     Nr := 0;
{ ******************************************************** }
    // Play Sound
{    DXWaveList1.Items[0].Play(false);  }
end;

procedure TForm1.HGTimer(Sender: TObject; LagCount: Integer);
begin
  // HUD zeichnen
  DrawHud(HitPoint, Ammo);
  // Bewegung Character
  DXInput1.Update;
  if isUp in DXInput1.States then Character.Y := Character.Y - Bewegung;
  if isDown in DXInput1.States then Character.Y := Character.Y + Bewegung;

  if Character.Y >= DXDraw1.Height - Character.Height then
   Character.Y := DXDraw1.Height - Character.Height;
  if Character.Y <= 350 - Character.Height then
   Character.Y := 350 - Character.Height;

  if (Nr mod 2 = 0) then Inc(Nr) else Dec(Nr);
  Character.Image := Chara.Items[Nr];

  // Hintergrund verschieben
  with Hintergrund[0] do
   begin
    X := X - Bewegung;
   end;
  with Hintergrund[1] do
   begin
    X := X - Bewegung;
   end;
   if (Hintergrund[0].X <= 0) then
   Hintergrund[1].X := Hintergrund[0].X + Hintergrund[0].Width;
   if (Hintergrund[1].X <= 0) then
   Hintergrund[0].X := Hintergrund[1].X + Hintergrund[1].Width;
  DXDraw1.Surface.Fill(clBlack);
  DXSpriteEngine1.Draw;
  DXDraw1.Flip;
end;

end.


ich erkenne irgentwo keine fehler
warscheinlich mag mich delphi net
achja ich nutz die delphi x komponenten
MasterBilke Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38

WIN XP
D3 Prof
BeitragVerfasst: Mi 21.01.04 06:42 
gut hab mein fehler selbst gefunden

wens interessiert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// Hud zeichnen
    HudG := TImageSprite.Create (DXSpriteEngine1.Engine);
    with HudG do
     begin
     Image := HUD.Items[10];
      X := DXDraw1.Width - Width; Y := DXDraw1.Height - Height; Z := 1;
      Width := Image.Width; Height := Image.Height;
     end;


hier erstelle ich zuerst die koordinaten mit hilfe der breite des bildes.
da ich die breite aber erst danach einstelle nimmt er sicher als breite 0 und zeichnet alles außerhalb des DXDraw :)