PDA

View Full Version : Getting tile id



Darkhog
14-06-2013, 08:02 PM
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:


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).

imcold
14-06-2013, 08:29 PM
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;

SilverWarior
14-06-2013, 09:21 PM
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.

Darkhog
17-06-2013, 07:14 PM
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.

SilverWarior
17-06-2013, 07:49 PM
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?

Ñuño Martínez
27-06-2013, 09:08 AM
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.