Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Best way to manage multi-tile item on isometric map
Started by J@V0 Jun 03 2019 11:26 AM

4 replies to this topic
qiso isometric map multi-tile

Best Answer richard11 , 04 June 2019 - 02:11 AM

I'd do it by splitting the database into two tables. One to define a building with ID and X,Y placements on the map, and one to define building pieces with references back to the buildings ID and then X,Y positions relative to the buildings X,Y.

For example, a 2x1 size building one have two records in tblBuildingSprites, like so:

fldID 1, fldBuilding 1, fldX 1, fldY 1
FldID 2, fldBuilding 1, fldX 2, fldY 1

Then in the building table you might position that building somewhere in the middle of a map:

fldID 1, fldX 40, fldY 16

The result would be two sprites, positioned at 40,16 and 41,16. I.e. their buildings origin X + their own X, by their buildings origin Y + their own Y.

The origin doesn't even need to be the top left corner, because you could have a sprite positioned at -1,-1 for example, and 40+-1 would drop it into 39.

It'd also mean that your buildings can be of any size, any shape, and even consist of sprite pieces shared amongst other buildings.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 50 posts
  • Corona SDK

Hi,

 

I'm using Qiso to manage an isometric map with items (buildings) covering one tile. Everything works fine.

 

Now I need to make some buildings cover sevral tiles (e.g. 2x3). I had a few thoughts but wanted to check if there was a better approach..

 

  1. In my sqlite3 database: I currently have X and Y coordinates for each building, those now become the origin of the building (e.g. top-left). I thought of adding two columns with xSize and ySize representing the number of tiles occupied (from origin) in the building properties.
  2. Avoiding collision when placing buildings on the map. I need to find a way to say "this tile is occupied", that's easily done when checking X and Y (origin) but what would be the best way to check if the tile is taken by a multi-tile building?
  3. Representation on the map: I guess I need a larger image which will cover several tiles. That should be straight forward.

Thanks

J@V0



[TOPIC: post.html]
#2

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 407 posts
  • Corona SDK

Personally I'd just break the buildings up into multiple sprites, i.e. a building that covers a 2x2 tile would simply become 4 separate sprites. Subject to how you're creating the graphics, this shouldn't be difficult to produce. Remember that the engine will layer foreground tiles over the top of background tiles so any ugliness in the resulting chops should be hidden away anyway.

This way, all you need to do is script your building placement code to drop the appropriate sprites into each individual tile, and then your basic X,y check on the tiles you're about to drop new sprites onto should return whether there's already building there or not.

[TOPIC: post.html]
#3

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 50 posts
  • Corona SDK

Good point, that seems like a good way to go. However, how can I connect 4 sprites to one building in my database? Today I have a building ID and ONE tileID but in that case I will need to have 4 tileIDs...



[TOPIC: post.html]
#4

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 407 posts
  • Corona SDK

  Best Answer

I'd do it by splitting the database into two tables. One to define a building with ID and X,Y placements on the map, and one to define building pieces with references back to the buildings ID and then X,Y positions relative to the buildings X,Y.

For example, a 2x1 size building one have two records in tblBuildingSprites, like so:

fldID 1, fldBuilding 1, fldX 1, fldY 1
FldID 2, fldBuilding 1, fldX 2, fldY 1

Then in the building table you might position that building somewhere in the middle of a map:

fldID 1, fldX 40, fldY 16

The result would be two sprites, positioned at 40,16 and 41,16. I.e. their buildings origin X + their own X, by their buildings origin Y + their own Y.

The origin doesn't even need to be the top left corner, because you could have a sprite positioned at -1,-1 for example, and 40+-1 would drop it into 39.

It'd also mean that your buildings can be of any size, any shape, and even consist of sprite pieces shared amongst other buildings.

[TOPIC: post.html]
#5

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 50 posts
  • Corona SDK

Fantastic! Thanks a lot!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: qiso, isometric map, multi-tile