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
    I'm pretty sure; someone else had the same problem and that fixed it. Give it a try and see if it works.

    It's not built-in yet, but it actually shouldn't be too hard to implement yourself right now with the current functions. You could move the player back once he gets to a certain point, and then use the various SetTile functions to draw the appropriate tiles so it looks like he didn't move, and then continue from there. Thanks for considering!

    --Eric
     
  2. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    I would love to but the Asset Store only has version 2.0 at the moment. It seems to have been that way for awhile. I guess the Unity staff are taking a break for Easter or something.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    2.0 is the most recent released version. The modification I mentioned is part of 2.1, but you can use the source code right now to do the same thing; it only takes a moment.

    --Eric
     
  4. TheLordDave

    TheLordDave

    Joined:
    Mar 2, 2014
    Posts:
    28
    If i wanted to detect clicks on the entire map how would i do that?

    I have an onmousedown function on my objects with 2d colliders, which reports the click correctly. if i then needed to identify a click that was not on any other object but just on the tilemap how would i do it?

    if I use the Tile.ScreenToMapPosition (Input.mousePosition, mapPos)) function, it will report that the click is on the map even if the object is handling the click.

    Do the tilelayers have a global collider or something that i could use?

    cheers
    dave
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could have a global variable that's normally false (let's call it "objectClicked"), which your objects would set to true if they are clicked on. Then you can check the global variable when checking ScreenToMapPosition:

    Code (csharp):
    1. if (!objectClicked  Tile.ScreenToMapPosition (Input.mousePosition, mapPos)) {
    2.     // only map was clicked
    3. }
    --Eric
     
  6. TheLordDave

    TheLordDave

    Joined:
    Mar 2, 2014
    Posts:
    28
    The problem with that is I cant guarentee what order the scripts run in. IF the check script runs before the click object script it wont catch the correct click.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you restructure your code a bit so that you can guarantee the order? For example, if you're using OnMouseDown to check for object clicks, then putting the ScreenToMapPosition check in LateUpdate will cause it to always run last.

    --Eric
     
  8. TheLordDave

    TheLordDave

    Joined:
    Mar 2, 2014
    Posts:
    28
    That did the trick. Cheers :)
     
  9. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    The asset store only seems to have the DLLs. How should I go about getting the source code?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The asset store version includes the source code; look in the SpriteTile folder.

    --Eric
     
  11. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    Ok, I've got the source files, but now I'm getting conflicts because Spritetile structs are getting defined twice (presumably once in the DLL and once in the source files). I tried deleting the DLLs, but then I get errors because of missing files.
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, if you're using the source, you need to remove the DLLs. After that, you would need to replace the TileManager script on the SpriteTile/Resources/TileManager object with the source script rather than the DLL. None of the data is lost so it's not a problem to do that.

    --Eric
     
  13. PortableCow

    PortableCow

    Joined:
    Dec 31, 2013
    Posts:
    8
    Does anybody know of a good pathfinding asset that would work with SpriteTile. I'm using a procedurally generated level and would like the enemy sprites to be able to locate the player. I'm currently trying to integrate this A* pathfinding solution: http://blog.nobel-joergensen.com/2011/02/26/a-path-finding-algorithm-in-unity/ into my game but I'm not sure if I'm properly using it with SpriteTile. It appears that most of the stuff on the store is geared towards 3D pathfinding. Any suggestions would be much appreciated.

    Thanks,
    Matt
     
  14. pstudio

    pstudio

    Joined:
    Apr 20, 2014
    Posts:
    12
    Hi Eric,

    I recently bought SpriteTile and have only really had the chance to play a bit around with it now. Right now I'm just using it to display a map while I'm prototyping a map generator. Generally SpriteTile is working fine but I have noticed some graphical artifacts showing in my rather simple tile map.

    As can be seen on the screen shots there are some artifacts displaying at the edge of some tiles. By moving the camera slightly the artifacts will be displayed at different positions or may be removed altogether.
    $tile_glitch01.png
    $tile_glitch02.png
    $tile_glitch03.png

    Right now I'm not to concerned about this issue since I'm just playing around with stuff, but obviously this is not a desirable result when I move on to actual production. Is there some settings I should be aware of that is causing this and what can I do to prevent this from happening?

    Thanks,
    Peter
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There are some different solutions...1) using a material with pixel snap on seems to help, 2) changing the tile size so that tiles overlap slightly, 3) waiting for version 2.1, which has a function for changing the scale of sprites, which can be used to fix the problem in a similar way as solution #2 (increasing the sprite scale slightly above 1.0 so they overlap a tiny bit) but without having to change the tile size.

    As for pathfinding, I'm planning on some kind of built-in pathfinding at some point. In the meantime you could use the GetCollider function to build a grid of collider cells, and use that for various kinds of pathfinding.

    --Eric
     
  16. pstudio

    pstudio

    Joined:
    Apr 20, 2014
    Posts:
    12
    Thanks, using pixel snap works fine for now at least.

    Btw. I just wanna say that my experience so far with SpriteTile is excellent. As someone that is mostly interested in using the tool through code it's a pleasure how easy and simple it is to have something running in the matter of a few minutes. Just what I was looking for. :)
     
  17. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    Thanks for you help with this Eric. I have replaced the references to dlls with references to the sources scripts and made the recommended change to the SceneManager file. I no longer get any error messages, but now the sprites won't activate properly. The ones that are in the view of the camera when the scene loads are fine, but when the camera moves no new tiles become visible. Except for the starting corner of the map, the entire level is invisible.
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You may have to call SetCamera again after loading a new scene.

    --Eric
     
  19. PortableCow

    PortableCow

    Joined:
    Dec 31, 2013
    Posts:
    8
    I was able to get basic A* pathfinding implemented, and so far it appears to be working.
     
  20. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    I always was. I called SetCamera in the start function of my level loading script (that is, a script placed on an empty object in the new scene that tells Unity to load the appropriate SpriteTile level), just before I called LoadLevel. Somehow SpriteTile would lose the reference to the camera after that point.

    Anyhow, I have bypassed the problem by making the camera persist between levels (which is something I probably should be doing anyway), but you might want to look into it for the sake of future users.
     
  21. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're right; I've fixed SetCamera in 2.1 so it works correctly with non-persistent cameras.

    --Eric
     
  22. Daniel_M.

    Daniel_M.

    Joined:
    Apr 28, 2014
    Posts:
    4
    Hi Eric,

    First of all, your work looks amazing and that's what I think I've been looking for.

    I want to do a top-down RPG in a Zelda-like style, does your tile system also provide BoxColliders for a group of tiles ? (For example, a large wall composed by 10 tiles)

    I've seen that you specified the following, but I did not exactly understand what you mean by this :
    Thanks in advance for your answer, I'm really interested by using SpriteTile ;)
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Thank you for your interest! You can use physics colliders like that, although for a Zelda-like game you'd probably be better off using the GetCollider method. This demo shows it in action. The character controller code is here; you can see where it queries a tile to see if it's a "collider" or not, and if so, then it prevents the player from moving there.

    --Eric
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    In other news, SpriteTile 2.1 is nearly done. Changelog:

    Additions:
    • Tile.AnimateTile function, for animating a specified kind of tile with a given frame sequence.
    • Tile.StopAnimatingTile function, for stopping the animation for the specified kind of tile.
    • Tile.AnimateTileRange function, for animating a range of tiles. Useful for things like water tile animations, flickering torch animations, etc., where you don't necessarily want all the tiles to animate in sync.
    • Tile.StopAnimatingTileRange function, for stopping a range of tile animations at once.
    • Tile.GetMapBlock function, for getting a section of a map that contains all tile data (tile, order, rotation, etc.).
    • Tile.SetMapBlock function, for putting that section somewhere in a map. So with GetMapBlock and SetMapBlock you can easily copy/paste parts of the map with code, either in the same layer or between different layers.
    • Tile.SetLayerColor function, for tinting all the tiles on the specified layer with a color.
    • Tile.SetColliderLayer function, for setting the GameObject layer of colliders. (Not related to SpriteTile layers.)
    • Tile.SetTileScale and Tile.SetTileLayerScale functions, for setting the scale of sprites. This can be used for special effects or, if you're having issues with occasional gaps between tiles, fixing that problem by using a scale slightly greater than 1.0.

    Fixes:
    • Loading a new scene (as in Unity scene, not SpriteTile level) is handled properly.
    • Tile.SetCamera works correctly when called with different cameras, subsequent to the first call.
    • Tile.GetMapPosition and Tile.GetWorldPosition return correct coordinates if Tile.SetLayerPosition has been used.

    TileEditor Additions:
    • A new group type, "Random", where you can add a list of tiles to a group, and when drawing with that group, the actual tile is randomly selected from the list. Useful for quickly adding variety when you have a number of similar tiles (grass, dirt, water, etc.). Also works when filling a selection box, so every tile in the selection is randomly chosen.
    • Multi-select for the Tiles section, where shift-clicking another tile will select the range of tiles, so changing the default collider/order-in-layer/rotation/etc. will be applied to all the selected tiles in the range. Also good for adding multiple tiles to Random groups with one click.
    • Up and down buttons for layers, which can be used to rearrange layers easily by moving them up or down in the list.
    • A "Sync ScrollView Position" toggle, which keeps the same scrollview position and preview size in the Level view, when switching between layers that have the same dimensions. Otherwise, all layers remember their own scrollview positions and preview size.

    TileEditor Changes:
    • The "Editor Preview" button is replaced by two buttons, "This Layer" and "All Layers", for making the preview show the respective layers.
    • The tile "Name" and "Number" toggle states are saved in the editor preferences, along with the currently selected tileset and the grid toggle.
    • Changing layers can also be done from the keyboard, using alt+up arrow and alt+down arrow.

    TileEditor Fixes:
    • When using the "Replace" button, the TileManager is updated correctly.
    • If the TileEditor window is kept open during play mode, it will be usable again when play mode is stopped, without having to close and re-open it.
    • Changing the default order-in-layer for a tile in the Tiles section and then drawing the tile will always work correctly. Groups with various order-in-layer values are also always drawn correctly.
    • After creating a group, the mouse wheel continues to work for the Tiles section.
    • When clicking "Refresh" with the tile numbers displayed, the tile numbers remain correct.

    The updated editor:



    --Eric
     
  25. Daniel_M.

    Daniel_M.

    Joined:
    Apr 28, 2014
    Posts:
    4
    Hi Eric,

    Thank you for your answer and also for your example ! That's exactly what I was looking for finally !

    Your example seems really "smooth" and not bugged. For my personal experience, when I tried to add Sprites for the walls and a Sprite for my player (both RigidBodies2D with a BoxCollider) the player sometimes was blocked when going along the wall.

    I think this is because for a wall of 4x1, I had 4 BoxColliders which were not perfectly aligned, but all of this are suppositions.

    I've bought and downloaded SpriteTile, since you do not have the same problem. Can I (we) ask questions about it on this thread once used to it ?

    Many thanks, and great job !
     
  26. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, I think physics colliders add unnecessary complexity if all you want is tile-based movement where tiles are either passable or not.

    Of course. Thank you!

    --Eric
     
  27. Daniel_M.

    Daniel_M.

    Joined:
    Apr 28, 2014
    Posts:
    4
    Hi again,

    So .. I was playing with your asset for a while now, designing levels and stuff, but something is bugging me.

    (For your information, I'm a newbie Unity user, I began 2 days ago)

    I've seen there is a function to load the level (Tile.LoadLevel(myLevel)) but I'm not sure about some things :

    1. myLevel : It is the "name" of the world I created in your editor ? Like "myFirstMap.bytes" ?
    2. Where do you load the level ? I mean, there's a script created with the necessary functions as detailed in your documentation, but I don't figure out where do you use / attach this script. Is there, like in Java, a "main" function which is launched at the run or something ?

    Sorry for the "spam", but I have a great idea for a top view rpg and I really really really hope your asset will help me in my task :D

    Have a nice day !
     
    Last edited: Apr 29, 2014
  28. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hello, this looks very interesting. I already own 2DToolkit, but am curious how this compares so I just may buy it. I have question regarding sprite sheets. Is it possible to just import a sprite sheet from a PSD file and use that as a base?
     
  29. hugosslade

    hugosslade

    Joined:
    Mar 24, 2013
    Posts:
    10
    Hi Eric,

    I just got SpriteTile and am having the same issue as Kytin. I've done the same changes except for having a persistent camera. Is there another way around it?

    I have to say so far SpriteTile is awesome, just like Vectrosity which I always use!

    Thanks
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can import a sprite sheet as a PSD, use the sprite editor in Unity to slice it, and it will work fine with SpriteTile.

    Version 2.1 with the fix will be done very soon.

    Thank you!

    --Eric
     
  31. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    I having a slight problem with the physics colliders for the levels occasionally. It's not a problem with spriteTile per-se. It's more of a combination problem of how unity handles 2D collision and the fact that I am using rather small tiles.

    The problem is that sometimes objects (particularly the player) will hit the ground in such a way that they become stuck in it. I paused the game and had a look, and it seems like it can even be stuck inside one of the polygon colliders formed by combining a group of tiles. I have not yet looked at how you generate these collider 'chunks' but if they have any internal edges, that could explain what I am seeing. My request would then be for a different way to calculate the colliders that does not leave any internal edges to the 'chunks'.

    I understand if you think that this would be rather more work than is justified to deal with an edge case that (so far) only seems to affect one person. If that is the case, then I will have to find a way to generate the kind of result I want, because this bug could really ruin the game for a number of people if I don't deal with it.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Can you try manually creating a collider without internal edges, to see if it makes any difference? Also it sounds like you might want to use continuous collision detection.

    --Eric
     
  33. Nodens

    Nodens

    Joined:
    Mar 27, 2014
    Posts:
    3
    Hello, the changelog looks really nice, with that kind of support i'm glad I bought SpriteTile :)

    BTW, I still hope to show multiple layers in directly the TileEditor and not only in the UnityEditor ;)

    Thanks for your work.
     
  34. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sorry, didn't mean to ignore you Daniel_M!

    It's not the name, but a reference to the file.

    See some of the included demo scenes for examples of loading levels, such as LevelViewer and TriggerDemo. I frequently attach the primary script to the main camera.

    --Eric
     
  35. Daniel_M.

    Daniel_M.

    Joined:
    Apr 28, 2014
    Posts:
    4
    No problem Eric, I've seen that your asset has some success, I understand the fact you can't answer everybody at the same time ;)

    Thank you for your answer, so :

    The variable itself is a reference ? I mean, the simple fact I named the TextAsset "myMap" will reference the map created ?

    Ah ! I didn't see there were some examples ! I will take a look, but I understand now how this script is supposed to work.

    Many thanks, I will see directly those examples, and from there I think I will be able to create some nice maps. Congrats for your asset!
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually the names aren't particularly relevant. In order to make references you hook up public variables to the desired asset in the inspector...sounds like it might be a good idea to do a few Unity tutorials so you can get a sense of how things work in general.

    --Eric
     
  37. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    By the way, SpriteTile 2.1 is out now! If you bought from my site you should be getting a notification. I'll be uploading to the asset store next.

    --Eric
     
  38. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    I've switched the player character to use continuous collision. The penetration issue was something that only cropped up very occasionally so I won't know for sure if that has solved the problem until I have done a lot of testing. Hopefully it worked.


    Moving on. I have started to look at the overlapping tiles feature and begun thinking about how I could make use of it. Unfortunately it's utility is limited for me without some way to modify the position of the tile image as well as rotation.

    For example, suppose I wanted to use the overlapping feature to place a tree. Unless I make the image with a lot of transparent space below the tree, the tile will be placed with the image of the tree centred on the tile it was placed into, instead of placing it such that the base of the tree is centred on the tile.

    I suppose this is another feature request. If there was the ability to give tiles an offset to their position it would greatly improve SpriteTile's versatility.
     
  39. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can modify the position of the tile by changing the pivot point of the sprite; I used that for some of the tiles in set 0 of the demo tiles (such as the gate).

    --Eric
     
  40. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    Unfortunately, that doesn't work as well when I'm getting my sprites from combined spritesheets. If the sheet is divided into a grid, the pivot point has to be the same for every tile, and can only be one of the default positions.


    EDIT: On another note, is it possible to add a new layer to a level at runtime?
    EDIT2: Nevermind. I found the script reference that says that it isn't possible.
     
    Last edited: May 2, 2014
  41. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, you can edit the pivot point of each sprite in the sprite editor individually, and every one can be customized individually as well, not limited to the defaults.

    Yet. ;)

    --Eric
     
  42. Peluin

    Peluin

    Joined:
    Apr 27, 2014
    Posts:
    1
    Does SpriteTile have "edging", so that I don't have to draw all the little road-meets-grass tiles manually?
    I tried creatively using the "Groups" functionality to get what I want but couldn't find a way.
     
  43. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Not yet, but it's on the to-do list.

    --Eric
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Version 2.1 is available now on the asset store!

    --Eric
     
  45. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22

    You're right. I found it. Seems like I can't see the forest for the trees sometimes.
     
  46. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    Hopefully I'm missing something again, but it seems like there isn't a straightforward way to add additional sprites from a spritesheet (at least, not without creating duplicate tiles).
    What is happening is that I have a spritesheet of terrain tiles and when I add new tiles I tend to just expand the spritesheet to have another row of sprites at the bottom. Refreshing the set that contains the sprite I added earlier in the Tile Editor doesn't add the new sprites. Sprites must be loaded as a single set, so if I load the image again I get a bunch of duplicates of the tiles that I loaded earlier as well. I can't delete the duplicates from the set, only delete the entire set.

    ...Wait, apparently I can delete individual tiles. It's just the control for this is hidden until I press the Move button. That's... an odd place to put it.


    Also, I think I hit a bug. If you move tiles around and then select some of them to add to a group, the tiles added are the ones that were originally in the places selected, not the ones that have been moved there.
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I moved the delete button there in a recent version, since it can potentially be kind of destructive and there isn't really a good way to undo it that I can figure. However, I just realized that it wouldn't be possible to multi-select a bunch of tiles and delete them all at once; you'd have to do it one at a time, which is obviously a bit tedious. Hmm.

    As for the bug, you're right. Sorry about that. I've fixed that for the next version, but in the meantime you can fix it right now by using the source code, and changing these lines in the AddTileToRandomGroup function:

    Code (csharp):
    1.                 if (!thisRandomGroupSet[selectedGroup].Contains (TileInfo(currentSet, i)) ) {
    2.                     thisRandomGroupSet[selectedGroup].Add (TileInfo(currentSet, i));
    3.                 }
    to this:

    Code (csharp):
    1.                 var tileInfo = new TileInfo(currentSet, GetTileNumber (TileInfo(currentSet, i)));
    2.                 if (!thisRandomGroupSet[selectedGroup].Contains (tileInfo)) {
    3.                     thisRandomGroupSet[selectedGroup].Add (tileInfo);
    4.                 }
    Also the RemoveTileFromRandomGroup function should be changed similarly:

    Code (csharp):
    1.             var tileInfo = new TileInfo(currentSet, GetTileNumber (TileInfo(currentSet, i)));
    2.             if (thisRandomGroupSet[selectedGroup].Contains (tileInfo)) {
    3.                 thisRandomGroupSet[selectedGroup].Remove (tileInfo);
    4.             }
    --Eric
     
  48. Kytin

    Kytin

    Joined:
    Dec 4, 2013
    Posts:
    22
    Thanks for the fix.
    I think encountered another bug in a related area. If you have moved your tiles around, then use them to create a level it works that far. However, if you load the level at runtime, make some changes to it, and then save the level the moved tiles will be mixed up.
     
  49. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Clearly my belief that I'd accounted for all cases of moved tiles was somewhat mistaken.... That fix is a little more involved, so if you send me your email address via PM I'll send you an updated Tile.cs file (which goes for anyone else who's run into that problem).

    --Eric
     
  50. hugosslade

    hugosslade

    Joined:
    Mar 24, 2013
    Posts:
    10
    Hi Eric,

    Is there future plans for multi-camera support? I'm adding split screen to my game and I want to keep using SpriteTile.

    The only 'solution' I can think of is to have the camera between both players so that it can see both. But that could be a lot of tiles loaded and unseen.

    Also, are you able to add custom polygon shaders to tiles? From my tests it's either full tile or Unity's auto one which isn't 100%.

    Thanks