Hello Guest

Author Topic: Enhanced tilemap manipulation  (Read 3902 times)

greatflash

  • Newbie
  • *
  • Posts: 2
    • View Profile
Enhanced tilemap manipulation
« on: December 09, 2013, 10:28:42 am »
Hello,

Being new to Unity, I decided to start a simple project and recreate an 'old' game of mine using tile maps. http://greatflash.co.uk/index.php?topic=471.0

This was a complete Boulderdash ripoff coded for the old Psion 3a computers and released by Yellow Computing. I know it is basic, but... it was a good starting point and gave me a chance to play with the 2d toolkit.

After less than 10 hours playtime, I have test levels that can be fully played, scrolling larger maps, and all the main code in place (though all within the player script until I work out a good way to split it all up).

Anyway, onto the question...

Currently, all objects move and fall a tile unit at a time (much like Boulderdash did), but... I want everything to move smoothly. ie. To have the boulders fall in pixel units rather than the 64x64 pixel tiles.
This I cannot find a solution to? I can see no way of offsetting a tile by pixels in x/y. This would be a solution as I could change the offset per frame and when it reaches the destination (a total of 64 pixels), I can then move the tile in the tile map.
I did attempt using prefabs as this offered the ability to offset them from origin. But... This looks like it would be rather intensive computationally. ie. the map is a max of 40x40 tiles. I iterate over that map from the bottom right to the top left. The only way (i can see) to find out what prefab is at a location is, for every tile I find, to iterate through the prefab list looking for a map (there could be a prefab for every tile). This it a lot of looping in a single frame.

So, Does anyone have a solution or any ideas that can help me realise my goal?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Enhanced tilemap manipulation
« Reply #1 on: December 10, 2013, 02:50:04 pm »
If you want objects to fall dynamically, you WILL have to create them as prefabs. The tile map editor is for regularly spaced tiles. You can of course create your levels with the tile map editor, but they must be converted into game objects at runtime. 40x40 could be too many tiles, but you could turn off chunks at a time as they went out of screen. The tile map splits stuff into chunks - you can make this smaller so you can turn off chunks as they go out of view. Even if you made the chunks 10x10 pixels - that will greatly reduce the number of visible / processed chunks.

greatflash

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Enhanced tilemap manipulation
« Reply #2 on: December 10, 2013, 04:06:57 pm »
Thanks for the reply.

Using prefabs could be the way to go, my only concern was the overhead involved in finding which prefab is at what tile location. Or am I missing something?

What would have been nice would have been the ability to offset a tile in X and Y. The tile would still be at it's original coordinates internally, but displayed with an offset. If the offset could be polled as well, it would open the tile maps up for the more adventurous with the ability to use the offsets alongside any detection code.

Oh, and it would solve my little problem lol... ;)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Enhanced tilemap manipulation
« Reply #3 on: December 10, 2013, 05:06:13 pm »
Changing the tile offset would require mesh rebuilding, and won't be too fast either... Especially so when it includes colliders. It'll be cheaper to move objects.