Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

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

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

  1. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can do exactly the same thing as tk2dAnimatedSprite is derived from tk2dSprite. So,
    GetComponent<tk2dAnimatedSprite>().color = new Color(1,1,1,0.5f);
    will do what you need.

    You shouldn't be calling GetComponent all the time, and cache the results, but that is just best practice generally anyway.

     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. RGBA32 is your best choice for quality. Compressed does look poor, but sometimes you can get away with it. You can also use 16bit depending on your texture contents, and this may look decent. The size of the texture 1024x1024 - 4MB for RGBA32 is as expected, there is nothing you can do about it :(

    2. Generate mipmaps is a tricky one. Having it enabled means your game will scale down to iPhone 3GS from iPhone4 resolution correctly. This is the only supported option for automatic scaling down for now, we are developing another method where you won't need mipmaps, but that hasn't been relesed yet. So if you need it to scale down automatically for iPhone 3GS, leave this enabled, otherwise turn it off.

    3. I am not sure I understand this one... could you please elaborate? The dice feature is to take larger images and dice it up into a small one while discarding empty space.

    unikron


     
  3. Seokho

    Seokho

    Joined:
    Aug 31, 2011
    Posts:
    23
    What I asking for this.
    When other 2D sprite tool before start to make atlas, they ask or have a option of atlas's width height size.
    So user can choose atlas width and height.
    But 2D ToolKit just make automatically. That is easy but can't make size user-self.
    Do you have a plan this feature?
    And I think "Sprite Animation GUI" (when make an anmation) has to be better than now.
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In 2d toolkit you can specify the maximum atlas size, eg 512, 1024, etc. you can't specify the full size, but we will reduce the atlas size automatically. For example if you have an atlas with max size of 2048 and only one 64x32 texture in it, your atlas will automatically be reduced to that size. Is there any particular reason you need to be able to specify full dimensions?

    There are plans to improve sprite animation GUI, but most of those are productivity improvements not making it prettier for the sake of making it prettier. This will be done in small batches over a period of time.

    Unikron
     
  5. vargonian

    vargonian

    Joined:
    Sep 3, 2011
    Posts:
    12
    Is there any documentation for this toolkit besides the videos? I'd like to get more introduction / theory behind what I need to do rather than just being shown some examples. For example, the very first instruction of the Sprite workflow video leaves many questions:

    "1. Starting out. Sprites saved in Sprites/src."

    Does this mean that sprites must be saved there, or they just happen to be saved there in this example? I assume the later but clarity would be appreciated.

    "1a. Sprites don't need to be Poz."

    I have no idea what "Poz" means. Positioned? Perhaps that's not a 'z' but a '2', and it means that they don't need to have power-of-2 dimensions.

    "2. Create a sprite collection."

    Wait, is a sprite collection a bunch of frames for a single sprite, or is it more like a texture atlas that can span multiple sprites?

    I could go on, but as you can see, the point is that I'm missing out on a lot of the introductory concepts. Hopefully I'm just not seeing the documentation; could someone point me to it?

    Thanks.
     
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'll PM you the current manual. We will be updating it to a HTML manual later on, as the PDF one is getting unmanagable.
    I can see how you are confused with this. We will also be doing another video tutorial, a decent one this time.

    Just to answer your questions:
    1. Just in this example. They can be saved anyhwere, and then moved anywhere else.
    2. PO2 = Power of Two.
    3. The sprite collection is the object you create to store a collection of sprites and set up their properties. An atlas (or atlases with the current version) is created from the sprite collection.

    I can appreciate some things may not be clear; those videos were just built as a quick demo during development. If you have any questions feel free to PM / support form on website.

    We have done a LOT of work to make obvious things just work, though its not possible to catch everything our users may do! Our idea is, the less you see of our interface, the better.

    unikron


     
  7. vargonian

    vargonian

    Joined:
    Sep 3, 2011
    Posts:
    12
    Thanks a lot, I really appreciate it. In fairness, I was going over this stuff with a very tired brain last night so I wasn't picking up as much as I otherwise would have.
     
  8. vargonian

    vargonian

    Joined:
    Sep 3, 2011
    Posts:
    12
    In the manual, when discussing texture refs in a SpriteCollection, it says "You should NEVER reorder sprites within the list as this will break sprites already set up."

    But what if this is exactly what I want to do? I don't care what this does to existing sprites; I can just regenerate the texture atlas. But what I need is a meaningful ordering of sprite IDs so that I can refer to them in code easily.

    Is there an easy way to reorder them? I can't seem to drag them around or anything.
     
  9. olecalfheim

    olecalfheim

    Joined:
    Aug 27, 2010
    Posts:
    3
    Am I the only one who recieves this error on import?


    `Resources' does not contain a definition for `FindObjectsOfTypeAll'
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You should use the name to resolve the id. That way the order can be static and you can refer to it from code in any order you wish. The button demo does this and the code is provided.

    Unikron
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What version of unity are you using? Can you try importing into an empty project, there could be a conflict with one of your assets. If this is the case we'll need to track it down and fix it..

    We do not wish to move our code into a DLL assembly, though that will greatly reduce the possibility of conflicts, it also means we won't be distributing code anymore, which I think is really important in a product like this.

    Anyway, we should move this to email until it is resolved, and I will post a reply with the solution in case someone else experiences it.

    Unikron
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Ole fixed the problem, in case anyone else encounters the same issues:

    I solved the issue by writing "UnityEngine." in front of "Resources." so it would say "UnityEngine.Resources.".. Then I got similar errors on "Path.". And that's because I had the Path plugin installed, removing that plugin altogether solved the issue.

    Again, I am very reluctant in packaging this up into a DLL assembly; I think source is very valuable for something like this, especially when it is built in such a way for the user to build upon.

    unikron

     
  13. arcandio

    arcandio

    Joined:
    Aug 30, 2009
    Posts:
    73
    What I'm trying to do is to set up my characters so that they idle until the player presses a key, then the character plays an attack animation and then returns to the idle. Upon actually trying to send play messages to the sprite animation with a single BroadcastMessage() when my attack begins, I noticed that it just freezes the sprite animation on the first frame I tried to call. Do I have to send Play() every frame?
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, you should only call Play once. Can you test your animation by creating an Animated Sprite, dropping it in the scene. At this point you can pick your SpriteAnimation and Clip and if you tick Play Automatically, it should play your animation properly when you press "Play" in Unity.
     
  15. Jodon

    Jodon

    Joined:
    Sep 12, 2010
    Posts:
    434
    After upgrading to the latest tk2d, all of the sprites that I'm using that have mipmaps and are on a lower mipmap now have black borders around them. If I disable mipmapping, the border goes away (but the texture doesn't look good because it aliases too much). Any ideas what could have changed? The previous version I was using didn't have support for multiple sprite sheets.

    Edit: Found it. You set the background to Color.black but it should be Color.clear. Search for:

    // Clear texture, unsure if this is REALLY necessary

    Turns out, it REALLY is :).
     
    Last edited: Sep 4, 2011
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    LOL. Thanks for that! I will get that into the next version due to be released very soon.

     
  17. arcandio

    arcandio

    Joined:
    Aug 30, 2009
    Posts:
    73
    That part works just fine, but I'm trying to switch an existing Animated Sprite from playing Idle to playing Punch and then back when Punch is done. Should I just code up my own solution that spawns a prefab of an animated sprite of Punch, then kill it after X seconds, or is there a way to switch an Animated Sprite back and forth between animations?
     
  18. Itchy-Games

    Itchy-Games

    Joined:
    Jul 8, 2009
    Posts:
    220
    use the Animation delegates trigger that have 2DTK since 1.05 version, works great. On the animation examples there´s a part of the script that helps you to use it.
     
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can do that no problem. Check the animation demo, "Animation delegate example". That example plays one animation, then switches automatically to another once it's done playing. You can also call Play which will interrupt the currently playing animation.
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks for that!
     
  21. vargonian

    vargonian

    Joined:
    Sep 3, 2011
    Posts:
    12
    What is the recommended way to handle touches/clicks on sprites? I notice they don't have MeshColliders (er at least, no mesh type... plane, etc.) so that method doesn't seem like it'll work out of the box.
     
    Last edited: Sep 5, 2011
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you add a BoxCollider to the Sprite, and increase the z depth slightly, it should automatically fit the sprite and you will be able to raycast too it. The button demo does just this. In the next release you will be able to set it up in the interface.

    Unikron
     
  23. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    219
    I am wondering how or if I can flash a sprite a color. In a standard 2D shooter sometimes they have where when an enemy is hit it briefly flashes red or white etc. I would like to do that with this package. I would also like to have better docs and examples, not videos and examples that have to slowly pull apart to figure out what you are doing.
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can flash a color by creating a script where in the Update function it flashes the color of the attached sprite. For example

    tk2dSprite sprite;
    void Start()
    {
    sprite = GetComponent<tk2dSprite>();
    }
    public bool flash = false;
    float flashTime = 0.0f;
    void Update()
    {
    if (flash) {
    flashTime += Time.deltaTime;
    flashTime = flashTime % 0.2f;
    sprite.color = (flashTime > 0.1f)?Color.red:Color.white;
    }
    }

    That's a really primitive example but it should do what you need it to.


    What kind of docs and examples would you like to have? With the whole thing being set up largely in the interface, its not exactly obvious what should be an example and what shouldn't. For example, the color flashing example wouldn't make a good example as its basic Unity stuff, and not particularly specific to 2d Toolkit (apart from the line setting the color).

    We are currently revamping the demo video docs, so any input here will be greatly appreciated.

    unikron
     
  25. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    174
    I'm getting an error when I try to change the sprite collection of a prefab. I select the prefab in the Project view, then change the sprite collection in the Inspector. I get this error.

    "NullReferenceException: Object reference not set to an instance of an object
    tk2dSprite.GetCurrentVertexCount () (at Assets/TK2DROOT/tk2d/Sprites/tk2dSprite.cs:111)
    tk2dBaseSprite.set_spriteId (Int32 value) (at Assets/TK2DROOT/tk2d/Sprites/tk2dBaseSprite.cs:47)
    tk2dSpriteEditor.DrawSpriteEditorGUI (.tk2dSprite sprite) (at Assets/TK2DROOT/tk2d/Sprites/Editor/tk2dSpriteEditor.cs:81)
    tk2dSpriteEditor.OnInspectorGUI () (at Assets/TK2DROOT/tk2d/Sprites/Editor/tk2dSpriteEditor.cs:24)
    UnityEditor.InspectorWindow.DrawEditors (Boolean isRepaintEvent, UnityEditor.Editor[] editors, Boolean eyeDropperDirty) (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/Inspector/InspectorWindow.cs:495)
    UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/842f9557127e852/Editor/Mono/Inspector/InspectorWindow.cs:190)
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)"

    Is this the expected behavior, limitation?

    The work around is to drag the sprite prefab into the Scene view, change the collection and apply the changes. It's not a big deal, but it does increase the time to edit a lot of sprites.
     
  26. bigdaddio

    bigdaddio

    Joined:
    May 18, 2009
    Posts:
    219
    I guess I expected a little better walkthrough, like a step by step of getting started. I no longer need that but the night I bought this I certainly could have used it... with pictures.

    Thanks for pointing out the blink, I was missing the GetComponent bit :)
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    Thanks for the feedback. We will add a tutorial (a html one so we don't have to worry about page sizes) to help others get started. We are already working on a full video walkthrough of creating the physics scene, we will just use stills from that for the document.

    unikron
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is a bug, and I have a very good idea when it got introduced. Will be fixed in the next release. Thanks for reporting it, and sorry for the inconvenience. I will post here with the fix when we have tested it thoroughly.

    unikron


     
  29. ArtX

    ArtX

    Joined:
    Jul 13, 2011
    Posts:
    16
    Last release have really cool futures. I have some questions. How to make sprite with polygon collider response on mouse touch? I'm have trouble with sprite collections when importing them from another PC(MAC) - as result old sprites broken. As i see the trouble with indexing and in linked file .tk2d.
     
  30. oliverdb

    oliverdb

    Joined:
    Jan 30, 2010
    Posts:
    165
    Well creating a multi-language system I have different length texts in different languages. I really want to center those on some defined max area.

    How would I go about doing that, anyone tried it?
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Polygon colliders don't create a cap right now; didn't think there would be much use with them so we skipped it, but we can certainly put it in as an option. As all the data is generated at atlas build time, there isn't an issue with performance. I'll try to get that in the next point release.

    The index will have issues if you import a sprite collection. You should delete it, and it will automatically regenerate it the next time you select a sprite. Let me know if this fixes your problem.

    unikron
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We can add an option to center around a region, but how would you expect the interface to work? What I can think of seems very complicated for something which should really be very simple.
     
  33. oliverdb

    oliverdb

    Joined:
    Jan 30, 2010
    Posts:
    165
    hey Unikron

    Well I found a solution where I made a cube I scaled to the area of the "parent sprite" where text was allowed. Then I added the textmesh as a child of that cube, disabled the cubes mesh renderer, and set the anchor to "middle-center". So it was very simple, once I found the anchor.



     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Well that's certainly an effective way to do it! Very clever.

    Doing it on the textmesh would have added more complexity to the code, something we have been striving very hard to avoid.
     
  35. arcandio

    arcandio

    Joined:
    Aug 30, 2009
    Posts:
    73
    I looked for this example, but I couldn't find it. Is it a video, a scene included in the kit, or a tutorial on your website? More specifically, can you just tell me the javascript syntax for an animation delegate? Assume I'm going from Idle to Punch and back on a Animated Sprite called Animator.
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The example is a scene within the kit, located at TK2DROOT/tk2d_demo/5 - animation. Here is a JS script which will do what you want. I am assuming you are attaching it to the animated sprite.

    Code (csharp):
    1.  
    2. var animatedSprite : tk2dAnimatedSprite = gameObject.GetComponent(tk2dAnimatedSprite);
    3.  
    4. function BackToIdle(sprite : tk2dAnimatedSprite, clipId)
    5. {
    6.     animatedSprite.Play("Idle");
    7.     animatedSprite.animationCompleteDelegate = null;
    8. }
    9.  
    10. function PlayPunchAnim()
    11. {
    12.     animatedSprite.Play("Punch");
    13.     animatedSprite.animationCompleteDelegate = BackToIdle;
    14. }
    15.  
    Hope that helps. If you need more specific assistance, drop me a PM and I'll see what I can do.
     
  37. WonkyWooGames

    WonkyWooGames

    Joined:
    Dec 31, 2010
    Posts:
    63
    Hello,

    Can anyone confirm that this is compatible with MegaFiers ?

    Cheers...

    D
     
    Last edited: Sep 11, 2011
  38. unikronsoftware

    unikronsoftware

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

    As mentioned in the email (not sure if you got it, as my email has been acting up the past two days):

    "I have not tested this plugin with Megafiers. A sprite in our system generally only has 4 points, unless dicing is turned on and which usually creates multiple quads, so I am not sure what kind of deformations can be performed on it."

    Cheers,
    unikron
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Due to feedback that the built in documentation is insufficient, and the amount of time it was taking to maintain it, we have decided to move all the documentation over to a wiki. You can currently access it at this address:

    http://www.unikronsoftware.com/2dtoolkit/wiki

    We have moved over most of the relevant documentation from the current document, and also added a new getting started walkthrough including scripting sprites, textmeshes and animated sprites. We also go through the process of creating a polygon collider. What remains to be moved over is the class reference, and this will be updated in due course.

    We have also added a link to the online documentation in the 2D Toolkit menu.

    Any feedback will be most appreciated.
     
  40. ArtX

    ArtX

    Joined:
    Jul 13, 2011
    Posts:
    16
    Thanks for reply. Removing of index file fixed problem. To make sprite with polygon collider response on mouse clicks and touches i added to project http://www.unifycommunity.com/wiki/index.php?title=Triangulator and temporary added code in SpriteCollectionBuilder at line 1239:
    Code (csharp):
    1.  
    2.         // Use the triangulator to get indices for creating triangles
    3.         Triangulator tr = new Triangulator(points.ToArray());
    4.         int[] indices = tr.Triangulate();
    5.                
    6.     for (int i=0; i<indices.Length; i++)
    7.         meshIndicesFwd.Add(indices[i]);
    8.            
    9.         for (int i=0; i<points.Count; i++)
    10.         meshVertices.Add( new Vector3(points[i].x, points[i].y, 0) );
    If you added it as option it will be helpful.
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks for that. We have added it as an option to add front, back and both caps, this could be useful depending on the situation.
    We have also added a rebuild index entry to the 2d toolkit menu.

     
  42. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Hi unikron,

    Do you plan to add an animation editor ( I mean just define the duration for each frame in an animation ) in a near future?
    It's a really important feature for animators and help for saving texture space.
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We actually had a few more tools in the animation editor, to duplicate frames, delete frames, delete to frame, etc. which should give you this ability. So if you wanted to achieve this:
    1 2 3 4 5 5 5 5 5 5 5 5 6 7 8
    you would do these actions:
    1. select frame 1
    2. autofill
    3. find frame 5, and click duplicate 7 times.

    I could get this feature tidied up and added if it will help.
    What do you think?

     
  44. funshark

    funshark

    Joined:
    Mar 24, 2009
    Posts:
    225
    Oh, that's interesting and usable for simple animation editing I think.
    Having said that, it would be nice to have more functionalities like a real duration editor and animation previewer. :)

     
  45. oliverdb

    oliverdb

    Joined:
    Jan 30, 2010
    Posts:
    165
    hey

    We have a themed game where i would really like to switch sprite automagically. But I do not want seperate objects since I have alot of physcis settings I dont want to repeat. Doing it by spriteID is very non-visual and is also bound to mess up

    Is there some way to invoke the sprite setting dropdown in my own script so I can read the unity-editor-set variables?

    hope it makes sense
     
  46. unikronsoftware

    unikronsoftware

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

    We will be adding these features mentioned in the previous post not long from now (probably in 1.52). We have a full revamp of the animation system planned, with some pretty awesome feature list, but I can't commit to a timescale or anything just say too much about it yet.

    The current animation editor is the way it is for some very important reasons, the main one being performance. Having a fixed timestep per animation clip, and having indexed frames means, to work out the current frame is really really simple and cheap. One of the requirements in our game was very fast animations, and this provides just that. It is also incredibly fast to set up animations, and the runtime performance is very simple and fast.

    An animation previewer is doable as is right now - we can certainly do that if there is demand? Our artists are perfectly happy having a test scene to test their animations.

    If more people need an advanced animation editor sooner, then we can probably justify moving it forward in the schedule, but as of now, it will be a while before this happens. If anyone else thinks this should be prioritized over other features, please feel free to post / pm / email.

    unikron
     
  47. unikronsoftware

    unikronsoftware

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

    This is totally doable. For starters, you will need to create an editor script for your behaviour. If you are switching all your sprites within the same editor, all you need to do in OnInspectorGUI() is -

    YourClass targetClass = (YourClass)target;
    tk2dSprite sprite = targetClass.GetComponent<tk2dSprite>();
    var spriteCollection = sprite.collection;
    targetClass.activeSprite = tk2dEditorUtility.SpriteSelectorPopup("Active Sprite", targetClass.activeSprite, spriteCollection);
    targetClass.inactiveSprite = tk2dEditorUtility.SpriteSelectorPopup("Inactive Sprite", targetClass.inactiveSprite , spriteCollection);

    If you need thumbnails, its slightly more involved, but not massively so - check tk2dSpriteEditor.cs (look for SpriteSelectorPopup in the code, all the relevant stuff is within that code block. Its not as bad as it looks.

    Hope that helps. If you need more details, perhaps we could modify the button sample to do this instead of using typed names?

    unikron

     
  48. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    I thought I remembered reading something about you creating a GUI solution for Unity. Are you doing this? If so, when do you think it might be available. I've looked around and am not really happy with what's out there.
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We were developing a GUI solution, but we kinda stopped when we heard about Unity 3.5 including a low-draw call GUI system. We did have some really nice ideas for it, and it was different to all the other offerings, but it didn't really seem worth developing further until we know what is coming in the new Unity.
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    New feature in version 1.51 (Now on the Asset Store) -
    Gradient Text Meshes and Inline Style Changes

    Walkthrough of creating a gradient text meshes and inline style changes on the wiki HERE

    Screenshot of new demo. 2 draw calls, 1 for all the text and one for the background.


    Feel free to ask if you have any further questions or suggestions.
     
unityunity