any1 have any starfield source for delphiX please ?
any1 have any starfield source for delphiX please ?
Sure What sort of starfield are you looking for a so called 2D starfield or a 3D starfield?
I can only provide you with the source of a 2D starfield, but it's really easy (once you know it)
Do it by the book, but be the author!
<br />
<br />Visit the Lion Productions website at:
<br />http://lionprod.f2o.org
Okay I looked on my hdd for the source of the 2D starfield and here are the usefull pieces
[pascal]
var StarField : Array[0..STARS] of TStar;
StarGraphics: Array[0..3] Of TDirectDrawSurface;
Procedure TForm1.InitStarField();
var D : Integer;
Begin
Randomize;
For D := 1 To STARS do
Begin
StarField[D].X := Random(VideoModeX);
StarField[D].Y := Random(VideoModeY);
StarField[D].Speed := 1 + Random(9);
StarField[D].Size := Random(3);
End;
StarGraphics[0] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[0].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster1.bmp');
StarGraphics[1] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[1].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster2.bmp');
StarGraphics[2] := TDirectDrawSurface.Create(DXDraw1.DDraw);
StarGraphics[2].LoadFromFile(ExtractFilePath(ParamStr(0)) + 'Ster3.bmp');
End;
Procedure TForm1.DrawStarField();
var D : Integer;
Begin
For D := 1 To STARS do
Begin
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarGraphics[StarField[D].Size]);
StarField[D].Y := StarField[D].Y + StarField[D].Speed;
If StarField[D].Y >= VideoModeY Then
Begin
StarField[D].Y := 0;
StarField[D].X := Random(VideoModeX);
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarGraphics[StarField[D].Size]);
End;
End;
End;
[/pascal]
Oh a usefull remark might be that you can replace the VideoModeX, VideoModeY with Screen.Width, Screen.Height!
call the InitStarField(); before any drawing thing and call DrawStarField(); in your main gameloop!
Hope this helps...
Do it by the book, but be the author!
<br />
<br />Visit the Lion Productions website at:
<br />http://lionprod.f2o.org
thanx dude,it worx perfectly )
this code is suposed to work without any change?
I say this cause I get errors...
Well, of course I made it work, but using bitmaps loaded intro a DXImageList and drawing from there...
I don't really know how tou use TDirectSurfaces (seems unbeliveble , but I always use the other method..). when It tries to load the images there's an error, and also Delphi says that the DXDraw.Draw sentence is incorrect...
:/
If you want to load TDirectDrawSurface images, you'll have to initialize the DXDraw component first:
DXDraw1.Initialize; // call this in the Form1.Create !
Do it by the book, but be the author!
<br />
<br />Visit the Lion Productions website at:
<br />http://lionprod.f2o.org
Yes, now I it works (anyway I don't know what was the problem, cause I did initialize DXDraw).
Anyway the Draw call doesn't work. It needs a TRect instead of a TDirectDrawSurface. I changed the line to this :
DXDraw1.Surface.Draw(StarField[D].X, StarField[D].Y, StarField[D].r, StarGraphics[StarField[D].Size],false);
where r is a TRect.
was this necesary?
DelphiX has two draw procedures, one uses rect, the other doesn't. In some Delphi versions the rect-versions overrules the other draw procedure and therefor you need to add the rect-version!
Do it by the book, but be the author!
<br />
<br />Visit the Lion Productions website at:
<br />http://lionprod.f2o.org
Thank you
Bookmarks