Search Unity

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

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

  1. lorenzo.cambiaghi

    lorenzo.cambiaghi

    Joined:
    Aug 16, 2011
    Posts:
    10
    Ok I resolved in this way:

    ..
    ..
    iTween.ValueTo(gameObject, iTween.Hash("from",1,"to",0,"time",3, "delay",0, "includeChildren",false,"easetype","easeInOutSine","onupdate","OnUpdateTween","oncomplete","RemoveMenu"));
    }


    void OnUpdateTween(float value)
    {
    ChangeAlphaColor(gameObject, value);
    }

    void ChangeAlphaColor(GameObject g,float value)
    {
    tk2dBaseSprite main=g.GetComponent<tk2dBaseSprite>();
    if(main)main.color=new Color(main.color.r,main.color.g,main.color.b,value);
    foreach(Transform child in g.transform)
    {
    ChangeAlphaColor(child.gameObject, value);
    }
    }
     
    Last edited: Nov 28, 2011
  2. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    The textures on 2dtoolkit sprites are not showing in the scene view. What am I doing wrong?
     
  3. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,012
    Okay, why does this keep happening to me:
    I have an atlas with a max tex size of 1024. if I add something and increase it to 1024x2048, the textures now look very low res in the game view- my editor quality is set to "fantastic" and full res. (decreasing the atlas size back to 1024 by removing some elements makes the textures look full res again)
     
    Last edited: Dec 1, 2011
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Can you check the max texture size on the actual atlas texture itself - sounds like that's set to 1024 for some reason, and your atlas is being downscaled to 512x1024.
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What have you done so far? Is this imported into an existing project or a brand new one? Do the scenes in the demo project work? Look forward to your response as I'd like to get to the bottom of this.
     
  6. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    Never mind. I had the wrong layers set up in the camera ... shouldn't be working that late at night ... :(
     
  7. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,012
    thanks Unikron!
     
  8. oliverdb

    oliverdb

    Joined:
    Jan 30, 2010
    Posts:
    165
    Our game has been released, thankyou for your help unicron and for the awsome framework.





    Link to itunes
     
  9. hyoga28

    hyoga28

    Joined:
    Dec 3, 2011
    Posts:
    1
    Hi,

    I'm part of a little grupo of indie developers. We're really interested in purchase your 2d Tool Kit for Unity, but we have two questions.

    In first case, It's compatible with Mac OS? We supose that is compatible but we prefere to be sure.

    Second, and more important, Can we use this in three diferent computers? Our team is composed by two more persons and we live in diferent cities, and we all want to have this asset in our computers to develop togheter in same conditions.

    Thank you! We really love your 2D Tool Kit! It's awesome!
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Congratulations on getting your game out! Tried it and it's pretty awesome indeed.
    Glad 2d toolkit helped.

     
  11. wintermute

    wintermute

    Joined:
    Jul 30, 2011
    Posts:
    22
    Hi! First of all awesome toolkit :)

    I have a few questions :
    In the animations, is there any other way of loading a custom sequence of frames aside from manually selecting them? Like say 1 2 3 4 3 2 3 4 5?
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, there isn't right now, but it is straightforward to add that as a feature. Let me know if you would like some pointers in how to do this.
     
  13. wintermute

    wintermute

    Joined:
    Jul 30, 2011
    Posts:
    22
    Yes please.
     
  14. Windfeld

    Windfeld

    Joined:
    Oct 17, 2009
    Posts:
    5
    Hey Unikron! The system looks very nice indeed!

    I have a question:
    Do you support per frame timing [when animating sprites]? As far as I can tell from the videos it doesn't seem like it, but wanted to ask in case you might be planning to put it in :D Ofc, users can hack it by adding the same sprite after each other, but that is just lame :D

    Thanks and keep up the good work!
     
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    Hi,

    No there isn't support for frame timing yet, this will be in a later release when we update the animation system. I (and my artists) prefer adding the same sprite multiple times (the way they think is 11123334555, if that makes any sense), but you're not the only one who has asked for this, so we will be addressing it when updating the animation system.

    Cheers,
    unikron

    Cheers,
    unikron
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Here is a bit of code which will do this for you - you can use this to customise your own version. It requires a sprite to be in the list to start with, but you can obviously expand it as necessary.

    You will need to place this in tk2dSpriteAnimationEditor.cs, just before #region DrawFrames. You will also need to create a string member variable called frameList.

    Code (csharp):
    1.  
    2. frameList = EditorGUILayout.TextField("Frame List", frameList);
    3. if (GUILayout.Button("Add List")  clip.frames.Length > 0)
    4. {
    5.     var spriteCollection = clip.frames[0].spriteCollection;
    6.     string[] frames = frameList.Split(new char[] { ',' });
    7.                
    8.     clip.frames = new tk2dSpriteAnimationFrame[frames.Length];
    9.     for (int i = 0; i < frames.Length; ++i)
    10.     {
    11.         int frame = System.Convert.ToInt32(frames[i]);
    12.         clip.frames[i] = new tk2dSpriteAnimationFrame();
    13.         clip.frames[i].spriteCollection = spriteCollection;
    14.         clip.frames[i].spriteId = frame;
    15.     }
    16.  
    17.     Repaint();
    18. }
    19.  
    This is very rough code, and doesn't do any error/sanity checks, but it does work.

    Hope this helped,
    unikron
     
  17. wintermute

    wintermute

    Joined:
    Jul 30, 2011
    Posts:
    22

    Thanks a lot. I'll let you know when I apply it.
     
  18. chillypacman

    chillypacman

    Joined:
    Oct 1, 2011
    Posts:
    71
    Hi There,

    I've been using this package for a while and I'm really loving it.

    Recently I started work on a game with a perspective camera but still wanted to use 2D sprites.I think there might be a bug in tk2DSprite though because I'm finding that sprites which are closer to the camera can sometimes draw behind sprites which are further away.

    In this demo: http://www.jabberworx.net/cellgame/cellgame.html you can see a character sprite with a red face. If you press the down and right arrow on your keyboard when the game loads up and run it you'll notice the players face will disappear after it reaches a certain point.

    The player face is a child of the body and its z position is offset by -0.05f of the body, I've checked and have found in terms of z coordinates it's always in front of the body, yet it still disappears behind the body.

    Any ideas why this is happening and how I could fix it? I'd like to keep rendering in perspective view though, I know orthographic rendering would probably fix this.

    I know for sure it doesn't have anything to do with rotations or billboarding since the sprites do neither and in fact the issue is also (and has always) been present in the editor for me.

    Any ideas what might be causing it?
     
  19. robinouu

    robinouu

    Joined:
    Apr 18, 2011
    Posts:
    3
    Hi,

    I have bough the 2d toolkit last week, great extension ! :)
    What about a tilemap editor ?

    So, there is my problem :
    I want to open and rebuild compressed sprites in the tk2dStaticSpriteBatcher dynamically (by script), I understand that tk2dStaticSpriteBatcherEditor manage it, but I can't activate the right method...

    Is it really possible ?

    Thanks for your attention,
    robinouu
     
  20. Murdokiler

    Murdokiler

    Joined:
    Feb 22, 2011
    Posts:
    8
    Hi, I have a problem when I create an instance of a Sprite prefab with box collider, this box collider is reset to 0, and Z center is -10000.

    As I can solve it??

    Thanks, and sorry my english.
     
  21. unikronsoftware

    unikronsoftware

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

    A tilemap editor will be coming in the next major update. It was meant to be released early this month, but we have been held up fixing various other things - we will probably release a maintenence update with all the current fixes, before releasing the next major update which will have the tilemap editor.

    To open and rebuild the sprites in tk2dstaticspritebatcher, its slightly tricky, as the code to do this is all within the editor class (to avoid runtime bloat). Your best bet is to simply copy this block of code - basically its all the code in GUILayout.Button("Edit") GUILayout.Button("Commit"). "Edit" expands the mesh into gameObjects, and "Commit" merges everything again. You should avoid doing this at runtime though, as it will be quite expensive merging the meshes, and memory allocations do occur.

    Cheers,
    unikron

     
  22. unikronsoftware

    unikronsoftware

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

    The only time this should happen, is when you add a box collider as an animated mesh, and some of the frames have a box collider and some dont. When a frame doesn't have a collider attached, it will be pushed off far into the distance to avoid colliding with other objects. Make sure all your frames have box colliders, if this is what you intend. If this is still broken, send me a zipped project where this happens, and I will investigate and fix this for you.

    Cheers,
    unikron
     
  23. unikronsoftware

    unikronsoftware

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

    This is caused by perspective projection and one of the projected z values being closer than the other. You can fix this (it will break batching on these 2 objects, however) by creating a second material for the eyes (perhaps do it as a second sprite collection) and increase the renderQueue on this material so it always draws after the rest of the materials.

    Let me know if this doesn't help, there is another way to solve it (and not break batching), but it is a bit more involved.

    Cheers,
    unikron
     
  24. RecursiveFrog

    RecursiveFrog

    Joined:
    Mar 7, 2011
    Posts:
    191
    Am I the only one who is noticing issues with tk2d and its polygon colliders? I find that the polygon collders work fine when intersecting a boxcollider, but the have issues with meshcolliders that are created from a StaticSpriteBatcher as well as other instances of the same polygon collider.

    As an example, make a polygon collider shaped like an arrow ( -> ) Try putting this object in your scene. Make a few of them and let them try to collide with each other. The results aren't what you'd hope for. Also, try dropping one onto a StaticSpriteBatcher shaped as a flat floor.

    ______________ (like that, but with good formatting)
    |_____________|

    If you're like me you'll find that the arrows don't collide with each other or the meshcollider. they simply fall through on their way to oblivion.


    Is there a workaround for this besides not using polygon colliders on rigidbody objects that need to react to gravity and collide with other mesh colliders?
     
  25. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    check if the generated mesh colliders are convex. if not they aren't allowed to move at all as mesh colliders. (you can move them but collision resolution will have more cases of 'wrong' than 'right')
    if they are convex ensure you don't move them too fast.
    If the arrow is really an arrow then you will need to work with multiple colliders on it (then it would be a matter of 2d kit generating appropriate meshes) so you either have primitive ones or multiple convex mesh colliders


    these are limitations in physx and the unity implementations, not related to the kit or any code you can write on C# / UnityScript / Boo at all.
     
  26. spk

    spk

    Joined:
    Jan 9, 2009
    Posts:
    532
    Hi,

    I started using your package to implement my own 2D GUI system and I was wondering if there's an easy way/API method to fit a sprite to fill an arbitrary screen-space rectangle? I'm quite new to this package, and have only dug a little bit into the code but so far I've mostly seen methods to adjust the sprite's scale so it's pixel perfect. Do I have to do this myself by adjusting the sprite's scale based on its spriteDefinition.boundsData (as stored in the collection) and the GUI camera orthoSize?
     
    Last edited: Dec 13, 2011
  27. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    305
    Does anyone know how this compares to SM2? If I already purchased SM2, is this worth getting?
     
  28. Murdokiler

    Murdokiler

    Joined:
    Feb 22, 2011
    Posts:
    8

    If I use "Is Trigger", i don´t have the problem. It's a temporary solution.
     
    Last edited: Jan 9, 2012
  29. woko

    woko

    Joined:
    Oct 11, 2011
    Posts:
    23
    To everyone having the z = -100000 collider problem, it happened to me too, and after some debugging i found out that it happens when you have more than one texture with the same name in one collection. Hope it fixes the problem for you too.
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The reason this is happening, is that you are trying to create your own collider, while the setting in the SpriteCollection for the particular sprite is "None".

    When an object already has a box collider and the sprite is set to "None" collision, 2d toolkit will set its bounds to 0,0,0 and origin z to -100000. This is primarily for animation, for instance, if 5 frames of animation have a collider and 3 dont.

    2 ways to solve this -

    1. if you need to mange the collider yourself, set it to "Unset" in the sprite collection. This means, the sprite will not try to manage the collider, and you can do what you wish with it.

    2. Set it to BoxTrimmed in the Sprite collection. You won't need to manage the collider any more at this point, and it will automatically fit the visible part of the texture.

    Hope this helps.

    Cheers,
    unikron
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The easiest way to do this for now, is to use the bounds, orthoSize and target resolution. Not ideal, I know. I will add some helper functions to calculate this and some additional stuff for the next release.

    Cheers,
    unikron

    p.s. finger gestures is awesome :)
     
  32. Murdokiler

    Murdokiler

    Joined:
    Feb 22, 2011
    Posts:
    8
    Thanks ,I have been able to solve it!
    I made a new scene, and set it to Unset and it worked.

    Thank you very much unikron, your plugin is very useful for me.

    Cheers,
    Murdokiler
     
  33. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Just purchased this and I'm having great fun learning! I've got an issue, I'm not sure if it's unity's issue or 2d toolkits. I've created a floor (which is working fine), then I've created a crate from the demo image and added a rigidbody and everything and it falls and collides with the floor just fine, however it takes ages to fall. Is there a global gravity setting which needs to be changed to make it fall quicker?
     
  34. unikronsoftware

    unikronsoftware

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

    You could try adjusting gravity - its in Edit > Project Settings > Physics. It sounds like your global scale is probably a bit too big. This isn't really a problem though, you could simply adjust physics to compensate.

    Cheers,
    unikron
     
  35. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    the odd thing is that I imported 2dTK with the demos and all the demos are fine, but I made a scene and added some of my own sprites and the gravity was too low, so I changed the grlobal gravity settings and it worked fine, but now the demos fall really quick now.
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Sounds like its the ortho size. What is it set to in your sprite collection? If its a perspective camera things get a bit more complicated as objects have to be bigger further away into the distance. Basically the bigger the object is ( though it may look the same size on screen, check the scale field) the slower it will fall as the space underneath it will be similarly scaled.
     
  37. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Here's a gallery with screenshots of my settings for the camera, object and collection. If these are incorrect what should the correct values be?
     
  38. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Obviously I didn't attach the album! Here is it - http://imgur.com/a/Dd9rz
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It's the orthographic camera size. Setting it to 50 means its 100 units from the top. The default gravity is -10 or so, which implies its a 100 m drop from the top to the bottom of the screen. Try reducing the ortho size to 5 and everything will drop a lot quicker!
     
  40. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Ah right. That indeed fix the problem. Thank you.

    I have another question. I have an animation where all the frames are 100 x 40, however one frame is 99 x 40.

    Ive added the box collider to all the frames and scripted it to animate when I move this is animating fine. However, I've added a rigidbody so that it works with unity's physics engine, when my animation hits the frame that is that 1px smaller my object goes flying. I've PM'd you a link to my project, hopefully you can shed some light on it.
     
  41. brdma-

    brdma-

    Joined:
    Dec 19, 2011
    Posts:
    4
    Need a bit of help here. I'm using 2D Toolkit, and at this stage of my project I'm just playing around and learning. I've searched a bit but couldn't find any resolution.

    The issue I am having is that my 2D sprites are rendering differently based upon where they are on the screen. I'm using an Orthographic camera with a size of 300, and a screen resolution of 800x600. The texture I'm using is 64px by 64px and it is a green square with a 1px gray border. My Sprite object is scaled to 320x/320y. When I Build&Run, and measure the objects in Photoshop after taking a screenshot, they are both 64px by 64px, but one of them is missing 2 sides of the 1px border.

    Any thoughts?

    Here is a screenshot:
    http://img835.imageshack.us/img835/3417/ggscreenshot.jpg
     
  42. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    Hi,

    I'm trying to change the color of a sprite during runtime through script with the following code:

    Code (csharp):
    1.  
    2. // Get the sprite component
    3. tk2dSprite sprite = go.GetComponent<tk2dSprite>();
    4.  
    5. // Change the color    
    6. sprite.color = new Color(128, 128, 128, 128);
    7.  
    However, it's not updating the color. My goal is to shade the sprite so that it looks disabled; is there another approach to take?

    BTW the following code does work to change to scale.
    sprite.scale = new Vector3 ( 0, 0, 0 );

    It's only the color that doesn't change.

    Thanks!
     
    Last edited: Dec 19, 2011
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, the color should definitely work - how have you got this set up?
     
  44. unikronsoftware

    unikronsoftware

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

    This is caused by sub pixel coordinates - you could try making sure your sprites are always on pixel boundaries. (y+0.5)/height * ortho size.
    let me know if it still happens after you've tried this.

    Cheers,
    Unikron
     
  45. Gooms9

    Gooms9

    Joined:
    Dec 17, 2011
    Posts:
    31
    This!! Please! As soon as a tile map editor comes out, my team will be buying copies! The plugin looks wicked, just needs proper tile map support. Any ideas when this will be available?
     
  46. brdma-

    brdma-

    Joined:
    Dec 19, 2011
    Posts:
    4
    Unikron, it worked, thanks. Ironically, the name of the company I will be publishing my games under is called Subpixel.

    Thanks again.
     
  47. soofaloofa

    soofaloofa

    Joined:
    Nov 18, 2011
    Posts:
    26
    My fault, I was trying to pass in integer RGBA values between 1 and 255 instead of floats between 0 and 1. It's working correctly.
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    LOL. Whats the chances of that?
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad to hear it works for you now.
     
  50. unikronsoftware

    unikronsoftware

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

    There are a couple of problems with your sprite - walk left frame 15 doesn't have a collider, when it plays that frame, your character will simply drop through the world, and with walk right, only frame 0 has any collider information at all.

    In addition to that, you should really set your anchor points to the base of his feet, as if the anchor point is in his body, and one frame was taller than others, he is likely to get pushed under the ground. Usually this results in the box getting pushed out with a lot of force.

    Cheers,
    unikron
     
unityunity