Search Unity

SpriteTile, a fast dynamic tile system (RELEASED)

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

  1. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    So that limitation is for scene and not for the entire game, right?

    Thanks for you time, btw :)
     
  2. sanpats

    sanpats

    Joined:
    Aug 24, 2011
    Posts:
    343
    I can't think of any game that use more than 32K 2D tiles, even big tile-based RPGs. 32K is pretty massive already IMHO. If you need more than 32K tiles, I think it's better to use a different implementation.
     
  3. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    It's amazing if they use more than 256 different tiles per map tileset. You're repeating a lot of tiles most of the time, so 32k isn't really a limit as such :)
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's for the project; all tile data is stored in the TileManager asset. You'll note that the TileEditor is the same regardless of what scene you have open, or if you have any scene loaded at all, which is the expected behavior (you wouldn't want to re-do all your tilesets just because you changed scenes). But even something like Terraria, which has an insane number of tiles, doesn't come that close to 32K.

    --Eric
     
  5. beit

    beit

    Joined:
    Mar 5, 2015
    Posts:
    24
    Hey Eric, any plan to add isometric import support for tiled tmx maps?
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unlikely, since I'd have to add isometric support to SpriteTile in general, which isn't really what it's built for.

    --Eric
     
  7. beit

    beit

    Joined:
    Mar 5, 2015
    Posts:
    24
    Hey Eric in a post here you mention about isometric tiles, now I've seen why I got confused, can you point me out to more info about how to make the isometric system you talk about work with SpriteTile.
    Isometric tiles in the end are not much different then orthogonal, I think it would be really interesting to have support for the different types(hex, iso, ort), do you see this happen in a near future? Do you see a high implementation cost for this?
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    A confusion of terminology; if you mean diamond-shaped tiles, then no, that's not likely to happen.

    --Eric
     
  9. V1k1ng

    V1k1ng

    Joined:
    Sep 30, 2015
    Posts:
    4
    Hey Eric,

    I'm pretty new to Unity so I'm probably missing something obvious, but how do I get my level into my scene? I couldn't find it in documentation.
    So I created a level in the editor and saved it in the asset folder in my project. But how do I actually add that to the scene so the level pops up there?

    Thanks
     
  10. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The "coding basics" section in the regular docs explains it, in the section called "loading a level". I would also recommend looking at the demos so you can see how things work in context.

    --Eric
     
    blizzy likes this.
  12. bitbiome_llc

    bitbiome_llc

    Joined:
    Aug 3, 2015
    Posts:
    58
    Hello,

    I have a question related to UI overlay interaction on Android devices. Is there a way to use EventSystem interfaces with tiles?

    I have a manager object that captures all clicks and touches. It will take the position vec and check to see if there was a tile at that location. This works great. I use EventSystem.current.IsPointerOverGameObject to determine if the pointer is over a canvas UI element. This works for the mouse but fails on my test Android device (Nexus 7). It still fails when specifying the specific fingerID when checking TouchPhase.Ended.

    As a work around, suggested by Fattie, I check if there is a selected EventSystem object, EventSystem.current.currentSelectedGameObject. This works but is not ideal.

    Is the only way to interact with the tile map through a vector position? Is there any way to implement EventSystem interfaces to specific sprite objects added to a scene? (too heavy? issues with caching?)

    I know this is not specifically a SpriteTile issue and only relates due to how one interacts with SpriteTile.

    Touch UI pass through topic
    http://answers.unity3d.com/questions/784617/how-do-i-block-touch-events-from-propagating-throu.html
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Tiles aren't GameObjects, so they can't use scripts and so on. Instead you can use Tile.ScreenToMapPosition with Input.mousePosition (or any other screen position).

    --Eric
     
  14. bitbiome_llc

    bitbiome_llc

    Joined:
    Aug 3, 2015
    Posts:
    58
    Yeah I know. I was thinking more along the lines of adding the script to the generated sprites that are added to the scene.
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not possible since tiles aren't GameObjects. There's a pool of sprites created for the tiles, but they don't "belong" to any particular tile and are recycled as needed. That's why you can have a level with 5 million tiles and it performs the same as a level with 5,000 tiles.

    --Eric
     
  16. bitbiome_llc

    bitbiome_llc

    Joined:
    Aug 3, 2015
    Posts:
    58
    Yeah, I figured something like that would be the case. Thanks. Love SpriteTile btw, great performance on PC and Mobile platforms.
     
  17. V1k1ng

    V1k1ng

    Joined:
    Sep 30, 2015
    Posts:
    4
    Thanks a lot for the fast reply, I'll give it a go today! :)
     
  18. V1k1ng

    V1k1ng

    Joined:
    Sep 30, 2015
    Posts:
    4
    Hey guys,

    My level is loading fine now, but for some reason when it runs all the tiles have no sprites assigned to them, do you know the issue here?
    In the TileManager everything looks fine and all elements have sprites plus I didn't move them anywhere in the project, which I saw you warned against in the documentation.

    Also is it possible to view the level in the scene somehow? Or is it only possible to view it during runtime? Since I would like to add behavior to some elements (like moving a platform on the x-axis) during gameplay, it would be great to be able to see it in the scene.

    Thanks!
     
  19. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    There's a preview button in the upper left.
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The docs say it's fine to move sprites around in the project. The only thing they say not to move is the TileManager object. I would assume your camera isn't positioned where it can see any tiles.

    --Eric
     
  21. V1k1ng

    V1k1ng

    Joined:
    Sep 30, 2015
    Posts:
    4
    At first I thought it was the camera position too, but it's not the case. If I run the game I can see that all the tiles are there, but they have no sprites assigned to them, so they're invisible to the camera. However, if I manually assign a sprite to the tile it will show up on the camera.
    In the SpriteTile tool all the sprites are there and looking fine when I make my level in the grid, but for some reason when I load level at runtime the tiles have no sprites assigned to them.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm pretty sure it's because of the camera position. The tiles are always all there, because that's how SpriteTile works—it creates a pool of sprites that fills the screen, so they exist whether the camera can see any tiles or not. Make sure the camera is moved back (e.g., not 0 on the z position). Use the preview to position the camera where you can see the tiles in the game view.

    --Eric
     
  23. BigED

    BigED

    Joined:
    Jul 25, 2013
    Posts:
    16
    Eric5h5, I have two question:

    1. Why when I use scene preview and go into play mode TileEditor reset my level. It is very bad for debuging, because I must to load level from .bytes file again and again.
    2. Can I always show my level in scene view if I have a small level? Without it is very difficult to put gameobjects on level.
     
    Last edited: Oct 3, 2015
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Save your level before going into play mode (just hit Alt-S), and check "Auto" next to the Open button. SpriteTile works by creating a pool of sprites that fills the screen, which are recycled as needed, so large levels are efficient; this can't be changed for small levels.

    --Eric
     
  25. bwheatley

    bwheatley

    Joined:
    Jun 23, 2012
    Posts:
    45
    So what I have is a 300 by 300 hex sprite map (each tile 1by1). I'm trying to break that map down into individual regions so i'm using your other product vectrosity to draw a square every N number of hexes. For this demo i'm doing 15 by 15 and drawing a box.

    I'm trying to get the worldcoordinates for the int2 locations of the sprites so I can draw the squares properly in world space. I'm using MapToWorldPosition but it does not appear to give me worldcoordinates. It's drawing all the squares in the bottom left of the screen and not properly where the regions should be demarcated.

    The pdf for maptoworldposition says - Returns the world position in units that corresponds to the specified cell. But looking at the source that does not appear to be the case.

    Sorry if I sound like a tard, this is one thing i keep stumbling over and i'm assuming it's a simple thing i'm overlooking.
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    MapToWorldPosition definitely does exactly that. What about the source makes you think it doesn't? It multiplies the tile position by the layer tile size (and adds any layer offset that might exist), which results in the world position. I'm not sure what you mean by hexes, since SpriteTile doesn't support that.

    --Eric
     
  27. bwheatley

    bwheatley

    Joined:
    Jun 23, 2012
    Posts:
    45
    Ah I'm thinking worldposition is World Coords and it appears that is not the case. When i say hexes i mean squares :).
     
  28. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Hexes are six-sided. ;) World position is in fact world coordinates; that's the same thing.

    --Eric
     
  29. bwheatley

    bwheatley

    Joined:
    Jun 23, 2012
    Posts:
    45
    yea i know hexes are 6 sided it goes back to my roots of wargaming. And when i say world position i mean real world coordinates like Input.mouseposition not the vector2/int2 representation of the grid.
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Input.mousePosition is not world coordinates at all, it's screen coordinates.

    --Eric
     
  31. BreadWeek

    BreadWeek

    Joined:
    Aug 12, 2014
    Posts:
    45
    I'm having issues with the GrabSprite function. I have 4 SpriteTile layers, but specifying any layer besides 0 results in the error:

    "Invalid layer id. Please use the unique id of the layer (which is not the same as its index in the list)."

    I'm unsure of what that means. Specifying a layer in any other SpriteTile function works correctly.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unity changed the way layers are handled at one point, and it looks like I neglected to update the GrabSprite function. It's fixed for the next version, but in the meantime you can fix it with the source: in line 3150 of the Tile.cs file, replace

    Code (csharp):
    1.         sprRenderer.sortingLayerID = layer;
    with

    Code (csharp):
    1.         sprRenderer.sortingLayerName = sortingLayerNames[sortingLayerIndices[layer]];
    --Eric
     
  33. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    Am I the only one who can get up in the morning and code that worked the night before now doesn't?

    I'm getting this error in my CharacterController script:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. SpriteTile.Tile.WorldToMapPosition (Vector2 p, Int32 layer)
    3. CharacterController.SetMapPosition () (at Assets/Scripts/CharacterController.cs:59)
    4. CharacterController.Start () (at Assets/Scripts/CharacterController.cs:51)
    5.  
    The line of code that's throwing the error is this:

    Code (CSharp):
    1. mapPos = Tile.WorldToMapPosition (transform.position, layer);
    I'm not sure where to start looking for the answer -- any tips? Thanks.

    Jay

    PS - The CharacterController script is not the one that comes with SpriteTile, but it's based off that code.
     
    Last edited: Oct 9, 2015
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would guess you're trying to use transform.position on an object that's been destroyed?

    --Eric
     
  35. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    That script is attached to a game object called Hero and it's still showing in the Hierarchy after the error is thrown -- I'm relatively new to Unity, but that should mean the game object hasn't been destroyed, yes? Also, right before that line of code I can print out the .x and .y of the transform.position and get actual values.

    Jay
     
  36. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    Just for the fun of it I hard-coded values into that line and get the same error.

    Code (CSharp):
    1. mapPos = Tile.WorldToMapPosition(new Vector2(-2.095f, 0f), 0);
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The only way that could happen is if you didn't have any level loaded, so SpriteTile wasn't set up at all.

    --Eric
     
  38. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    The level shows up even after the error happens -- but could my CharacterController be loaded/run before the SpriteTile stuff? If that's a possibility, is there some way I can make sure SpriteTile comes first?

    Thanks.

    Jay
     
  39. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    I found where you can change the script execution order and set my character controller to load later than normal and the error has gone away.

    Jay
     
  40. bwheatley

    bwheatley

    Joined:
    Jun 23, 2012
    Posts:
    45
    LOL Forget I even asked for help. I'm going to forget I asked you for help because it would hinder my desire to buy your products going forwards. Being pedantic is very poor support. Have a good one.
     
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm sorry you're upset, but I'm not sure I can see why. You asked about MapToWorldPosition not returning correct coordinates, but in fact it does work correctly. You're apparently confused about the coordinates returned by Input.mousePosition, which are screen coordinates, not world coordinates, which is why you can't use them with MapToWorldPosition. I'm not sure how this is "poor support"? It should answer your question. Or, are you not aware of the difference between screen and world coordinates? It's an important distinction, since those are two different and incompatible things, not me being pedantic. If you need further elaboration, please ask.

    --Eric
     
    SoftwareGeezers likes this.
  42. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Uhh, what?? I think it is very good support if they point out mistakes I'm making etc.
     
    orb likes this.
  43. AndyGFX

    AndyGFX

    Joined:
    Jan 13, 2012
    Posts:
    98
    Hi,

    today I started working with SpriteTile asset and because I have to create procedural world I tried start with ground and from script only without build-in editor.

    Here is code which works in second option only, but in doc is function for create level via NewLevel from LayerData array, maybe I have something wrong, but doesn't work for me. :(

    Code (CSharp):
    1.     private void Start()
    2.     {
    3.         this.mapSize = new Int2(mapWidth, mapHeight);
    4.         TileInfo layer0Info = new TileInfo(0, 8);
    5.         TileInfo layer1Info = new TileInfo(0, 0);
    6.  
    7.         this.layers = new LevelData[2];
    8.         this.layers[0] = new LevelData(mapSize, 2, Vector2.one, 0f, LayerLock.None);
    9.         this.layers[1] = new LevelData(mapSize, 2, Vector2.one, 0f, LayerLock.None);
    10.  
    11.         Tile.SetCamera();
    12.  
    13.         // (1) ERROR
    14.         Tile.NewLevel(this.layers);   // < ----- LOG: ArgumentOutOfRangeException: Argument is out of range. Parameter name: index
    15.  
    16.         // (2) WORKS correct
    17.         /*
    18.         Tile.NewLevel(mapSize, 2, Vector2.one, 0f, LayerLock.None);
    19.         Tile.AddLayer(this.layers[1]);
    20.         */
    21.  
    22.         Tile.SetTileBlock(Int2.zero, mapSize - Int2.one, 0, 0, 8);
    23.         Tile.SetTile(Int2.one, 1, 0, 0);
    24.     }
    Note: I have added SortingLayers in to unity editor (L-Background/L-Middle/L-Front) and fixed with Assets/Set SpriteTile Sorting Layer Names.

    Best Regards,
    AndyGFX.
     
    Last edited: Oct 12, 2015
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Your code is fine; that's a SpriteTile bug, sorry about that. I've fixed it for the next version. Let me know via PM if you want an updated Tile.cs script in the meantime.

    --Eric
     
  45. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hi bwheatly,

    I think you misunderstood Eric5h5's response. I have asked for support a couple of times and he has helped straightaway. If you look at all his products you'll see they are constantly updated. If you look into his code you'll also see he knows what he's doing so any advice is worth listening too.

    thanks
     
  46. AndyGFX

    AndyGFX

    Joined:
    Jan 13, 2012
    Posts:
    98
    Hi,

    I have a classic issue with tiles and I can't find solution for correct rendering. (Sorry, I found solution, but don't make me sense, why so)

    1) Tiles are separated image and to ST are loaded from folder. Scene is created manualy via script and result is OK.



    2) Tiles are as single tileset and to ST are loaded from as sprite sheet. Scene is created manualy via script and result is WRONG with gaps.



    1) Is this problem Unity only or I have something wrong with map painting?
    2) Is possible create tiles from code as single mesh or convert to single mesh, similar to created map in editor?

    Note: Technicaly i need change during gameplay some tile or destroy him.


    Andy.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd need padding between tiles when using a spritesheet. SpriteTile only uses sprites, not meshes. It wouldn't have any effect on the issue anyway.

    --Eric
     
  48. AndyGFX

    AndyGFX

    Joined:
    Jan 13, 2012
    Posts:
    98
    Thanks,
    now I understand.

    A.
     
  49. JayJennings

    JayJennings

    Joined:
    Jun 24, 2013
    Posts:
    184
    Any news on this front? (hope hope) I'm going to need pathfinding at some point in the next few weeks and if I don't have to write it from scratch, I'd be very happy. :)

    If your internal version isn't close, do you (or anybody) have tips on an existing asset that could be shoehorned into place with minimum frustration?

    Jay
     
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, I haven't done anything with that yet, so it won't be within the next few weeks.

    --Eric