Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

SpriteTile, a fast dynamic tile system (RELEASED)

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

  1. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    Thanks, this works great now.

    I notice a different issue with the camera rotation now in the procedural demo. ScreenToMapPosition does not seem to work correctly for mouse clicks. It looks like it assumes that the mouse click x/y coordinates correspond to clicking on the level when it is flat, not rotated. Is there a way to fix this?

    Is there some way to convert the mouse coordinates to camera coordinates, then pass that to ScreenTo<MapPosition?
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    There's always some way. :) Unfortunately nothing simple is coming to mind at the moment; I'll keep thinking about it.

    --Eric
     
  3. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    Can this be done using a raycast on the SpriteTile surface by adding a mesh filter and collider? And then pass the raycast hitpoint to ScreenToMapPosition.

    I am just not sure where to make the changes in the SpriteTile source code.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    No, since sprites are recycled so you wouldn't have colliders that are assigned to any specific tile. But raycasting is a good idea; I'd use Plane.Raycast, then you can use WorldToMapPosition.

    --Eric
     
  5. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    That worked, excellent. Thanks!
     
  6. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    I am using a perspective camera since the camera is rotated. Do you have any advice on how to keep the camera's viewport within the bounds of the level, as not to reveal the background?
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    I would say get the camera bounds as usual, then inset them by whatever number of tiles you added with the AddBorder number.

    --Eric
     
  8. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    Thanks, how would one go about getting the width of tiles and insetting the camera?

    I was also thinking of calculating the number of tiles that can fit in the current viewport, and limiting movement based on the number of tiles the player is from the edge of the level.
     
  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    You can use GetTileSize. So the bounds would be numberOfTiles * GetTileSize.

    --Eric
     
  10. danielhamel

    danielhamel

    Joined:
    Apr 1, 2019
    Posts:
    3
    Can we serialize the level data? I can serialize most of my other level variables in the same file, but don't know if it will work for a custom level?
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    The level data is stored in binary files.

    --Eric
     
  12. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    Tile.GetSize() returns (1.0, 1.0). Is there a way to get tile width in world coordinates or pixels?
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    That is the size in world units. (1.0, 1.0) means it's 1.0 units wide by 1.0 units tall.

    --Eric
     
  14. danielhamel

    danielhamel

    Joined:
    Apr 1, 2019
    Posts:
    3
    Would it be possible to have a "wall" group type like the terrain group?
     
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Not quite sure what you mean, but you could use terrain groups to make walls if you like.

    --Eric
     
  16. codesushi

    codesushi

    Joined:
    Sep 27, 2014
    Posts:
    22
    I see, then the issue is the tiles will be different sizes because of the level rotation and the use of a perspective camera. And the tile sizes will change relative to the camera position.

    Tough problem given the perspective camera. Will need to figure this out with some fancy 3d math most likely. Thanks though.
     
  17. danielhamel

    danielhamel

    Joined:
    Apr 1, 2019
    Posts:
    3
    Ah, ok, will continue to do it myself.
     
  18. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    296
    Hiya. I've noticed that a cell without a tile (e.g. prefab) doesn't have the trigger value copied over to the new cell when it's cut/copied in the level editor. The properties do get copied over correctly though. Works fine when copying a cell with a tile.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Yep, I see what the issue is. You can fix this in the source, where in MapData.cs, change line 270 from

    Code (csharp):
    1.                 if (skipEmpties && map[sIntPos] < 0) {
    to

    Code (csharp):
    1.                 if (skipEmpties && map[sIntPos] < 0 && !HasProperty (p)) {
    --Eric
     
  20. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    296
    Thanks for the quick response and fix.
     
  21. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    296
    I haven't applied the fix above yet, but I've just spotted another minor issue in the Level Editor window.

    When the Extra and Trigger overlays are both selected, cells without tiles (e.g. prefabs) don't have their Trigger value displayed. The Trigger value for them is displayed if only the Trigger overlay is selected (Extra overlay is unselected). Cells with tiles do correctly display their Trigger value with Trigger and Extra overlays both selected.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Hmm, I'm not seeing that (regardless of the fix above):

    Screen Shot 2019-05-05 at 10.00.31 AM.png

    You have to zoom in fairly close though or else the prefab icon covers the trigger value.

    --Eric
     
  23. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    296
    Yes, I see what you mean. You do have to zoom in very close to see it though.
    Anyway, thanks for checking and letting me know.
     
  24. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    74
    I'm a little confused about importing from Tiled. I'm getting an error: "No tilewidth property found in tileset tag" and I don't know what I need to fix that, other than editing the XML manually. I notice the sample XML uses PNGs in the tileset tags – does SpriteTile not support Tiled maps that use .tsx tilesets?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    As described in the "Importing a Tiled map" section in the docs, Tiled files require some manual work to import, including importing the tiles as sprites. The tilewidth and tileheight tags are used for informational purposes so you know what pixel sizes to use when slicing the tilesets. So no, .tsx tilesets wouldn't work. The tiles should be in some format that Unity can import, which would usually be .png.

    --Eric
     
  26. Kaven-Co-Games

    Kaven-Co-Games

    Joined:
    Jun 3, 2014
    Posts:
    16
    Hey Eric, I just wanna let you know I've been using SpriteTile for years and I very much love it. Thanks for all the hard work you do man. I wanted to leave this here just because I have been saved so many times by this. You're a blessing. :3
     
    SoftwareGeezers likes this.
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,244
    Thank you, it's very nice to hear that!

    --Eric
     
unityunity