Search Unity

SpriteTile, a fast dynamic tile system (RELEASED)

Discussion in 'Assets and Asset Store' started by Eric5h5, Dec 11, 2013.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Could be the thing about texture bleeding caused by not using padding between tiles, perhaps.

    --Eric
     
  2. G0sub

    G0sub

    Joined:
    Apr 28, 2015
    Posts:
    10
    Excellent. No need for an updated file, I'll just remove my hack when the next version drops. Thanks!
     
  3. AssembledVS

    AssembledVS

    Joined:
    Feb 23, 2014
    Posts:
    248
    Hey, Eric.

    I am currently experimenting with SpriteTile - it looks pretty great and well-documented so far.

    Is it possible to move objects on a per-pixel level within the editor, not necessarily snapped to the grid? I have something similar going within Unity's own editor and U2DEX (pixels to units at 100, snap amount: 1, grid enabled and sized to the size of my tiles).
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Tiles are always snapped to a grid, but you can change the pivot arbitrarily, though that affects all tiles of that particular type. For individual tiles, you can use GrabSprite to convert it to a normal sprite so you can move it as you like, and PutSprite to convert it back to a tile.

    --Eric
     
  5. Cultured

    Cultured

    Joined:
    Dec 11, 2008
    Posts:
    31
    Hi,

    I'm considering purchasing this plugin but I have one question once you have created your tilemap are you able to access the map data to be passed to an array?

    The reason I ask is that I'm creating a turn based tactics style game and would like to able to use this data for pathfinding.

    Cheers
    Ben
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, there are GetTile functions; see the reference guide here.

    --Eric
     
  7. Cultured

    Cultured

    Joined:
    Dec 11, 2008
    Posts:
    31
    Cheers Eric, picked Sprite Tile up this morning!
     
  8. Nixaan

    Nixaan

    Joined:
    May 30, 2013
    Posts:
    118
    Look at "conversations" at your user profile.
     
  9. G0sub

    G0sub

    Joined:
    Apr 28, 2015
    Posts:
    10
    Small feature request: I'd like a method to return all triggers within a subset of the map. Basically, GetTriggerPositions, but allowing the caller to specify an x, y, width, and height to restrict the search area.
     
  10. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    Hello, I just purchased your pack and I'm having some weird issues, everything was just working fine but now I see this message after a few minutes of testing :
    No tile layers are set up
    UnityEngine.Debug:LogError(Object)
    SpriteTile.Tile:CheckParams(Int32) (at Assets/Plugins/SpriteTile/Tile.cs:3259)
    SpriteTile.Tile:GetCollider(Vector3, Int32) (at Assets/Plugins/SpriteTile/Tile.cs:2413)
    Player:Update() (at Assets/Codes/Player.cs:19)
    NullReferenceException: Object reference not set to an instance of an object
    SceneManager.LateUpdate () (at Assets/Plugins/SpriteTile/SceneManager.cs:108)
    The only code I wrote within your packages is this:
    Code (csharp):
    1.  
    2.         Vector3 v = GetComponent<Rigidbody2D>().transform.position;
    3.         if (Tile.GetCollider (v, 3)) {
    4.             SpriteRenderer[] go = GameObject.Find ("SpriteTileLayer3").transform.GetComponentsInChildren<SpriteRenderer> ();
    5.             foreach (SpriteRenderer g in go) {
    6.                 g.color = new Color (1F, 1F, 1F, 0.1F);
    7.             }
    8.         } else {
    9.             SpriteRenderer[] go = GameObject.Find("SpriteTileLayer3").transform.GetComponentsInChildren<SpriteRenderer>();
    10.             foreach(SpriteRenderer g in go)
    11.             {
    12.                 g.color = new Color(1F, 1F, 1F, 1F);
    13.             }
    14.         }
    15.  
    The idea was a 3rd layer of roofs so when the player enters the layer the roof would turn transparent.
    Do you have any idea of what might be ?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like you need to run the "Set SpriteTile Sorting Layer Names" menu item; see the "How layers work" page in the docs. However it's never a good idea to touch the tile objects manually. Use the API functions, such as SetColorBlock.

    --Eric
     
  12. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    Thanks Eric, I was checking the method publicstaticvoidSetColorBlock (Int2p1, Int2p2, intlayer, Color32color) but I cannot trace the final result, can you help me to achieve the same as GameObject.Find ("SpriteTileLayer3").transform.GetComponentsInChildren<SpriteRenderer> ().color ?

    And one more thing, I'm seeying a pink border in the edge, I double checked the tiles and they are fine, there is no pink border, what could it be?

    Thank you.
     
    Last edited: May 6, 2015
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use SetColorBlock to cover the entire layer, so p1 is Int2.zero and p2 is Int2(layerWidth-1, layerHeight-1). I'd suggest using padding with your sprite atlas, or else just use single images per tile, and let Unity handle the atlas.

    --Eric
     
  14. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    It worked to one texture file but I don't think it will work anymore with tiled :/ I will have to manually correct the xml files
     
  15. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    You can do basically anything with the data. That is one of the cool things about TileMap data structures. In my main game project I have a layer for Enemies and Obstacles. Another layer for Collectibles (hidden treasures and so forth). These layers are deactivated so they are never displayed then as the player enters each area I scan the relevant tiles for that area and spawn the appropriate Enemy, Obstacle and Collectible GameObjects.

    I recently started a second little side project just because I needed to get my head out of the other from time to time. Here is a screenshot for my tile map data:


    The first 4 layers are used for the parallax scrolling background.
    The 5th layer is for Enemy placement.

    All that is needed is to make some tile images representing the Enemies. In my case, I just created images E0, E1, E2, E3... and so forth with each one corresponding to a type of enemy. More accurately they reference a type and certain styling attributes for that enemy. For example E3, E4, E5, E6 and E7 are all for one Enemy Type but E3 moves in a wave pattern starting out moving upward, E4 is the same but starts out moving downward, E5 and E6 are the same as E3 and E4 but the starting velocity is faster and E7 is the same except the enemy moves only horizontally with no wave pattern. That is probably more detailed than you cared to know but I thought it might be useful to consider how you can style in different attributes even for the same enemy types by simply using a different Enemy Tile.

    Markers are what I call these things. Because all they do is mark a location on the map where an enemy or other object appears that I need to spawn into a GameObject from a Prefab.

    The screenshot above shows the first 3 waves of enemies.

    I simply advance a position tracker as the player moves through the stage and each time the position advances by a full tile I scan the next column of the Enemy Marker Layer. All enemies found are spawned as GameObjects in their appropriate positions.
     
    Last edited: May 7, 2015
  16. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    I'm also trying to figure the tiles limit, I tested with a 4 layered 10.000x10.000 map and there was no success :/, any idea or reference to achieve it?
    I saw a product feature for "massive maps" but I can't figure how it works
     
    Last edited: May 7, 2015
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I tried 10K x 10K, 4 layers, and didn't have any problems. Keep in mind this is four hundred million tiles, and even though SpriteTile only uses 7 bytes/tile, that's around 2.7GB. So it probably won't work in Unity 4 (32-bit editor). While it does work in Unity 5, it would be more practical to use smaller chunks, say 1K x 1K.

    --Eric
     
  18. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    Yes, I think it would be better to use 1k chunks but I need smooth transitions between chunks so the user wont notice :/
    Do you think it would be possible to do something like this?
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use LoadMapBlock to load sections, so in combination with SetMapBlock it's pretty easy to do chunk loading.

    --Eric
     
  20. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    Is it possible to set physics collider tiles to only affect sprites on the same layer? I have multiple layers of tiles that my sprites can move between, but currently sprites on layer 1 are colliding with the physics collider tiles from layer 2 as well.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use SetColliderLayer to set different SpriteTile layers to different physics layers.

    --Eric
     
  22. HeavenDust

    HeavenDust

    Joined:
    May 6, 2015
    Posts:
    6
    Eric, thank you for your fast answers, everything you've said have worked :)
    I would also like to know if you have had any experience implementing SpriteTile with minimaps or if there is any method that could help me
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I haven't done that, but I expect you could use GetTile and use the results to build a texture, or maybe use a second camera.

    --Eric
     
  24. beit

    beit

    Joined:
    Mar 5, 2015
    Posts:
    24
    Hello SpriteTile team, thanks a lot for this amazing piece of art, I just bought and I'm starting to know it. It will take a bit but from my first understanding the basic feature are almost drop in and go. I'll give this a try really soon. I would like to ask you if by any chance there is a way of getting the gem hunt script in c#. Thanks a lot and have a great day.
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you for purchasing SpriteTile! I don't have the Gem Hunt script in C#, sorry.

    --Eric
     
  26. beit

    beit

    Joined:
    Mar 5, 2015
    Posts:
    24
    Hey Eric, ok no worries I tried :)
    Do you have any preferred plugin for pathfinding that fits your tool that you would suggest?

    Enrico
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I haven't used pathfinding as such with SpriteTile myself (just waypoints so far), so I wouldn't be able to recommend anything. I do have plans to add built-in pathfinding at some point.

    --Eric
     
  28. archwaykitten

    archwaykitten

    Joined:
    Jun 12, 2014
    Posts:
    14
    I don't know whether this is a SpriteTile question, or just a general Unity workflow question, but I'm trying to update SpriteTile from 2.7 to the latest 2.9 version, but I can't figure out how to do so without breaking my game (and not in the expected ways outlined in the update notes).

    I've been going to Windows->Asset Store, then tabbing over to the downloads page, locating the SpriteTile 2.9 package and pressing import. This seems to delete all of my tilesets. Is there a better way I should be updating to new versions?



    I've also been using the source files for 2.7 rather than using the DLLs, if that complicates matters. I'd be happy to go back to using DLLs, except I'm having trouble doing that as well.

    In the documentation I found the following passage:

    "Note about DLL and source code usage
    If at some point you decide to switch from the DLL to the source code, follow these steps:
    1) Remove the DLLs from the Plugins folder and the SpriteTile/Editor folder.
    2) Add the source code.
    3) On the SpriteTile/Resources/TileManager object, the TileManager reference will now be missing. Replace
    it with the TileManager script that you just added. Your data will not be lost when you do this.
    If you want to switch from the source code to the DLL, the process is the same, except you’d remove the
    source code from the appropriate folders and add the DLL again."

    How do you add the DLL again? I can add the sourcecode by doubleclicking on the "SpriteTileSource.unitypackage" within the SpriteTile directory, but there's no "SpriteTileDLL.unitypackage" to click on if I want to go back.
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can import SpriteTile to get the DLLs again; "plugins/SpriteTile.dll" and "SpriteTile/editor/TileEditor.dll" are two of the items that are imported. If you import the DLLs you should remove the source code.

    As for deleting tilesets, when you import version 2.9, make sure to uncheck SpriteTile/Resources/TileManager.asset. That should not have been included, sorry; I've uploaded a new version that fixes this, but it will have to go through the approval process. In the meantime just don't import the TileManager.asset file.

    --Eric
     
  30. Neroir

    Neroir

    Joined:
    Feb 2, 2015
    Posts:
    7
    Hi Eric.

    How does SetRotationBlock works? Does it rotate each tile contained in the block individually or does it rotate the block as a whole? I need to add into a map objects that can be rotated, and don't know which option is better: object as group tiles (only possible if the block rotates as a whole) or object as sprites not linked to tiles.... What do you suggest?
     
  31. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep.

    Objects as sprites, since the block doesn't rotate as a whole.

    --Eric
     
  32. Yukichu

    Yukichu

    Joined:
    Apr 2, 2013
    Posts:
    420
    Okay, started to seriously play with this. Definite ups and downs. Initially, wouldn't work, updated asset, had the dreaded .dll.1 issue with Unity 5, just deleted the whole folder, imported again, and worked... but lost all data, as to be expected. Not your fault, just annoying.

    Desires:
    - Can you change the rotation pivot for rotating the camera? Right now, it is always the center of the camera and I'd like to have the option to move it if necessary.
    - Someone else mentioned, the interface could use some work. It just seems cluttered and crazy.
    - Is there a setting to change which Unity Layer (not tilemap layer) is being used? It defaults to, well, default, and while I could probably write a script, it'd be nice to just have the option already there.
    - More individual tile options or ease of use for setting them. If I want to set a single rotated tile, I need to select the tile from the Tiles section, select the rotation, then repaint it. Ability to select tiles already on the map, which would auto-select the relevant tile, and allow you to rotate it via hotkey would be nice, or flip it.

    Nice:
    - Seems fast. The occlusion culling is awesome. Rotation appears to work fine, though I really wish you could just use standard camera rotation, as I'll need a second camera for showing the tilemap now.

    Anyhow, nice product, UI could use some love, has some definite features over other products.
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thanks for the feedback! I'm not aware of a case where you'd need to lose data; if the TileManager reference gets lost for whatever reason, you can just reconnect it and keep everything (see page 3 in the docs). The "Sorting" drop-down can be used to change the sorting layer. If you mean GameObject/render layer, there's the SetTileRenderLayer function. You can rotate each tile by using the rotate keys, or by alt-clicking a tile and setting the rotation explicitly, and using the P key selects the tile under the cursor. I'd recommend reading the keyboard shortcut document.

    I spent some time organizing the UI logically, so all related stuff is grouped together; it's just that there's a lot of functionality at this point. Other than hiding stuff in tabs or something (which I don't like—I prefer everything to be always accessible), I think it's just a matter of using it for a little while. I was thinking of tooltips, but I'd have to figure out a good way of doing that; I can't see a way to get the standard method—hover over something for a bit then you get a popup—to work, since the window won't refresh if the user isn't moving the mouse.

    --Eric
     
  34. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    I am getting an error when upgrading spritetile:

    Assets/AstarPathfindingProject/ExampleScenes/Example12_Procedural/ProceduralWorld.cs(63,20): error CS0433: The imported type `Int2' is defined multiple times

    I understand this type is also defined for spritetile.... any quick way to correct this?
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, looks like I neglected to put Int2 in a namespace. It should work if you use the source and edit the Int2 file so it starts like this:

    Code (csharp):
    1. namespace SpriteTile {
    2.  
    3. public struct Int2 {
    Then add a } at the end.

    --Eric
     
  36. Blue-Wolf

    Blue-Wolf

    Joined:
    May 27, 2014
    Posts:
    20
    Great plugin and documentation Eric!

    Does SpriteTile play nice with Git version control? I’m about to add it to my project’s repo and was wondering if there’s anything SpriteTile specific I should keep in mind (gitignore and all).

    Cheers!
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not that I know of.

    --Eric
     
  38. Eric-Gu

    Eric-Gu

    Joined:
    Feb 19, 2014
    Posts:
    28
    Excuse me. After I select a tile from list in the editor and then I could click somewhere in the level to place this tile. Currently, the tile is always in the center of grid of the level. Could I change the position of tile with an offset?
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, change the pivot point of the sprite.

    --Eric
     
  40. Blue-Wolf

    Blue-Wolf

    Joined:
    May 27, 2014
    Posts:
    20
    Thanks for the prompt support Eric. Good to hear there shouldn’t be any Git issues with SpriteTile. In the off chance I encounter issues I’ll share my learnings.

    This plugin is magic. I ran a 40 million tiles procedural dungeon level, all created at runtime with SpriteTile, and the FPS remained in the 100s. You rock!
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you! Now I'm imagining the sort of person who'd build a dungeon that takes 40 million tiles to depict, and what he'd do with it. You could throw, like, everybody in that dungeon. ;)

    --Eric
     
  42. twelveplusplus

    twelveplusplus

    Joined:
    Mar 25, 2013
    Posts:
    12
    is there a way that i can add translucency to a a particular tile from within spritetile?
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use Tile.SetColor.

    --Eric
     
  44. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    Eric, I'm working on a more efficient infinite tile system here. I had one a while back, but it looped over the entire level every time it changed chunks, and I think that is probably unnecessary. Imagine if the player moves one tile (or one "chunk" of tiles) to the left. I really only need to load a few new columns of data on the right after shifting the map left, but with my current system, that means I still need to SetTile on every tile on the map. It feels inefficient, and I know there's likely a better way to do it.

    I guess what I'm asking, is how would I achieve this map shifting effect:



    I'd like to "shift" the whole level by one or more tiles. The data is not changing, just the location of the data. I imagine such a shift would be more efficient than x*y SetTile calls, possibly utilizing some kind of combination of LoadMapBlock, SetMapBlock, or GetMapBlockBytes. Then I could go to the "fresh" columns, and use SetTile on those to load the procedural data, avoiding x*(y-chunkSize) unnecessary calls to SetTile. Is this map shift possible? How would I go about it?

    If it isn't already possible, then this is a feature request. It could really speed up procedural stuff.
     
    Last edited: May 29, 2015
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I wouldn't shift the entire map; instead I'd reset the player's position, as discussed here.

    --Eric
     
  46. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    Well, I'd like to have an infinite (or very large, in my case) map, I did the math, and having that map in memory would take several gigabytes of memory. Resetting the player's position still requires the entire map to be in memory, so I'd like to "stream" it into the tilemap as needed, to remove this size limitation. Right now, I'm dynamically setting all the tiles, but this understandably causes slowdowns. Shifting is the only way I know of to solve both issues.

    I am also doing floating origin, so I do teleport the player on occasion, but for a different reason. Another option might be to have multiple tile maps being displayed (3x3 or so), and only loading the ones that change, but I'm not sure if SpriteTile supports this, and it wouldn't be as efficient as a shift, as more tiles than necessary would be changed, and multiple tilemaps means potentially losing some draw calls.
     
    Last edited: May 29, 2015
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You would do it in chunks, so you can use the block commands and not SetTile every tile.

    --Eric
     
  48. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    43
    I know premature optimization is the root of all evil, but I still feel pretty good about this.

    I was working on a super complicated chunking thing when I realized that chunking is just splitting up the work into infrequent but still somewhat large quantities. I noticed that the smaller I made the chunks, the faster it tended to be, because it was loading evenly and frequently. So I made a scrolling world which utilized the shift I outlined earlier. It only loads in rows and columns as needed. If there is a large amount of work, it will divide it out amongst multiple frames. It only uses SetTile on the new row of tiles, the rest it moves as one block.

    Of course, since it loads over time, there is a possibility that you move more than once before the work queue is cleared, so every shift looks at that queue and shifts the queued tiles too.

    Now I just need to make it load based on the distance to the center of the map, rather than in chronological order, and then a map large enough can load all of its data off of the screen. The map itself would ideally be just larger than the screen.
     
    Last edited: Jun 2, 2015
  49. apache_cd

    apache_cd

    Joined:
    Mar 30, 2013
    Posts:
    10
    HI , I want to put a game object in the tiled map, how to do that ?
    If Its status will keep after it leave the viewport by scrolling the map?
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't support for arbitrary objects in maps per se, but you can just use standard GameObjects as usual. You can also use GrabSprite and PutSprite to convert tiles to sprites and back.

    --Eric