Results 1 to 3 of 3

Thread: TDirectDrawSurface's...

  1. #1

    TDirectDrawSurface's...

    Now this may seem completely stupid but as I have only been using DelphiX for a short time I need your help with an issue.

    Basically, if you have read some of my other questions you will know that I am trying to create a rather large RPG which uses a grid of 256x256. My Current method of drawing is to take the players position... then based on the screen size draw the tiles (11x11) in so as not to slow it down too much.

    I am currently trying create another layer by which to display trees and objects you can walk under. However, when I try and draw it using the same (11x11) tiles visible method it slows down. I know there are things called TDirectDrawSurface's, but I cant seem to draw onto these, I can only load one image or tile onto the surface? Is this right?

  2. #2

    TDirectDrawSurface's...

    I'm not sure what you have sofar, but here's a short overview of how you can use TDirectDrawsurface in your game.

    First the surfaces for your tiles.

    const
    MAXTILES = 9;

    var
    Tiles : array[0..MAXTILES] of TDirectDrawSurface;

    for imgCounter := 0 to MAXTILES do
    begin
    Tiles[imgCounter] := TDirectDrawsurface.Create(DXDraw1.ddraw);
    Tiles[imgCounter].LoadFromGraphic(Form1.DXImagelist1.items.items[imgCounter].picture.graphic);
    end;
    The images 0 through 9 correspond with the images in your dximagelist.

    Then you have your tilemap. I assume you'll use two maps one for the tiles and one for the objects. I'll only show you the tiles version, as the objectversion is nearly the same.

    const
    MAPWIDTH = 250;
    MAPHEIGHT = 250;

    var
    TileInfo : array [0..MAPWIDTH, 0..MAPHEIGHT ] of byte;

    You probably have you own load version, here's an very very basic one
    for xpos:=0 to MAPWIDTH do
    for ypos:=0 to MAPHEIGHT do
    begin
    TileInfo[xpos,ypos] := random(10);
    end;
    end;

    Then you can draw these tiles using:
    for xpos := 0 to (form1.Width) div 32 do
    for ypos := 0 to form1.Height div 32 do
    dxdraw1.surface.draw((xpos*32),(ypos*32),tiles[1].clientrect,
    tiles[TileInfo[xpos, ypos],false);

    You can use objects in a similar manner.

    I hope some of this made any sense, I haven't cheched the code, so you may a warning or two (hope not)

    Otherwise you can also read tutorials 3 and 4 on my website. I have explained things (and more) much better.

  3. #3
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    TDirectDrawSurface's...

    Also see The Lions tutorials in the Tutorials and Links section.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •