Results 1 to 8 of 8

Thread: Objects on a tilemap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    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
  •