Search Unity

  1. 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
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

2D Toolkit - 2D in Unity made simple [RELEASED]

Discussion in 'Assets and Asset Store' started by unikronsoftware, Jun 16, 2011.

  1. acmshar

    acmshar

    Joined:
    May 4, 2010
    Posts:
    24
    I understand about 3.5. We are only on it because we need pro features and can't get the extra funds to get a few pro 4.x licenses before we finish this project. Oh right, I forgot that was the name of his UI solution!

    Ok, so dicing should be fine if the sprites won't be animated or scaled too much, and if they are, might be ok, but I should probably check just in case?
     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup. Scaling is normally fine, its animating that is more adversely affected, as poly counts are likely to change between frames.
     
  3. wightwhale

    wightwhale

    Joined:
    Jul 28, 2011
    Posts:
    390
    How do you detect collisions between objects in the UICamera? When I use OnCollisionEnter() nothing ever happens.
    Currently I'm trying to detect when the user drags one button into a sprite.
     
  4. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    I'm importing a TMX file into the tilemap, and I was wondering how the Chunks are created in the children gameobjects in the TileMap Render Data gameobject? It'd be nice if I could combine some of the Chunks, and I was wondering if I can do that in Unity 2DToolkit, or do I need to do that ahead of time in the Tiled app that exports to to TMX?
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That has nothing to do with the camera - for OnCollisionEnter to work, you need 2 colliders hitting each other, and they can't be triggers. How have you got yours set up?
     
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The chunks are created at regular intervals. You can't combine them, as the data is partitioned into regular chunks for various reasons - mainly being able to discard chunks that aren't there, and still being able to index quickly.

    Is there any reason in particular you need to join the chunks?
     
  7. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    I was interested in joining chunks, so that their collision data would be together, so that way I could activate/deactivate parts of the tile map. That way I could build a map that is a room by room type layout, similar to Super Metroid.

    I suppose I could just parent the chunks that belong together under a common parent gameobject. Or will that break things?

    Edit:
    I think I can do what I'm trying to do with the layers in the Tiled App.
     
    Last edited: Sep 6, 2013
  8. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,150
    Hey there,

    for some sprites I set up a custom box collider in the SpriteCollection for the Attack-Animation.

    Now it is not possible to set the Z-Position of the Collider. Everytime I set it to a certain number (1, 12, -5) and run the game it's setting itself back to 0. Is there a workaround?
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup. I was just about to suggest that. Layers work with tk2d, and do it that way. Though if you had a VERY large number of layers, it might be better to consider other alternatives.
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't a way to set the z position of the collider independently right now. Any particular reason you're doing this?
     
  11. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,150
    Yes, there is a reason:

    - my Character Sprite has the custom Collider, made in SpriteCollection
    - my Enemy has also a custom Collider for the Attack-Sprites, made also in that certain SpriteCollection

    Now I want to draw the Character in FRONT of the enemy, but when I change the Z-Position the Collider moves of course and doesn't collide any more with the Enemy, of course.
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In 2D Toolkit 2.2, you can change the order of sprites without changing the z position. That could just work for you here. The beta is available right now - you can grab it from our forum (http://unikronsoftware.com/2dtoolkit/forum/index.php). There aren't any major known issues and its been out for a while, so if you need a solution now, feel free to grab that.

    Alternatively, you can change the code to make sure it doesn't modify the z values on the collider, but the above is a much nicer solution.
     
  13. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,150
    But wouldn't changing the sprite's position also change the Box Collider, since it is attached to the sprite itself?
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes thats the point. In 2.2 you dont have to use z depth to sort the sprites, you can simply use the renderLayer property instead. That doesnt actually change the positions of sprites but will let you decide how to sort them.
     
  15. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,150
    Ah, I see, well, that's great, isn't it. I'll grab that when it's not in beta anymore.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Shouldn't be too long now. Probably this week.
     
  17. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Hey Unikron, I'm looking to create doors to different tilemaps/other parts of the tilemap, but I'm having trouble finding the position of individual tiles. Looking at the API, it looks like there are ways to find position if you explicitly define the position of the tile in the tilemap, but is there any way to find the position from a reference to a specific chunk?
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,

    There isn't any API to expose the internal chunk structure as that could change. Do you need to do anything relative to a chunk though? The world position (as opposed to chunk local position) can be directly resolved to a tile x, y coordinate and you'll be able to work around not knowing where chunk boundaries are.

    Are you using the chunk system for anything out of the ordinary?
     
  19. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Not really, I was just hoping that I could use a reference to the connecting door rather than essentially hardcoding the x and y values of the tile. Sounds like I can't do that? Not a big deal, was just hoping I could
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I don't think I understand how using the other method would change anything. You could use triggers and spawn the door object as a prefab - that way you might not even need to know the positions relative to anything else.
     
  21. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    My apologies, I should have explained a bit more...I've been working with JNA's 2d plaform controller, which uses raycasting for triggers rather than unitys physics. Tiles that extend the platform class in the platform controller contain logic to handle triggers. I've been attaching a door script which extends the platform class to the chunks in 2d toolkit, and giving it a reference to the connecting door. In this way I would never have to specify the world or tilemap coordinates of the connecting door, I can just make the player's position equal the reference to the second door's position from the first door's script. Does that make a little more sense?
     
    Last edited: Sep 9, 2013
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  23. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    I was wondering if you had any other alternative suggestions just in case? Currently, it looks like I'll have about 32 rooms, though that number may get larger, which could potentially get out of hand.
     
  24. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,015
    Our company uses 2D Toolkit and it's amazing, thanks for the awesome plugin!
     
  25. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    32 layers isn't too bad, actually. Your use case is quite unique in that you're using layers as for mutually exclusive things. The overhead for these is really low, so you could have 32 or 64 layers at very little cost. 32 completely filled layers would be bad. The max is 32 right now, you can increase it to 64 if necessary. It shouldn't be any issues the way you're planning on using it.

    Ultimately though, if your game is big enough, you should consider using a different scene and use LoadLevelAdditive for each room as you need to. That will free you from any limitations and you can extends this massively.
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That does make a bit more sense. But instead of making the player position == second doors local position, you could simply player.worldPosition = secondDoor.worldPosition. Unless I'm missing something, this should just work, shouldn't it?
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You're welcome. Glad its helped.
     
  28. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Well, that's what I originally thought to do, but I have the doors as a separate layer in the tilemap, and I don't seem to be able to get the actual positions of the chunks...I get the position of the actual tilemap instead
     
  29. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you have the gameobject for the door, then you can get the layer object by traversing up the hierarchy. transform.parent = layer.
     
  30. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    Hey Unikron,

    We noticed when you import a .TMX file into the tilemap, it is only an additive import, in that it will add the .TMX file and its layer into the layers that were already imported into the tilemap. This makes sense, but if we want to say import a .TMX file to replace the a .TMX file with a mistake in it, the tilemap still saves the originals layers, which we want to be overwritten. Is there a way to overwrite?
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No there isn't at the moment, but it should be easy enough to tweak in the code.
    tk2dTileMapImporter.cs, PopulateTilemap is where the tilemap is filled. If you delete all layers before starting, it'll force a full import.
     
  32. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    If you don't mind me asking, how do I delete the layers? I tried to call the tk2dEditor.TileMap.TileMapUtility.DeleteLayer(), but I'm not sure how to get the layerToDelete integer value.

    Edit:
    Clearing the tileMapLayers List seems to do the trick.
    tileMap.data.tileMapLayers.Clear();
     
    Last edited: Sep 11, 2013
  33. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Right, and I'm doing that, but I'm getting the position of the tilemap origin instead. Perhaps I'm doing something wrong with the actual tilemap. Anyway, you answered my original question, so thanks for the help! I'll figure out what I'm doing wrong.
     
  34. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    We were going to make the TileMap a prefab that we use in other scenes, but we noticed when we make the Tilemap prefab and drag it into another scene, none of the tilemaps tiles copy over. We get all the chunks in the Unity Hierarchy, but none of the tiles show up in the scene view.
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Going in and out of edit mode will fix it there when you instantiate the prefab. You need to create a prefab from the tilemap object, not the render data object.
     
  36. destapp

    destapp

    Joined:
    Oct 22, 2012
    Posts:
    18
    i have a question, is possible to build flash using 2d toolkit? when i import assets 2dtoolkit and build it to flash, its always getting error..
    $error.jpg
    thankyou unikron :)
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It used to be, but later versions haven't been tested with the Flash export in later versions once Unity announced that they were discontinuing it. The error is specifically in demo code - you could try deleting the demo c# files to see if you get any further?
     
  38. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    We tried creating the prefab from the tilemap object, but it still does not seem to work. When we click edit then commit after instantiating our TileMap prefab, it creates a TileMap Render Data gameobject with all the child gameobject layers without any children chunks gameobjects.
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    How are you doing this? You're instantiating in code, but then clicking edit in the editor? This seems to be a very specific use case. Drop me an email and we'll discuss further. support at unikronsoftware dot com.
     
  40. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    We do everything in the Unity Editor for right now. Should we not?
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You should. If thats the case, this should work just fine - I'll investigate. You're on 2.2, right?
     
  42. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi everyone,

    2D ColliderGen is today's Daily Deal at -75% (only 7,5$ instead of 30$)!
    If you don't already know, it integrates with the 2DToolkit framework to automatically generate polygon colliders for your sprites at the click of a button!
    Give it a chance now or live with regret ;)
    $2DColliderGen_DailyDeal.png

    Short Trailer:


    Visit the Asset Store page: [link]
    Website with Documentation and Video tutorials: [link]

    And thanks so much to all who have already happily purchased the tool! Big Thanks to you guys! :)
    Cheers, Harald
     
  43. Fuzzypup

    Fuzzypup

    Joined:
    Aug 13, 2013
    Posts:
    124
    Would this toolset work well for turn based wargames using hexes?

    Some maps would be loaded and objects instantiated (hexes based on map size, terrain, units, resources)
    Some maps would be randomly generated

    Thanks
     
  44. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    Yeah, we're on 2.2.
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    2D Toolkit does sprites, tilemaps, etc and doesn't have support for specific game types. You could certainly build a hex based game with it, but the built in tilemap editor doesn't support hexes natively. Well it kinda does, but not officially - it supports stagerred tilemaps, and can be made to work with hexes instead of diamonds.

    Hope that helps, don't hesitate to ask if you have any further questions.
     
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I don't seem to be able to reproduce this at all - Commit tends to fix it after instantiating. We've patched in the code to automatically build the meshes when dragging into the scene / Instantiating. Drop me an email and I'll share the changes with you before the next release.
     
  47. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    799
    Nooooooooooooooooooooooooo! Missed it... :(
     
  48. cc0919

    cc0919

    Joined:
    Apr 5, 2013
    Posts:
    17
    Unikron, got another quick question for you...

    I'm animating volumetric shadows by slowly changing the texture's offset using renderer.material.SetTextureOffset. When I have a 2d toolkit animated sprite in the scene, and the sprite is moving/animating, the offset changing of the volumetric shadows stops until the sprite stops animating. I don't have this problem when I use renderer.sharedMaterial, but I'd like my shadows to animate separately (by the way, the shadows aren't made in 2d toolkit obviously.) Anyway, have you run into this at all? Any ideas?
     
  49. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    I've got some good news for you at least: just writing a new post in a second..
     
  50. Pixelcloud-Games

    Pixelcloud-Games

    Joined:
    Apr 29, 2011
    Posts:
    158
    Hi again everyone,

    2D ColliderGen is now Permanently Reduced -50% (15$ instead of 30$)!
    If you don't already know, it integrates with the 2DToolkit framework to automatically generate polygon colliders for your sprites at the click of a button!

    We felt a bit sorry for those who missed the DailyDeal, so this is our way to help.
    If it has been too expensive for you at 30 bucks, maybe you want to give it a chance now..

    $2DColliderGen_Permanently50OFF.png

    Visit the Asset Store page: [link]
    Website with Documentation and Video tutorials: [link]

    And thanks so much again to all of you who have already purchased it! You guys rock! :)
    Cheers, Harald
     
unityunity