Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

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

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

  1. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. what version did you update from?
    2. Are you running in some emulation mode in Unity?
    3. Have you tried restarting Unity?
     
  2. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    Never mind! I have figured it out.
     
    Last edited: Jun 29, 2013
  3. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,217
    Hi,

    I seem to be having clipping issues. I have a parallax scrolling effect, but when the camera scrolls some of the 2nd and 3rd layer objects, the objects behind the main layers and front layers, are being clipped to the front laying over the layers closest to the camera. How can I fix this? Is there some type of setting or script?

    I'm using your textmesh system, how do I edit text by script and can it be edited using JS? (I'm using it for my score system) If so, could you provide me with an example?

    Also, is there a way to minimize the draw call amount? Your scenes have only a couple draw calls, where mine seem to have 1 draw call per textured object.
     
    Last edited: Jun 30, 2013
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    1. How are you doing parallax scrolling? The solution to this depends entirely on how you're doing this.

    2. http://unikronsoftware.com/2dtoolkit/doc/2.00/tutorial/scripting_a_text_mesh.html

    3. Again, this depends on what you're doing. Draw calls depend on how many sprites you have, and whether you're using the unity transform.localScale (you shouldn't, use sprite.scale instead), etc. Impossible to tell specifically without seeing what you're doing.
     
  5. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Hi,

    I'm using 2dToolkit in a 3d game to animate for example computer screens.
    My issue appears once I created the animated sprite. I try to place it in front of a desk according to the desk location and rotation angle.
    I rotate the animated sprite trying to position it correctly but unity's gismos don't work correctly.

    I've been looking for 1 hour already and haven't found anything about it so I'm asking here to save me some time and frustration.
    What can I do to avoid this issue and rotate/translate my sprites like I do for other objects in the editor?

    Thanks
     
  6. Metabble

    Metabble

    Joined:
    Mar 29, 2013
    Posts:
    114
    I'm not sure if I understand exactly what you want, but if you want to access the normal movement and rotation handles available to other objects, you can use keyboard shortcuts. Clicking a sprite and tapping W brings up movement handles, while E brings up the rotation gimbals. Alternatively, you can click the icons in the upper left corner of the window. That's usually how one would rotate and translate other objects in the editor. :/
     
  7. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    285
    The issue is that the controls for the sprite and the draggable sprite plane will take precedence over Unity's gizmo, so it can be hard to move and rotate in the viewport sometimes. In the 2D Toolkit/Preferences menu there are two options where you can turn this off, "Enable Sprite Controls" and "Drag Sprite to Move".
     
  8. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There is an option in 2D Toolkit > Preferences to disable the gizmos if you don't like them.
     
  9. Metabble

    Metabble

    Joined:
    Mar 29, 2013
    Posts:
    114
    Ah, that makes sense. I never noticed that 2DTK's gizmos took precedence. Thanks from me, too, then. :)
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The ideal solution is to detect the Unity gizmo positions, but I don't think thats possible without some terrible hacks...
     
  11. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Great thanks guys this worked.

    Now I have another issue with perhaps also a quick fix?
    For some reason my animation sprites in my scene don't play anymore.
    The last things I did was to add additional frames to my collections, create a new clip , add the sprite animator in the scene and duplicate it once.

    Here's a screenshot of our game, world exclusive preview so this stays between us ;). The screens are animated by 2dtoolkit :).
    The problem occurred when I added one of the screens there and duplicated it to place it on another control center in my scene. The animation plays correctly in the inspector preview if I select a screen in play mode.
    $Screens.jpg
     
    Last edited: Jul 1, 2013
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. Check that the sprite animation is still correct and the clip is correct.
    2. Make sure the sprite animator is pointing to the correct clip, switch to another clip and swtich back just to make sure.
    3. Any errors in the console when you press play?
    4. Thats a cool screenshot :)
     
  13. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Thanks for your help Unikron

    1. The sprite animation seems correct as the animation is played in the inspector when I play the game and select a screen.
    2. I switched both the clop the anim lib and other collections to no avail; animation just stays on one frame.
    3. No errors
    4. Thanks :D

    I also rebuild the index just in case and successfully checked the integrity but it didn't help
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Is "Play automatically" ticked? how do you get it to play?
     
  15. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Yeah play automatically is ticked.
    I used to see it played with just that, they are mainly level decoration so they loop all the time as soon as the map is loaded.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I think I've found the issue. There is a serialized tk2dBaseSprite object that shouldn't be serialized. Works fine in most cases, but duplicating will copy the references as well which will mean the animator will be animating the sprite it was originally linked to. in tk2dSpriteAnimator.cs, change
    [SerializeField] protected tk2dBaseSprite _sprite = null;
    to
    protected tk2dBaseSprite _sprite = null;
    And you should be good to go.
    Let me know if you run into any issues.
     
  17. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Just tried it but it didn't work.
    Also acording to your theory if I understand it right the other sprite should be animated no? In my case nothing is animated, not the original one, neither the other ones I didn't touch.
     
    Last edited: Jul 1, 2013
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Can you drop me an email at support at unikronsoftware.com, please?
     
  19. Azuri

    Azuri

    Joined:
    Jul 23, 2012
    Posts:
    5
    This might be a very basic question, but i can't find an answer to it.
    How can I create a textmesh via script while the game is running?
     
    Last edited: Jul 1, 2013
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You need a tk2dFontData reference.

    Code (csharp):
    1. public tk2dFontData fontData; // drag the font you want to use here, or get it using Resources.Load.
    2.  
    3. GameObject go = new GameObject("text");
    4. tk2dTextMesh tm = go.AddComponent<tk2dTextMesh>();
    5. tm.font = fontData;
    6. tm.text = "Hello";
    7. tm.Commit();
    That should be it.
    Alternatively you can create a prefab, and then Instantiate it, fi you don't want to care about fontData and stuff like that.
     
  21. Azuri

    Azuri

    Joined:
    Jul 23, 2012
    Posts:
    5
    ok thanks :)
     
  22. bigzer

    bigzer

    Joined:
    May 31, 2011
    Posts:
    160
    Alright, I will do that tomorrow when I got more time.

    Thx for your support
     
  23. G_Koko

    G_Koko

    Joined:
    Aug 25, 2012
    Posts:
    30
    Hi, I update from the 2D Toolkit Version 1.76 final + patch 1. It's important to say that when I updated I was unable to use the 2D Toolkit because Unity could't load the scripts (perhaps the links were broken) so I intall the 2D Toolkit on a new Unity project and I replace the TK2DROOT Folder from the new Unity project to my current Unity project using Finder. After this I open my current Unity project and I had to assign shaders to all the Tk2d materials (at this point ALL the sprites were rendering in pink on the Unity Scene window) but on the Inspector Window and SpriteAnimation Editor the images are rendering on pink... Hope we can fix this :)
     
  24. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    I'm sure this is super simple but I can't get it to work. How do you flip, or mirror a sprite on the x axis? Its just for basic movement. I need the character to face to correct direction he is moving in. I can't get FlipX to work.
     
  25. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    285
    FlipX works here. yourSprite.FlipX = true;
     
  26. Ben-BearFish

    Ben-BearFish

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

    We noticed a lot of Unity Asset Store sales going on this summer, and were wondering if you were going to participate in any of the summer sales soon with 2DToolkit? Thanks.
     
  27. unikronsoftware

    unikronsoftware

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

    We'd like to be in the summer sales, but we don't know if it'll happen, and even if it does, I'm sure we won't get more than a days notice :) Sorry I can't be more specific, but thats as much as I know now.
     
  28. Rabbit2G

    Rabbit2G

    Joined:
    Apr 14, 2013
    Posts:
    10
    Aha! yourSprite being whatever the name of my sprite is, or do I use the name of the animation that is playing?
     
  29. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yoursprite is a reference to the sprite. In your script:

    public tk2dSprite yourSprite; // drag the reference to the sprite here

    and later on...
    yourSprite.FlipX = true;
     
  30. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,729
    Quick (possibly stupid already answered question) but it's possible to place 2DToolkit sprites anywhere in the scene or use them within a 3D world, right? with any rotation? thanks :)
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    They are just meshes on gameobjects, so you can place them anywhere you like and do whatever you like to them.
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  33. soldmeadow

    soldmeadow

    Joined:
    Jun 23, 2011
    Posts:
    42
    Last edited: Jul 8, 2013
  34. Ben-BearFish

    Ben-BearFish

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

    We're using a tk2dCamera in our scene, which works fine with the 2D sprites.

    When I tried to add the tk2dUIManager and a BasicButton which uses the tk2dCamera for the UI Camera, the button does not detect input. I have the button on the correct layer and everything. My question is do we have to have a separate camera for the UI, or is there something else possibly going wrong?
     
  35. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    53
    @ Update: When making the space between the letters from the image transparent it seems to workin'on out there. Don't no why that is, because the images produced by BMfont ain;t no transparent.

    Hello, I'm using 2dtoolkit 2.0 + hotfix 2. Now I made a font with the program BMfont and afterwards I made the letters thicker with photoshop. This was done by making an inner stroke to the letters, but only the old sized letters keep showing up in the textmesh. Wwhatever I do, if I give the letters a different inner stroke color or give an inner color instead of transparent color to all the letters, nothing shows up, only the size of letters from the original image. Offcourse I attach the targa file to the font and click commit. Also when making a whole new font it is always the same, I really don;t get this :confused::confused:

    Do you maybe know if I'm doing something wrong?

    Thanks
     
    Last edited: Jul 10, 2013
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Quite likely the button collision box isn't correctly resized for the camera. Select the button and then click on the "Automatic Fit" button in the UIItem script. That should fix it.

    Also, if you're only using tk2dCamera purely for anchors / scaling (which most people seem to be doing) - the 2.1 beta tk2dCamera lets you configure it to work with any camera size, i.e. you could use ortho size 1 and it'll just work.
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The images from BMFont should have an alpha channel if set up as described in the tutorial here. http://unikronsoftware.com/2dtoolkit/doc/2.00/tutorial/preparing_a_font.html

    Check the format in Photoshop, it should not be greyscale.
     
  38. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    53
    Ok thanks for the tips :)
     
  39. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,197
    Thanks Unikron that seemed to be the issue.

    I was wondering memory-wise, do you recommend having all the UI as persistent between scenes, and just hide and unhide them as we need them, or is it better to only load UI per scene? I'm asking this with regard to 2D Toolkit, as I'm not sure how it handles texture memory? Thank you.
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It really depends on how your game is set up. If you don't have ridiculous amounts of UI specific data, then just hiding them will be fine. The textures are loaded as they are in any other asset in Unity living in the scene - it is loaded and resident even if you don't use it. But if your overhead was low, that shouldn't really mater.
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  42. BaronGalf

    BaronGalf

    Joined:
    Aug 15, 2012
    Posts:
    8
    Tilemap is still beta ?
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Tilemap will leave beta as of 2.1 final when that is realeased.
    Its far more polished than before.

    Some features still classed as beta, though, as they've not been battle tested sufficiently. Eg. isometric tilemaps.
     
  44. Ben-BearFish

    Ben-BearFish

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

    I was wondering is there a way to enable/disable input for a specific/individual tk2dUIItem? I tried removing all the events, but the buttons still animate when someone clicks/touchs the button.
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Setting tk2dUIItem.enabled = false on the item will disable it.
     
  46. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    248
    Will listening to UI events work in UnityScript as in the following?
    Code (csharp):
    1. function OnEnable() {
    2.     uiItem.OnDown += ButtonDown;
    3. }
    Also, my game supports splitscreen with an arbitrary number of cameras (players). What would 2DTK's workflow be for assigning a UI (HUD) copy to each player? Wasting a layer per supported player (likely over half the number of available layers/tags in total) would not be ideal. Menus with interaction don't need to be copied; just the HUD. Would it be a simple matter of creating and instantiating an ortho camera prefab with the UI tree as a child (and a script on the camera which would update the UI based on an assigned playerCharacter var) and setting the instantiated camera's rect to the player's camera rect? Would I still need to also set the camera's layer culling? If you've managed to create a UI system that doesn't require a culling mask per HUD, it would certainly be worth my cash for that alone.


    Edit: I see from the most recent UI beta thread that focusing isn't supported yet, so consider the following little more than a suggested implementation which you've likely already considered.


    Finally, does the UI system support selecting/highlighting a button via non-pointer input? That is to say, it should be possible to navigate a menu using a keyboard or gamepad in addition to a mouse, highlighting the current selection until the player moves to the next (by pressing down, for example) or until the player hovers over another control with their mouse. This is similar to VB.NET's Control.Focus() method and GotFocus(). Seamless transitions between using a gamepad and mouse are an absolute requirement to me. After trying the demo, I'm assuming this isn't built into the system. I'm sure it would be rather easy to implement this myself, but I do suggest adding a separate OnFocus() handler and including a single selection mode which automatically unfocuses controls when another control gains focus. It would be great even if we were required to manually implement focusing on hover by calling a Focus() function OnHover(). The important part is the OnFocus event, which should also come with an audio slot like the other events.
     
    Last edited: Jul 17, 2013
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    1. OnDown += ButtonDown works like that from Unityscript. I ported one of the built in controls to UnityScript, available here for reference: http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1835.0.html

    2. Splitscreen - its up to you. It doesn't NEED a culling mask per HUD, but we use that to mask raycasts. You can create 1 final camera and have all the UI there, or have the same UI visible from 2 different cameras with 2 different rects. Or you could just construct a HUD scene, with all the HUDs visible from one camera.
    Input is handled using a singleton manager class though - which could be an issue for you if you need to handle input for each split independently. HUD tends to be read only so you can just set it up using sprites, etc, no need to even deal with the UI stuff if you don't need it.

    3. No it doesn't cope with focus yet, but its a widely requested feature so it is probably going to get implemented at some point. (https://trello.com/b/UfqlXqXy/2d-toolkit-roadmap)
     
  48. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    248
    Thanks for the info. The UI bits aren't quite there yet, but they're promising. Nice use of Trello.
     
  49. Stilghar

    Stilghar

    Joined:
    Feb 4, 2013
    Posts:
    81
    Hi Unikron,

    Is there any example on how to use 2Dtk to create a parallax scrolling effect? Is it complex with 2Dtk?

    Cheers,

    Stilghar
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    If you're a registered user, you should be able to access this page.
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,87.0.html
    There is a parallax camera sample there. Its fairly easy to set up and get going with. It doesn't use perspective cameras, which is nice in some cases.
     
unityunity