Archived

This topic is now archived and is closed to further replies.

FooFighter

DXDraw Surface draw problem

Recommended Posts

FooFighter    122
Thank you guys for the previous help Now I''m stuck again...you know it is the first time I go into developing a level editor I''m working with DelphiX Well, it seems that the DXDraw surface is limited to the DxDraw components height and width, for example, the form default size is 640x480 (windowed) and when I maximize it and try to create or draw a tile outside these "limits" they are created but not drawn. I tried to change the value of the SurfaceHeight and SurfaceWidth properties but they don''t see to change anything... Delphi just rules!!!

Share this post


Link to post
Share on other sites
Harry Hunt    542
as far as I remember, you will have to re-initialize DXDraw whenever the window is resized (which is awfully slow). A better solution of course is a fixed width and height...
Or something that I''ve been doing a lot: Use GDI for the editor and DirectX for the actual game.

Share this post


Link to post
Share on other sites
FooFighter    122
Hi ,

Yeah, use GDI, that's a nice sugestion but as I did a lot of Work with DelphiX already, I would like to know how to set the DXDraw Surface size when I create a new level... so I would put scrollbars to scroll the level, resizing wouldn't be a problem.

[edited by - FooFighter on April 28, 2003 9:10:29 PM]

Share this post


Link to post
Share on other sites
cairnswm    181
Just draw a portion of the map at a time.

// Draw Map
for I := 0 to MaxX do
for J := 0 to MaxY do
Begin
TileImages.Items[Tiles[I,J].TileID].Draw(DXDraw1.Surface,I*32-Camera.Y,J*32-Camera.Y,0);
End;

Camera represents the Left,Top corner of the map being displayed. This means that only a portion is being displayed at anyone time. To make it faster first check that the tile being drawn is on the screen.


Share this post


Link to post
Share on other sites
Harry Hunt    542
I don''t think that''s his problem, cairnswm.

The back-buffer of a DXDraw object is created when DXDraw is initialized and has a fixed size from then on. If you set the align of the DXDraw object to "alClient" it will resize when its container (the form) is resized, but the backbuffer won''t resize with it. So if the backbuffer is 640x480, it will stay like that, even if you resize the DXDraw object to 1024x768.

Share this post


Link to post
Share on other sites
FooFighter    122
Hello,

I already switched to GDI, I''m thinking of using the Form Canvas for all the drawing stuff, is it the best way? Other thing: When I draw the grid in the form canvas when the Form is 640x480, when I resize the form to a less size the and switch back to 640x480 part of the grid desappears!

Thank you for the help

Marcelo.

Share this post


Link to post
Share on other sites
FooFighter    122
I figured out that the Form Canvas is not the best way of doing that ....

I found the TImage component a very nice way of drawing stuff in the app, the grid went ok there I think I''ll go with that

Thank you for the help and keep up the good work with XCessGDK! :-D

See ya ,

Marcelo.

Share this post


Link to post
Share on other sites
Harry Hunt    542
Hey, XCESS comes with a double-buffered GDI component. Check out the "XSWindowsDraw" examples.

Of course you can do it without xcess, too.

I like to use a TPaintBox. Set Align to alClient.
Define a private variable "BackBuffer: TBitmap".
Create the BackBuffer in "OnFormCreate".
Assign the OnFormResize event and add the following code to it:

BackBuffer.Width := PaintBox1.Width;
BackBuffer.Height := PaintBox1.Height;

Create an OnPaintBoxPaint event and add the following code:

with BackBuffer.Canvas do
begin
Pen.Color := clWhite;
Brush.Color := clWhite;
Rectangle(ClipRect);
// Draw your stuff here
end;

BitBlt(PaintBox1.Canvas.Handle, 0, 0, BackBuffer.Width, BackBuffer.Height, BackBuffer.Canvas.Handle, 0, 0, SRCCOPY);

Free the BackBuffer in the OnFormClose event.

This can be pretty fast and it doesn't flicker.
Whenever the user performs a change, call

PaintBox1Paint(Self);

Do not call PaintBox1.Repaint. If you do, it will flicker.


[edited by - Harry Hunt on April 29, 2003 6:09:13 PM]

Share this post


Link to post
Share on other sites