Search Unity

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

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

  1. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    When does the next version come out? Also, what if I have hundreds of different animation sequences? Can 2dtoolkit handle it? And is there a way to organize that many animations/atlases/images?
     
  2. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hey unikron, I purchased the plug-in and I just wanted to say how freaking awesome it is. Excellent job, blows other 2D solutions out of the water, IMO..
     
  3. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I have a really strange and frustrating problem. I added a new animation clip to my main character's sprite animation, but for some reason when I play that new clip in my Animated Sprite, the offset is wayyyyy off. Any idea why this might be? The source textures are the exact same dimensions as all the other animation clips, and I don't have any issues with the other ones.

    EDIT: It seems that adding any new clip to an existing Sprite Animation will result in the animation being completely offset.
     
    Last edited: Jan 9, 2012
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,
    I have certainly not seen this before - could you send me a repro case, as I don't seem to be able to reproduce this. If possible, send it to support at unikronsoftware dot com. Otherwise, simply drop me an email on there and I'll send you a list of things to try and troubleshoot this issue.

    Cheers,
    Unikron
     
  5. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi,

    Unikron I finally managed to build sprites at runtime. It was pretty straight forward. Just one thing, I build the sprite this way, do you see anything wrong here (for example that it could break batching, etc...)?

    Code (csharp):
    1.  
    2. tk2dSprite spr= go.AddComponent<tk2dSprite>();
    3. spr.SwitchCollectionAndSprite(_sprCollection.spriteCollection,0);
    4. spr.spriteId=spr.GetSpriteIdByName(sd.name);
    5. spr.pixelPerfect=true;
    6. spr.Build();
    7.  
    Thanks in advance.
     
  6. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Sorry for the dumb question, is this good also for making optimized 1. draw call particle sys as well?
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    One small problem - you should store the link to the sprite collection data rather than the collection itself, as storing the collection will include all the source textures in your runtime, uncompressed, which you certainly don't want. That's why I suggested creating a prefab from the collection you want then intabtiating that, as there will be no chance of accidentally linking to the wrong thing then.

    Apart from that it's fine though.

    Cheers,
    Unikron


     
  8. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, there isn't a particle system yet, but you can build one fairly easily with the provided data.

    Cheers,
    unikron
     
  9. namoricoo

    namoricoo

    Joined:
    Apr 14, 2011
    Posts:
    534
    Any plans on Extending 2D toolkit to learn a couple NGUI tricks. That would put some more money in your pocket. The only thing the NGUI did is copy a lot of UIToolkit features.
     
    Last edited: Jan 10, 2012
  10. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Thanks for the observation, but, I have a prefab for the SpriteCollection. In my window editor what I'm doing is dragging the sprite collection I want, then it shows the atlas this collection has gerated (just extract it from the material) and instantiate sprites. The window is the one containing the reference to the collection, but this will not be active when playing. Did I say something odd? :S

    Thanks.
     
  11. unikronsoftware

    unikronsoftware

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

    I'm not sure I understand what you have done so far. What you need is a prefab to a sprite from the sprite collection. Simply create a sprite, set the sprite collection to the one you're interested in, and drag it to the project window to create that. You can then instantiate it using Instantiate, then GetComponent<tk2dSprite> and change the spriteId on that. Hope that describes it better... if it doesnt, drop me an email / PM and I can send you a sample scene or something.

    Cheers,
    unikron
     
  12. unikronsoftware

    unikronsoftware

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

    Our longer term plan with GUI is to provide a bunch of basic controls for GUI. However, I do know of one person who is working on a full 2d toolkit based GUI system, and it looks great so far.

    Cheers,
    unikron
     
  13. trikker

    trikker

    Joined:
    Jan 10, 2012
    Posts:
    1
    Hey, I imported a sprite sheet into a sprite collection and am now setting up the colliders. If I use the trimmed box it works fine, but when I set up a custom box the collider is offset above the character 0.375 units. Don't know why this is happening.

    Also, just to clarify we need to manually set up a collider for each frame of the animation correct?
     
  14. unikronsoftware

    unikronsoftware

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

    If you need to create a custom box collider, you will have to manually create it for every frame for now. If you need a temporary workaround for this, its easy enough to do - I can point you to the relevant bits of code.

    With regards to the issue you're having with the sprite collection, could you email me at support at unikronsoftware.com; I have an updated version which fixes this issue, but I'm not sure if I've got all cases - need to either test it or give you a fixed version to test.

    unikron
     
  15. namoricoo

    namoricoo

    Joined:
    Apr 14, 2011
    Posts:
    534
    Thank you for your response. I do enjoy your product. I think I will wait for the Next UI Unity is working on. I have developed a UI agnostic front end. with so many different options I wanted something that easily lets me transition between tools. At the moment I can transition between UIToolkit and Regular Unity GUI in under 10 seconds. If the New Unity system does not live up to my expectations I'll go from there.
     
  16. Mark-Davis

    Mark-Davis

    Joined:
    Jun 21, 2011
    Posts:
    156
    Just bought this package yesterday and am quite happy with it so far. Just in case it helps someone... I didn't see a built-in method to position sprites at specific pixel coordinates where 0,0 is the upper left corner of the screen, so cooked up this quick and dirty method:

    Code (csharp):
    1. void PositionSprite(tk2dSprite sprite, float x, float y)
    2. {
    3.     float pixelScale = (1f / (float)Screen.height) * 2f;
    4.     sprite.transform.position = new Vector3(x * pixelScale - ((float)Screen.width / (float)Screen.height), 2f - y * pixelScale, 0f);
    5. }
    Note: This assumes you're using an orthographic camera with a size of 1.
     
  17. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Hello, this sounds like you kind of put 2DToolkit upgrades onto a hold, or am I wrong ?
    (basic GUI feats being put on a long term)
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    Hi,

    Thanks for that. I have added a similar helper function which works for generic camera set-ups. This will be in the next version.

    Cheers,
    Unikron
     
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, that's not what it means at all. We are currently trying to get the current version into beta for release sometime this month. This version has a few smaller GUI updates, sliced sprites, an upgraded button class, tile map editor, and some other features we aren't announcing yet in the event that it can't be done in time.

    The following versions will have more updates to help with GUI construction. By longer term I meant 2-3 versions on.
     
  20. xcube

    xcube

    Joined:
    Nov 27, 2011
    Posts:
    45
    Hi all.
    What about if you want a universal application under iPone and iPad?



    What you need to specify the parameter Target Height?
    Is there a way out of this situation?
    Thanks!
     
  21. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Ok, sorry for the misunderstanding :)
    Good luck !
    (and at least you're able to expose an ETA about GUI features availability, unlike Unity :p )
     
  22. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    I'm trying to figure out what rebuild index does in the top menu? What I want to be able to do is switch sprites that are in a sprite animation easily by keeping their file name the same, but changing what is actually in the file. Is there an easy way to do this without getting the "Missing Texture" in the sprite collection?
     
  23. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    How can I attach an Animated Sprite via code when runtime starts?
     
    Last edited: Jan 12, 2012
  24. protayne

    protayne

    Joined:
    Jan 12, 2012
    Posts:
    1
    Hello thanks for this
     
  25. unikronsoftware

    unikronsoftware

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

    One way to do this, is to pick one resolution (eg. iPhone) and go with it for everything - make sure it works properly with your resolution. When switching to iPad, simply modify the camera ortho size to compensate, and everything should work as expected. For example, if you follow the above example in landscape, and your initial sprites are set up for 960x640, the conversion ortho size conversion should be

    newOrthoSize = oldOrthoSize * 768.0 / 640.0 = 1.2 * oldOrhoSize

    Hope that helps,
    unikron

     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Rebuild index rebuilds the .tk2d index file - it is currently broken in the released version due to an embarassing find and replace mistake. You can achieve the same thing by simply deleting .tk2d in the project root.

    I'm not sure what you mean by "siwtching sprites" that are in a sprite animation - do you want to replace a sprite with something else already in the sprite collection, or do you mean something else completely? Can you send me more details on how your are ending up with the "Missing Texture"? The support email (support at unikronsoftware.com) would be best.

    unikron
     
  27. drgsus2

    drgsus2

    Joined:
    Mar 8, 2011
    Posts:
    54
    Hey guys,

    I have a question.

    I looked through the complete wiki section of the 2D Toolkit website and I can't find a proper Scripting Reference. In the Asset Store, one of the customers said there is a poor API.
    Is it really true, that the scripting basically reduces to very basic methods, like play, pause or color?

    Is it possible to, for example, mirror an animated sprite in runtime (for walking in the other direction i.e), or get exact information, which animation is currently playing, if it is playing, on what frame it currently is or have a method, that is similiar to SM2s "DoAnim" (which basically plays the animation, but doesnt reset it, if the animation is already playing) and stuff like that. And if it is, where do I get these methods? The example code, was very simple to say the least.

    I hope I really just oversaw the scripting reference. Because the rest of the sprite handling, is just top notch. :)
     
    Last edited: Jan 13, 2012
  28. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    I highly recommend 2dToolKit. The support is great from the community and it really is easy to script as well. I've never had to wait more than a day to get an answer to any question. If you want to mirror an animated sprite, just flip it's x scale. There are function callbacks as well, to see if the animation is complete. You can loop, loopsection, play once on animated sprites. You can't go wrong with this plugin.
     
  29. duni

    duni

    Joined:
    Jan 15, 2012
    Posts:
    2
    hi, i bought 2d toolkit and im doing some test for my new game, however im a bit lost, when i set up a polygon collider the sprites collide with normal objects ( like a cube etc ) but they never collide with themselves, however if i check the convex option and commit, they collide, and in the inspector, when the scene is playing, if i disable the convex option they keep colliding with themselves (this is what i want but without having convex and then disabling it) , whats wrong? i wanna polygon colliders without the convex option, it seems to work only if i check convex option and then i disable it when the scene is playing, i hope i explained right, my english isn't so good.
     
  30. DerDree

    DerDree

    Joined:
    Jan 16, 2012
    Posts:
    6
    Hi,

    Bought 2d Toolkit yesterday and I am very happy with it so far. But now I have a small question:
    I have a script which fills a sprite batcher with sprites as child and now I want to batch these sprites. So is it possible to batch sprites during runtime and if yes how can I do this?

    Thanks in advance.
     
  31. Helmut Duregger

    Helmut Duregger

    Joined:
    Mar 17, 2010
    Posts:
    18
    The toolkit is quite useful but please look into the following two issues

    1. The text mesh centering does not work correctly if kerning is enabled. Usually the text is narrower with it enabled than if it is disabled. This causes the text to be slightly off-center towards the left when set to centered.
    2. A function in text mesh that returns the width of a string would be useful. This would allow us to automatically layout messages at runtime or enlarge encapsulating boxes.
      Currently there seems to be no way of computing the width. There is a char width value somewhere, but it radically overestimates the average char width. Not sure if a workaround using the mesh size and regenerating the mesh several times would work or be performant, as I did not try that yet.
     
  32. ssfulfer

    ssfulfer

    Joined:
    Jan 26, 2011
    Posts:
    6
    Hi Duni,

    In unity, 2 mesh colliders can only collide if at least one of them is marked convex. Look up mesh colliders in the manual for more info.

    - Steven
     
  33. pavlito

    pavlito

    Joined:
    Nov 27, 2007
    Posts:
    136
    1. Is static sprite batcher intended for large numbers of static sprites, or can it be used for a single element (like a platform created with left end, middle, right end) and then duplicated across the scene. I am asking this, because we have platforms created with 3 (or more) sprites, each with it's own collider. When these colliders touch eachother and our player lands on the spot where they touch, it wont jump as high as we want it to). Creating a batch fixes this problem, so I figured we go with batchers.

    2. "Cleaning up leaked objects in scene since no game object, component or manager is referencing them Mesh has been leaked 12 times." message appears every time I save the scene with commited batchers. The number of leaked meshes is different most of the time. Is this normal?

    3. Can I make a prefab out of a batcher and instance them with code?
     
  34. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Does anyone know why when I add a BoxTrimmed collider to a sprite, the colliders work as expected, but when I add a BoxCustom the collider seems to be way off? That is, the collider looks like it should be accurate, but objects collide with it well below what it should be.
     
  35. pavlito

    pavlito

    Joined:
    Nov 27, 2007
    Posts:
    136
    @Helios, i came across this issue when using BoxCustom on objects within a static sprite batcher. My player drops INSIDE the collider and wont go out. I just used polygon colliders in a shape of a box (which is more or less the same). Hope this helps.
     
  36. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    @pavlito, thanks that seemed to do the trick for now. You're right, it acts funny when in the sprite batcher. Once I take it out it is fine. I'm just using polygon colliders for now.
     
  37. duni

    duni

    Joined:
    Jan 15, 2012
    Posts:
    2
    wow, never knew that, I'm not familiar with physics, thanks for clear my doubt, changing the subject, I recommend everyone buy 2d toolkit, really worth it and makes it much easier to make 2d games, I'm very happy with it and its very powerful
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its on the TODO now. May or may not make it into the next release - we are currently considering releasing all the accumulated fixes so far before the tilemap release, if thats the case, then this will be in.
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks ssfulfer for answering that!

    @duni, glad you like it!
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Can you send me a unitypackage showing this problem? This is probably different to the other ones which have been reported. Please use support at unikronsoftware dot com.

    Cheers,
    unikron
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. Static sprite batcher is meant for a large number of static sprites, which end up being merged to one object. You can duplicate them and instance as you like; prefabs should work too.

    2. This is because of a bug when switching between editable and non-editable meshes. We fixed a few with the latest version, but not caught all of em yet; we don't consider it a critical bug as it only happens in the editor, and never in game. You can safely ignore them for now, but if the number grows too high, simply save and reload the scene - it should reset when a scene is loaded.

    3. Yes.
     
  42. halgorithm

    halgorithm

    Joined:
    Oct 27, 2010
    Posts:
    22
    Tilemaps support is going to be added? Awesome! I was really hoping for this.
    Would you guys be willing to give an estimate on a release date for the new version? It looks like the latest release is a few months old so I'm guessing that this will probably be a rather hefty update.
     
    Last edited: Jan 17, 2012
  43. halgorithm

    halgorithm

    Joined:
    Oct 27, 2010
    Posts:
    22
    Oh, and I actually had another general question that I wanted to ask...

    Does anybody know how to apply interesting visual effects/shaders to a single 2D Toolkit sprite (programmatically, NOT baked into the sprite)? For example, if you wanted to add a colored glowing outline around a sprite at runtime, or a scrolling colored alpha mask on top of a sprite, or to invert the colors of the sprite... that sort of thing. It sounds problematic for sprites that are batched together with others the same texture atlas, but I was curious if anybody knew a good way to handle this sort of thing.
     
  44. Helmut Duregger

    Helmut Duregger

    Joined:
    Mar 17, 2010
    Posts:
    18
    Awesome, looking forward to it. Thank you for the fast response.
     
  45. whalec

    whalec

    Joined:
    Jan 17, 2012
    Posts:
    1
    I have a number of sprites on the screen that I'd like the user to be able to interact with, tap, drag around etc etc.

    However I don't appear to receive any touch events in the Update function on tk2dsprite objects. Are you able to point me in the direction of how to receive such events. I think it has something to do with these not being a GameObject, but being a noob to Unity I'm not quite sure how to resolve that.

    Even something as trivial as this doesn't work when attached to a tk2dsprite:
    using UnityEngine;
    using System.Collections;

    public class Touching : MonoBehaviour {
    void Update () {
    foreach (Touch input in Input.touches) {
    Debug.Log(input);
    }
    }
    }

    Doesn't log anything to screen. From reading the Unity docs, the Input.touches should also proxy the mouse clicks through to it, so I thought it should work, even when not on the device.

    I know it's something simple and fundamental I'm missing, any tips of how to resolve it and make sprites interactive with touch would be most appreciated.
     
  46. markpollard1

    markpollard1

    Joined:
    Apr 1, 2010
    Posts:
    70
    HI,

    I have a animation sprite and i want to swop the Anim Lib using code is this posible?

    Thanks
     
  47. flashfoxter

    flashfoxter

    Joined:
    Jul 12, 2011
    Posts:
    6
    I added box collider to sprite and is works perfect, but if i add box collider to animated sprite, box collider z goes to -10000(after run game) ? How i can fix it ?

    I read this: "You can simply add a Box collider to the sprite in the sprite collection editor - everything should then work as expected".

    But its not helps me !
     
    Last edited: Jan 17, 2012
  48. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I think you're supposed to add the collider to each sprite of the animation in the Collection.
     
  49. flashfoxter

    flashfoxter

    Joined:
    Jul 12, 2011
    Posts:
    6
    Its added automatically to all sprites in collection....
     
    Last edited: Jan 17, 2012
  50. vstudios

    vstudios

    Joined:
    Aug 24, 2011
    Posts:
    19
    Hi, Does the Toolkit come with a demo level ?