0
\$\begingroup\$

in a tilegame, how can we use several tiles for 1 object?

I thought I could add each tile in a json file, with the type and its coordinates, like :

"line1: type1_xTile1_yTile1, etc."

"line2: type1_xTile1_yTile1, etc."

but in case when an object is bigger than the others, i don't see how to store this information. Is there another common way to store the tiles with different sizes?

Here is an example : the pond is bigger than the other tiles :

enter image description here

Thanks!

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

you can say on pond tiles that they are part of a multi-tile object with a reference to where the actual data is stored

if there is no data then you can create a type for each sub tile of the large object and just store those, so you can find the orientation and bounds by just looking at the type

in game you can have it act as one object.

edit: let say your pond is a 2*2 and needs no other data, then you create 4 tile types pond0, pond1, pond2, pond3, with pond0 the top left file. when you place a pond then you check if all tiles are free and then change all the tiles into the appropriate pond tile

when you interact with it then you forward the interaction to all tiles of the pond and have them act on it properly, (start glowing; have one trigger a sound, etc.)

\$\endgroup\$
2
  • \$\begingroup\$ thanks @ratchet freak could you add more details please? I am not sure to understand what you mean. How could I know which part of the pond should be on "line 2, tile_X 3, tile_Y 4" for example? \$\endgroup\$
    – Paul
    Commented Nov 27, 2013 at 12:37
  • \$\begingroup\$ @ratchet.freak thanks OK I will give it a try, thanks for your answer \$\endgroup\$
    – Paul
    Commented Nov 28, 2013 at 3:34
1
\$\begingroup\$

That looks like different size tiles, and not multiple small tiles in a premade configuration.

If all the tiles are the same size, storing tile sheet information is simple. All you need to know is the number of pixels from the top and left edge of the sheet image.

left_x, top_y

If each tile is a different size, you also need to store the width/height of each tile

width, height

and the drawing offset for each tile. When drawing a larger tile to the screen, you need to know how many pixels +/- x and y over you need to draw this tile (compared to "regular" sized tiles). Example, if you want a very tall object you'll need to draw that tile further up on the screen (-y) than the other tiles.

offset_x, offset_y

So the full data you need for each tile in your tileset becomes:

tile_id, left_x, top_y, width, height, offset_x, offset_y
\$\endgroup\$
1
  • \$\begingroup\$ Yes, thanks, I finally used "Tile1-1", "Tile1-2", -1 and -2 being the offset, and Tile1 a class with the coordinates on my Texture. Thanks for the answer \$\endgroup\$
    – Paul
    Commented Nov 29, 2013 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .