Results 1 to 6 of 6

Thread: Getting tile id

  1. #1

    Getting tile id

    Ok, I'm struggling with calculating x/y position of tile in tileset (needed to get tile sprite) based on tile id.

    To getTile(ID) function I'm passing tile id. Tiles are arranged in pretty standard tile grid, like this:

    Code:
    00 01 02 03 04 05 06 07
    08 09 10 11 12 13 14 15
    16 17 18 19 20 21 22 23
    24 25 26 27 28 29 30 31
    Tileset can have any amount of tiles horizontally and vertically. The problem is how to get proper x/y coordinates of specific tileid (for simplicity we assume tile size is 16).

  2. #2
    Don't know what's the tile size relevance, since you care only about the horizontal amount of tiles in the pictured ordering scheme.
    x := id mod row_width; y := id div row_width;

  3. #3
    Doesn't allegro alow using of tiled textures. I think that in allegro they are refered as "atlas bitmaps".

    Othervise it is quite similar as handling snapping tile to grid that we discussed in one of your other threads.

  4. #4
    imcold, thanks.

    SilverWarrior: Yeah, it support it, but as much as TCanvas does - i.e. you need to copy rects yourself. But thanks to imcold I'll manage it.

  5. #5
    Quote Originally Posted by Darkhog View Post
    SilverWarrior: Yeah, it support it, but as much as TCanvas does - i.e. you need to copy rects yourself. But thanks to imcold I'll manage it.
    Wait there is no automated system for that in allegro?

  6. #6
    Allegro means "Allegro Low-Level game routines" and tile stuff is high-level. Allegro just allows you to load, create and draw bitmaps, but doesn't provide any "tile map" functionality.

    The Allegro.pas' demo game does use tiles, but the engine was written from scratch. Anyway you (Darkhog) should take a look into the sources (tilemap.pas and sprites.pas). The sprites unit shows how to calculate the "tile ID" from the sprite position.
    No signature provided yet.

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
  •