Results 1 to 8 of 8

Thread: Objects on a tilemap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    The objects that I had that were bigger than a single tile were broken up into multiple tiles. By doing this I was able to create the illusion of depth by drawing them on different layers relative to the player so the 'front' were rendered behind the player while the 'back' was rendered in front of the player.

    But, back to your question... how could this work if the objects are bigger than a tile? Good question

    I'm not sure and it's not a solution I would pursue personally because of the overheads involved.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  2. #2
    Your original solution was almost perfect, but you are right, on larger maps it would get lower performance. Thus you can divide your map into chunks.

    Code:
    const CHUNKSIZE = 32;
    
    TChunk = class
    public
      posX, posY: integer;
      Tiles: array[0..CHUNKSIZE-1, 0..CHUNKSIZE] of TTile;
      Objects: array of TObject;
    end;
    
    TMap = class
    public
      Chunks: array of array of TChunk;
      function GetTile(x, y: integer): TTile;
    end;
    
    function TMap.GetTile(x, y: integer): TTile;
    var cx, cy: integer;
    procedure
      cx:=x div CHUNKSIZE;
      cy:=y div CHUNKSIZE;
      result:=Chunks[cx, cy].Tiles[x-cx, y-cy]
    end;
    Or something along these lines... Of course you could do range checking in GetTile() to avoid critical errors on negative values or out of boundaries.

  3. #3
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    if I were trying to do someting like this I would use an 8bit index map and use index 0 as a null. the background would be for normal size tiles while the forground would be for larger tiles. then I would add a clip frame that reperesents the view able portion of the map. now all you have to do is move the clipframe around within the map to change the view. on the forground the indexed position would be the top/left and all indexes underneath it would be 0's. your clip frame would have to be larger then the actual view so if a larger tile were half on it would still be displayed.

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
  •