Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

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

  1. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    Please add to tk2dSlicedSprite.cs

    Code (csharp):
    1.  
    2.  
    3.     void OnEnable()
    4.     {
    5.                 // This will not be set when instantiating in code
    6.         // In that case, Build will need to be called
    7.         if (collection)
    8.         {
    9.             // reset spriteId if outside bounds
    10.             // this is when the sprite collection data is corrupt
    11.             if (_spriteId < 0 || _spriteId >= collection.Count)
    12.                 _spriteId = 0;
    13.            
    14.             Build();
    15.            
    16.             if (boxCollider == null)
    17.                 boxCollider = GetComponent<BoxCollider>();
    18.         }
    19.  
    20.     }
    21.    
    22.     void OnDisable()
    23.     {
    24.         if (mesh)
    25.         {
    26. #if UNITY_EDITOR
    27.             DestroyImmediate(mesh);
    28. #else
    29.             Destroy(mesh);
    30. #endif
    31.         }
    32.     }
    33.  
     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @eskimojoe,

    I am aware of the "xxx mesh leaked" message, and while this gets rid of the message, and more or less fixes it, this isn't the best solution to fix this issue. OnEnable and OnDisable are called when you activate and deactivate a mesh - i.e. if you pool your sprites, you're going to get very little benefit, as the meshes will be regenerated every time you enable them as opposed to once at startup.

    There is a way to fix this properly, and without any additional overhead - I've had this fix for absolutely ages but never got around to deploying it as it hasn't been tested on many different set-ups.

    Drop me an email if you'd like a copy (support@unikronsoftware.com). Otherwise I'll try to get tested enough for the next release.
     
  3. Itchy-Games

    Itchy-Games

    Joined:
    Jul 8, 2009
    Posts:
    221
    Hi @unikronsoftware,

    I want to make a little request for the next updates (or a plugin):

    ok, we have the 2D colliders, but for some 2D games we need something more appart of this.

    I´m talking about HitBoxes.

    - on sprite collection editor, appart of edit the base collider, we can add none, 1 or more hit boxes on each sprite.

    - These hit boxes behave more or less like collision triggers: if some base collider (or even another hitbox) collides, activates an event or delegate (like the animation triggers).

    - maybe needs to have a public boolean that enable or disable the hitbox detection on the base collider, (this can control the number of times that a hitbox of a certain sprite animation only collides once and not each sprite update for example).

    - HitBoxes can send a string, int or/and float variable (like animation triggers).

    - This last is optional, but you can add the posibility to do the same with base colliders (that we can add none, 1 or more base colliders to the sprite)

    I hope you consider it to add on the 2D Toolkit´s next updates.

    Regards,
    Jonay.
     
  4. 3dFoin

    3dFoin

    Joined:
    May 30, 2011
    Posts:
    631
  5. bazmod

    bazmod

    Joined:
    Jul 3, 2012
    Posts:
    1
    Hi, I have a problem with the atlas generation in 2dtk. I have 6 textures that will fit into a 1024 atlas (they all have a width of <512 and I can easily fit all 6 of them into a 1024 texture in photoshop). However the atlas generator is giving me the 'unable to fit in atlas' error. Is it possible for me to organize the atlases manually?

    To recreate this I have 6 textures that can be organized in an atlas like this:

    t3: 512x267 - t2: 512x300
    t4: 512x359 - t5: 512x385
    t7: 512x394 - t6: 512x335

    what is really annoying me is that if I use 2dtk to create an atlas with t3,t4,t7 then it creates a 512x1024 atlas. Same thing happens if I use t2,t5,t6. But putting them all together it refuses to create one 1024x1024 atlas...?

    I've also tried resizing everything to have a width of 510 instead of 512 just to make sure that its not trying to add padding - by the way, I have made sure that I have the pad amount set to 0.

    Any help would be much appreciated?

    Many Thanks
     
    Last edited: Aug 12, 2012
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, something like this is already in the pipeline - I've added your suggestions to the TODO so I'll investigate all of this when I start work on it. It'll be after 1.80 though, 1.80 is mainly for dynamic atlas loading.
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Drop me an email at support@unikronsoftware.com - I have a few suggestions to try.
     
  8. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I've not tried this thing in particular, but I don't see why you couldn't combine the two. 2D Toolkit simply creates geometry which you can use in your scenes, and you should be able to just mix and match the way you like / need. Again, I'm not confirming that it WILL work - as I've not tried this asset - but I can't see any obvious reasons why it wouldn't.
     
  9. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,125
    @unikronsoftware

    how is your flash support? is it compatible with the current beta version?

    can i use your sprite with unity animation editor? (position, rotation, scale)
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @atmuc

    Flash export worked fine the last time I tested. The tilemap rebuilding (i.e. dynamically updating tiles in the tilemap) doesn't work on Flash, and I wasn't going to workaround that until the final flash version got released. No other limitations as far as I'm aware.

    You can work with the animation editor, position and rotation work fine, but... there is a catch with scale - dynamic batching will stop working when an object is scaled, so the best option here is to transfer the data from transform.localScale -> sprite.scale using a script.
     
  11. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,125
    i understand this; you believe flash export must be supported and you will go on improving flash support .

    do you plan to add skeleton animation feature? is there any restriction to use skeleton animation now by using parenting on sprites?
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Flash works for the most part apart from the tilemap thing above. I will continue supporting it for as long as it is viable - Unity are constantly making it more and more compatible, so things should only improve over time.

    I have plans for some form of skeletal animation add-on in the future which will work with the Unity animation system.
     
  13. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    Hi,

    Can you make it auto-save when Unity is switching platforms?
    I get lots of prompts when switch platforms:

    $Unity.png
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    @eskimojoe, I've never seen those prompts before. Is there a setting somewhere to enable it?
     
  15. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    It's in build settings where you point to a different target then press change target.
     
  16. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    When I change targets (e.g., PC to iOS), it goes and prompt to save.


    If I setup a cache server, it prompts estimated ~5 times, takes almost 10 seconds to re-import everything.
    If I do not setup a Cache server, it prompts estimated ~50 times, takes almost 2 hours to re-import everything.


    Most annoying is when you wait for Unity to import and then these 'Save Assets' popup occur.
    If you don't didn't see the "Save Assets" dialog, you may spend hours wondering why your Unity project takes so long to import.
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    OK I found it. These dialogs are only visible when "Verify Saving Assets" is turned on - I have never had it on hence I've not seen it ever. I also noticed how Unity pushed the dialogs to the back. I'll investigate this. I don't think there's any callback "before platform is switched", but I think this is due to the atlases being regenerated because Unity thinks the textures have changed. I'll see if theres a way to work around this - its largely unnecessary as the I don't need the platform specific version of these textures.
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Right. I've got a patch which will stop this, with or without cache server. Anyone fancy testing it to see if it works in their config?
     
  19. YUSHI

    YUSHI

    Joined:
    Jul 7, 2012
    Posts:
    19
    I want to made a red coler encounter another color ,slowly from the center to become the color of the encounter.
    Please tell me how to do?
     
  20. unikronsoftware

    unikronsoftware

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

    Can you please explain in a bit more detail what you need exactly? Is there a video of what you need exactly?
     
  21. YUSHI

    YUSHI

    Joined:
    Jul 7, 2012
    Posts:
    19
    like this
    $1.JPG $2.JPG $3.JPG
     
  22. marjan

    marjan

    Joined:
    Jun 6, 2009
    Posts:
    563
    Hi i just bought 2dTK and am already stuck. I had a whole level already up and running, but thought igive t2Toolikit a try.
    So i have a character that needs to be cot in layered parts. Body behind, in fron t eyes and mouth. OK, i gut that.
    Then same kind of platform where he can walk on. Got that.
    But. For some reason i don't Understand the camera and scene scale are messing up the phyiscs. (I used one of the demo scenes to put my own stuff in for the beginning). Now, when i hit play, the character is sinking down superslowly to the platform. That means the seen scale is wrong, i guess. or the cameras orthographic scale.
    I have absolutly no ideo on how to fix this with 2DToolkit infolved.
     
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can adjust either thing (or both) here, I need more info on how you've set this up to be able to give you any meaningful advice.

    Drop me an email, it'll be much easier to work this out there.
    support@unikronsoftware.com
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  25. atamocius

    atamocius

    Joined:
    Aug 18, 2012
    Posts:
    8
    Hi, I'm contemplating on getting 2DToolkit, but I'd like to ask 1 question first. Is it possible to use the 2DToolkit out-of-the-box to procedurally generate a level ala Spelunky?

    If so, how would I go about it? Can the Tilemap SpriteCollection be built up through code?

    Edit: To be more specific, when I say "procedurally generate", I mean building up the tiles for a level.
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, that is possible. The easiest way to go about this, is fill up the tilemap with one tile and at level load, fill it up procedurally with whatever you need at runtime.
     
  27. atamocius

    atamocius

    Joined:
    Aug 18, 2012
    Posts:
    8
    Sweet! One more thing, so I assume that the TMX loader creates a Tilemap object once loaded?
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, it works the other way - you create a tilemap object, and then import a tmx into it. This only works in the editor at the moment - though it should work at runtime if need be with a few modifications. It needs an additional managed dll (zlib.net) to be present in your project.
     
  29. woko

    woko

    Joined:
    Oct 11, 2011
    Posts:
    23
    Hi! Are there any plans to add support for the new dynamic fonts from unity4? I'm using a regular bitmap font right now, but I'd like to enable CJK characters in some way. The dynamic fonts look like the way to go, but all my UI is made in tk2d, so I'm hoping it'd be feasible to extend the tk2d textmesh somehow.
     
  30. sanpats

    sanpats

    Joined:
    Aug 24, 2011
    Posts:
    343
    Hi,

    I am developing turne-based game, and, when it is time for a character to move, I want to hi light walkable tiles with transparent color. Any tip on how to do it?

    Btw, I use tilemap engine in tk2d.
     
  31. BaronGalf

    BaronGalf

    Joined:
    Aug 15, 2012
    Posts:
    8
    I have 2 special request before buying your product. What I want to do exactly is to be able to join multiple sprites in one to create a animation. All my body part are separated in 5 sprites sheets. Is there a way to make an animation from that beside creating 5 AnimatedSprite upside each other ?
    The second part is that i want to edit the position of each sprite in my animation. example: I want to move my body 1 pixel up then 1 pixel down to make a breathing effect in my animation. It is possible with 2D toolkit ?

    Thanks !
     
  32. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    I've been out o the 2D game for a while and recently updated the 2DTK and was very happy to see the camera bug has now been fixed! However, I have a question. If i make my sprite in 2 layers, say the front layers being the eyes, ears, nose and mouth, and he second layer being a head. I create a "head" sprite which contains the head image, then nest the facial features inside that. Imagine if both sprites are animations. How can I get the "head" animation to trigger the "mouth" animation? Is there a way to group the animations or would I have to get them both to play independently?

    Also do I need need 3 handlers to play animation, stop animation, and do physics?

    Code (csharp):
    1.  
    2. if( Input.GetKeyDown(KeyCode.D) ){
    3.             anim.Play("Run");
    4.         }
    5.        
    6.         if( Input.GetKeyUp(KeyCode.D) ){
    7.             anim.Play("Stand");
    8.         }
    9.        
    10.         if( Input.GetKey(KeyCode.D) ){
    11.             transform.Translate(Vector3.right * moveSpeed * Time.deltaTime, Space.World);
    12.         }
    13.  
     
    Last edited: Aug 24, 2012
  33. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Hello Unikronsoftware,

    I have some text clipping too early in and out of the screen. The texts are parented to a scrolling main sprite. Any idea of what the issue could be?
    Also, do you have an idea on how I could change some colors on a sprite and not others?
    Thanks!

    f.
     
  34. G_Koko

    G_Koko

    Joined:
    Aug 25, 2012
    Posts:
    30
    Hi Unikron, one question. When i update the Toolkit for the new update from Unity, sent me several errors because of this. I don't know if i need to do something, move carpets, to fix that problem. I saw the carpets between the past Toolkit that i have and the last one, and you increased a few in the root folder.

    Thanks.
     
  35. unikronsoftware

    unikronsoftware

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

    I'm not sure about dynamic fonts. I will have to investigate that - Unity doesn't expose a lot of that stuff, so it might not be possible. However, it might be able to make tk2dTextMesh wrap around and use the dynamic fonts in place. Drop me an email if you wanna explore that and I'll explain how you can do that. support@unikronsoftware.com
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hey sanpats,

    The easiest way to do this is - first, you get the position of the tile, tileMap.GetTilePosition(x, y). Get the spriteId at the position with tileMap.Layers[0].GetTile(x, y). Create a new tk2dSprite with the sprite collection and spriteId, and put it at the position you got earlier, and push it forward in z a bit, so it appears on top of your normal sprite.

    Now you can do what you like with it. I suggest putting a different shader on it, eg. one which doesn't read the rgb values, but simply uses alpha - i.e. the shape of the tile will be correct, and you can fade the highlight in and out.

    Hope that helps.
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @BaronGalf,

    With the first thing - you can create animations from multiple sprite collections. Is that what you mean, or do you mean coordinated sprite animations for the different parts of bodies (i.e. multiple sprites). The second would have to be done by hand.

    The answer to the second question is yes and no. We don't have a custom animation editor like other skeletal packages, and while I don't intend on making one, I do intend on making it a whole lot easier to animate this using the built in animation editor. So yeah, it is doable right now, but not exactly an amazing experience. It will get better in future updates.
     
  38. unikronsoftware

    unikronsoftware

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

    I am pretty sure I know what this is...
    in tk2dTextMesh.cs, look for these lines and change from
    Code (csharp):
    1.  
    2.                 // comment this in for game if it becomes a problem
    3.     #if UNITY_EDITOR
    4.                 mesh.RecalculateBounds();
    5.     #endif
    6.  
    to

    Code (csharp):
    1.  
    2.                 // comment this in for game if it becomes a problem
    3. //  #if UNITY_EDITOR
    4.                 mesh.RecalculateBounds();
    5. //  #endif
    6.  
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Are they warnings or errors? 2D Toolkit 1.76 + patch1 definitely works fine in Unity 4 beta 7. What versions are you using?
     
  40. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    It worked! Thanks a lot! :D
    Any idea on how to change some colors from a sprite and not others?
    Cheers!

    f.

     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You mean like if a sprite had red + green + blue all on one sprite, just to change red? The easiest option would be a custom shader, but it would be very specific to what you want to do there...
     
  42. YUSHI

    YUSHI

    Joined:
    Jul 7, 2012
    Posts:
    19
    I want to made player hit monster player change appearance if hit monster again the player change appearance .How to do?
    And how to flicker player?
    And how to made like this game in android? Like character collision and character move.Can give example?
    game Website :http://www.wordfreegames.com/game/spongebob-halloween-horror-1.html
    Like this:
    $2012-08-27_144938.jpg
    $2012-08-27_145113.jpg
    $2012-08-27_145213.jpg
    $2012-08-27_145202.jpg
     
    Last edited: Aug 27, 2012
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you wanna change the player from one sprite to another like the pics above, the easiest is to have 4 copies of every sprite. Alternatively you can use a custom shader to do the reveal but that's a bit trickier to get revealing correctly, consistently. Another option is to have 2 sprites, one the first one with the alpha to draw the sprite, the second containing alpha describing the reveal + custom shader.

    To flicker the player, use sprite.color.a - modify that over time to make the sprite flicker.

    How to do character collision and movement - I suggest looking at the Unity 2d game example for that. Its far too involved to describe in a few lines.
     
  44. G_Koko

    G_Koko

    Joined:
    Aug 25, 2012
    Posts:
    30
    Are errors in the scripts of the TK2D. I update to 3.5.5f3, and i download the last update you have in the asset store. I need to update to the Unity 4 beta 7 to work fine? And with this works fine with the iOS 6 update beta?
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Drop me an email at support@unikronsoftware and we'll try and work out whats going on. The latest version on the asset store should work fine on Unity 3.5.5, and works in Unity4 beta 7 (with a few warnings).
     
  46. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,116
    Hi! I'm having a strange issue - this occurs only with PremulVertexColor
    ( BlendVertexColor works but objects have this slight dark outline so it can't be used. )

    The issue is as follows: we are using toolkit 2d to make atlasses for later use in 3ds max. However, if we later save the atlas in photoshop as a png or anything else, suddenly some of the empty areas become white, and this "whiteness" is visible as white lines/shapes on the actual model

    (simulated image)


    in other words, we cannot seem to edit the created atlas images without causing these white parts to appear - how do we avoid this?
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I have a good explanation of why this happens, but probably not a foolproof way of avoiding it.

    For starters, you have to understand how photoshop saves alpha color channels in PNG files. (PNG files are 32bpp, and store color and alpha values). To compress better, the png saved by photoshop will white out square areas where alpha = 0. Check the image for more info. It will always find the largest square it can fit in.



    The PNG writer in Unity will write out exact pixels specified in the texture. Premultiplied alpha will premultiply the rgb with alpha channel. So rgb in any area where alpha = 0 will become 0,0,0.

    So the difference will be - in 2D Toolkit, saving out the image the areas with 0 alpha will be 0,0,0. If you load it into PS and save it out, it will fill up the square areas with white (and 0 alpha) which is what you're seeing in your image there.

    So, if you can find a png plugin which will write out complete data rather than "optimizing" the image, then you could work around this... I never edit the atlases, so never have this issue.
     
  48. BaronGalf

    BaronGalf

    Joined:
    Aug 15, 2012
    Posts:
    8
    Hi,
    I'm looking for a solution to make a 2D platformer game where we play in total darkness with a flashlight. I only want to show the real color of my sprite without "reflect" or "Brightness glare" so avoiding 3D spotlight at all cost. It is possible to achieve this with 2D toolkit and Unity Free 3.5.5 ?

    Thanks
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There is, but you'll have to build the tech yourself. We're working on a seamless solution to this as a low priced add-on to 2D Toolkit, but that isn't ready for use yet (doesn't cope with all scenarios yet). Post on the private support forum (http://unikronsoftware.com/2dtoolkit/forum/index.php/board,5.0.html) and I'll share a bit more information on how you can do this yourself if you want to.

    Or if you can wait a couple weeks or so, then we will have a really neat solution to this working on Free (with a lot of bonuses when run on Unity Pro).
     
  50. BaronGalf

    BaronGalf

    Joined:
    Aug 15, 2012
    Posts:
    8
    Awesome thanks !