Search Unity

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
    Your raycast origin isn't inside the bounding volume is it? I've had it fail because of that.
     
  2. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    It's inside the first sprite's collider if that's what you mean.

    [edit] Aha! The second you mentioned this, some part of my brain remembered the "from inside a sphere" part in the docs... I feel dumb now, but at least it works. Time to get some sleep. :)

    Thanks for the tip!
     
    Last edited: Jun 3, 2012
  3. Sytto

    Sytto

    Joined:
    Jul 20, 2010
    Posts:
    28
    hello, i have a simple question, i'm creating a 2d game for phone, i plan to do big maps so i guess i must use static sprite batcher for reduce draw calls but my maps are loaded procedurally, is there a way to access to the "Commit" function of static sprite batcher through code? i didn't find any documentation, also, is this a good idea? my plan is to split map in pieces for avoid rendering so much tris and those pieces should be batched on runtime with static sprite batcher, is this possible? thank you and sorry for my bad english :p
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You don't have access to the "Commit" button, but you can construct the contents of your static sprite batcher using the batchedSprites array, and then once you've done that, call Build() when ready.
     
  5. sleekdigital

    sleekdigital

    Joined:
    May 31, 2012
    Posts:
    133
    I'm having some problems with creating slopes with the tilemap. It seems that the colliders of adjacent tiles are not getting merged in a smooth enough manner and that is causing some unwanted edges which my character gets hung up on. The character is using a rigid body and a capsule collider. I've also tried using a physics material with 0 friction.
     
  6. sleekdigital

    sleekdigital

    Joined:
    May 31, 2012
    Posts:
    133
    Here is a close up screenshot where you can see the strange merging of the colliders...

    $slopeCollider.jpg
     
  7. Sytto

    Sytto

    Joined:
    Jul 20, 2010
    Posts:
    28
    thank you :D
     
  8. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    183
    Anybody figures out how to fade sprite color to white? Like, flash a sprite?
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The current shader wont do thiss, but you could use this one instead. This basically makes the tint color additive (i.e. by default you'll see the sprite go white, set the color to black to make it the original color), but the alpha channel is still usable, so you can fade out your flashing sprite.

    Code (csharp):
    1.  
    2.  
    3. // unlit, vertex colour, alpha blended, additive overlay
    4. // cull off
    5.  
    6. Shader "tk2d/BlendAdditiveVertexColor"
    7. {
    8.     Properties
    9.     {
    10.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    11.     }
    12.  
    13.     SubShader
    14.     {
    15.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    16.         LOD 100
    17.        
    18.         ZWrite Off
    19.         Blend SrcAlpha OneMinusSrcAlpha
    20.         Cull Off
    21.  
    22.         BindChannels
    23.         {
    24.             Bind "Vertex", vertex
    25.             Bind "TexCoord", texcoord
    26.             Bind "Color", color
    27.         }
    28.  
    29.         Pass
    30.         {
    31.             Lighting Off
    32.             SetTexture [_MainTex] { combine texture + primary, texture * primary }
    33.         }
    34.     }
    35. }
    36.  
     
  10. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Is it possible to change an animation library to another animation library at run time?

    For example. I'm making a simple character selection feature where the characters are then displayed as portraits in the game. Each portrait has several poses as single frame animations in a single library. In my script I can then do:

    Code (csharp):
    1. potrait.Play("happy");
    Each animation set has the same four poses named the same things so no matter which character it uses the correct pose will be played. For the moment I've made do with changing them to static sprites and just making an array which holds all the available sprite collection data objects and then using

    Code (csharp):
    1. portrait.SwitchCollectionAndSprite(spriteCollectionData[collectionID], portrait.GetSpriteIdByName("happy"));
    but it's a tad messy.

    Is this my only option or is there a better/simpler means of going about something like this?

    Thanks.
     
    Last edited: Jun 8, 2012
  11. unikronsoftware

    unikronsoftware

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

    Yes it is possible to change the library. Set

    Code (csharp):
    1.  
    2. portrait.anim = newAnimationLib;
    3. portrait.Play("happy");
    4.  
    I know, anim is a really stupid member variable name and isn't descriptive at all.
     
  12. cjow

    cjow

    Joined:
    Feb 29, 2012
    Posts:
    132
    Aha. Thank you :) I did read the anim variable description but yea it didn't seem like the right thing at first glance :p
     
  13. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    183
    Awesome! Thanks, unikron! :)
     
  14. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    I have an AnimatedSprite that's playing on every wrap setting except Once, which is what I need. Any ideas?
     
  15. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    I figured it out. It played correctly once I lowered the framerate from 24 to 15.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thats strange - any idea why this is happening? is your game running at around 24fps? How many frames are there in the animation?
     
  17. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Hello,
    Before I commit to buy, I was wondering if sphere collisions where indeed supported and if the sphere size would scale with the sprite?
    Thanks!

    F.
     
  18. unikronsoftware

    unikronsoftware

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

    Sphere colliders aren't supported directly. You can create them on the sprite yourself should you desire, but they won't scale directly using the sprite.scale parameter. Its easy enough to add should you want to add the functionality yourself - the reason it isn't in there by default is mainly because the colliders are set up per frame of animation, and adding and removing components per frame will be quite expensive. The second reason is you can have non-uniform scales on the sprite, and the sphere collider is just a sphere and cant be scaled non-uniformly.

    If you understand the constraints and would like to implement it yourself in the system - its fairly striaghtforward - I'll be happy to post some pointers on how you'd go about setting it up.
     
  19. sp00ks222

    sp00ks222

    Joined:
    May 12, 2011
    Posts:
    37
    Hmm i think my textures are too big (larger than 4000x4000) its a game where you are in a car and speed through the environment. Should I split these textures in smaller amount? Or shold I just make the textures smaller and the car smaller? (though the car seems to lose detail when I do that) It's all vector based...
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Sorry, I'm confused - is this a different problem to the one you were mentioning before? The other one was about large mesh colliders, the texture size should have no bearing on that. 4000x4000 is a HUGE texture though. You could split it up into smaller chunks (eg. 1024x1024) to help if you're running into problems with large textures like that.
     
  21. mobilegamelabs

    mobilegamelabs

    Joined:
    Apr 11, 2012
    Posts:
    26
    I have made a new game Angry Polygon with Unity3D. In the game, I used Toolkit 2D to make all the texts. Toolkit 2D is very easy to use.

    #1 Top Download on App Store (iPhone/iPad/MacOS):
    iOS App Store - http://itunes.apple.com/app/angry-polygon/id536157715?mt=8
    Mac App Store - http://itunes.apple.com/app/angry-polygon-hd/id536799429?mt=12

    Google Play:
    http://play.google.com/store/apps/details?id=com.mggggg.ap
    http://play.google.com/store/apps/details?id=com.mggggg.ap.paid

    Related forums:
    http://forum.unity3d.com/threads/140230-ANGRY-POLYGON-My-First-Unity3D-Game!-D
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,388.0.html

    Official Site:
    http://www.mggggg.com/ap





    Dog:



     
    Last edited: Jul 17, 2012
  22. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Bought it! Trying now :)
    I'll let you know how I'm doing. Your prompt answer convinced me :)
     
  23. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We have a support forum (http://www.unikronsoftware.com/2dtoolkit/forum/) which you can use if you have any questions without getting lost in this thread, and also feel free to email support (support at unikronsoftware dot com)! We always try to answer as soon as possible.
     
  24. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    All right, so I have done some work on my project and I have it seems some issues with scaling.
    I have added a sphere collider, no problem there and disable the default collider (In editor). I find the td2ksprite component and change the scale parameter and I can see the sprite scale but I get warning messages saying:

    Destroying object immediately is not permitted during physics trigger and contact callbacks. You must use Destroy instead.
    UnityEngine.Object:DestroyImmediate(Object, Boolean)
    tk2dBaseSprite:EditMode__CreateCollider() (at Assets/Plugins/tk2d/Sprites/tk2dBaseSprite.cs:439)
    tk2dBaseSprite:set_scale(Vector3) (at Assets/Plugins/tk2d/Sprites/tk2dBaseSprite.cs:70)
    SBird:Feed(Single) (at Assets/Resources/SBird.js:22)
    UnityEngine.GameObject:SendMessage(String, Object)
    Physics Fun:OnCollisionStay(Collision) (at Assets/Physics Fun.js:41)

    I use a sendmessage to signal colliding object to grow.
    Any idea on how to avoid this?
    Thanks!
    f.
     
  25. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    Ok we're experiencing an issue where the asset file is not being created and the 2D Toolkit menu only gives "Setup for Javascript" as a possible option. I'm not experiencing it on my machine but my artist is seeing it on his end. We've tried reinstalling Unity and it is still happening. We are running Unity v3.5.1 and 2DTK v1.7 final + patch2.

    Thanks,
    Ian
     
  26. ivincent

    ivincent

    Joined:
    Jan 16, 2012
    Posts:
    16
    There were 8 frames with fps set t0 24. My guess is that the animation was playing just too fast to be able to notice.
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,
    That is quite strange. What have you set your collider type to in the sprite collection editor?
    On the sprite itself, is it a box collider or a custom sphere collider like you mentioned earlier in the post?

    One last thing to try - drop me an email (support at unikronsoftware dot com) and I'll send a patch your way, it could be a bug there. This bug only affects running in editor and not at runtime.

    p.s. If you can get back to me ASAP that would be brilliant, as I'd like to get this sorted whatever it is - planning a new release this weekend.
     
    Last edited: Jun 20, 2012
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Do you see any errors? This is likely to happen if some scripts (doesn't have to be tk2d specific) failed compilation.

    Also can you try importing into a blank project to rule out a corrupt download (if you haven't tried that already with reinstalling unity) Lastly, you can delete the downloaded asset store file (on windows its %APPDATA%\Unity\Asset Store) or simply get the latest one from our forum http://unikronsoftware.com/2dtoolkit/forum/
     
    Last edited: Jun 20, 2012
  29. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    I have just added a sphere collider and checked out the Box collider. I have not changed anything in the sprite collection editor. I'm just doing tests so I have used a standard example (Polygon colliders).
    The warning happens only if I change sprite scale in the OnCollisionStay function or on the function receiving the Sendmessage.
    If I change sprite scale in the update loop, I have no warnings.

    Fred.
     
  30. ChaseRLewis73003

    ChaseRLewis73003

    Joined:
    Apr 23, 2012
    Posts:
    85
    Well I'm enjoying using 2Dtoolkit for creating my levels and atlases. However, I'm trying to make a beat-em up style side scroller and to get the proper 3d effect I need to be able to adjust the Z-coordinate of sprites. In the environment their are several static 3d sprites with box colliders that I was hoping to statically batch together but it seems that when I do it makes them all have the same Z-coordinate. Any recommendations on statically batching them but keeping the sprites with differing Z-coordinates? Is there a reason I shouldn't do that if the sprites won't ever move?
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I think this might actually be a bug. That bit of code shouldn't be executing while the game is running. I'll get it fixed for the next version, but in the meantime, if you need a fix, please drop me an email (support at unikronsoftware dot com).
     
  32. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Thanks! It will be fine. I'll wait for the update to get that resolved and keep moving on in the meantime.

    f.
     
  33. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is slightly more complicated than it first seems. The static sprite batcher does retain z positions, and also sorts them correctly by z distance, but the problem you're seeing is probably to do with the fact that the whole batcher will be drawn in one draw call, and uses transparent shaders (by default). When this is done, and the next draw call is a sprite which happens to be between the front and back surfaces, it'll get drawn on top, as the previous draw call didn't write to the depth buffer (it can't as its transparent).

    A couple of ways you can deal with this...

    - Use solid shaders. If your sprites are predominantly solid and don't have feathered edges, etc, you can simply switch to the solid shader, and use the "custom geometry" function in 2D Toolkit to cut out the non-square edges of your sprites as opposed to using blended shaders.

    - Don't bother batching, and keep them as separate instances. You're obviously free to batch things from the same "plane" together.
     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its fixed in the current version now. I hope to release 1.75 final this weekend, and if I do, the fix will be in there.
     
  35. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Actually, it seems that even if my prefab has boxcollider off, every time I instance a new one (Or is it when I change the scale) it turns the boxcollider back on...
    Any idea?
    (It's when I change the scale...).
     
    Last edited: Jun 21, 2012
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In the sprite collection editor for that sprite, set collider type to unset and commit.
     
  37. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    853
    When using the sprite batcher, will it preserve the indiviual colliders' tags or will they all share one collider tag?
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It'll share one collider as of the current version (1.7 / 1.75)
     
  39. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    It worked! Thanks! GREAT SUPPORT ;)
     
  40. ryansworld10

    ryansworld10

    Joined:
    Jun 23, 2012
    Posts:
    1
    Could you possibly make a trial version of this?

    I am considering using it to develop a game, but I don't want to buy it just to find out I don't like working with it. If no trial, is there a return policy?
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't a trial at the moment, unfortunately. 2D Toolkit is distributed as full source, so making a trial would take a fair bit of time. A trial is indeed planned after 1.8 is released, so that might work out for you if you're willing to wait a bit.

    I'm not sure about the returns policy, as the product is sold through the asset store, you'd have to find out how you return things on there. I know it is possible, just now how you'd go about doing it.
     
  42. moproductions

    moproductions

    Joined:
    Sep 28, 2010
    Posts:
    88
    I'm curious about how to implement a tk2dTextMesh object with a unicode font, specifically Chinese. I've managed to get Chinese text up on the
    screen using a GUI Text object and their default Ariel font, but so far no luck with a tk2dTextMesh. The furthest I've gotten is creating what I think is
    a valid font, but whenever I input the Chinese unicode characters nothing shows up. I know the object is working because I can see normal English
    characters just fine.
    I've seen in an update that unicode is supported, but I can't find anything that shows me how to use it with tk2d. Can you point me to some resources or help to sort this out?

    Thanks
    -Mo
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    First things first - what version of 2D Toolkit and Unity are you using?
    Secondly, how are you generating the font?

    I can't remember specifically which version Unicode support was added, but this definitely works in the current version.
    The font was exported from GlyphDesigner, but it works equally as well in BMFont as well. In GlyphDesigner, the additional glyphs were just typed in, like any other Unicode text.
    Once the font is imported into 2D Toolkit, you can simply enter the same characters into the text box and see them appear in the viewport.

    I tested this just now with Kanji characters just to make sure everything is still working and it is. I don't see why it wouldn't work with Chinese or any other Unicode charsets.
     
  44. moproductions

    moproductions

    Joined:
    Sep 28, 2010
    Posts:
    88
    Hey there. Thanks for the quick response. I got the problem sorted out.
    The issue wasn't tk2d, it was the character sets I was using when creating the font. I'm using bmGlyph, which is a cheaper version of GlyphDesigner. I would add all the cjk character sets but nothing would show up. However, when I would start of with a blank character set and add the ones I needed I just flipped through the fonts until I found one where they all showed up.

    I think I was told once that you can't do custom character sets with bmGlyph and never tried making them myself but I was certainly wrong.
    It works out fantastic.
    thank you
     
  45. stuatk

    stuatk

    Joined:
    Nov 18, 2009
    Posts:
    53
    Am I right in thinking that using a sprite as part of a prefab is not handled correctly?

    The prefab:
    I have a root game object. this root contains 4 sprite game objects.

    I place an instance of this prefab in the scene.

    Then in the project view, I select the one of the sprite game objects (a child of the root prefab) and in the sprite drop down list I select a different sprite - surely the scene instances should reflect the changes made to this prefab - they don't. (changing an instance in the scene and 'applying' it doesn't work either).

    This is a major set back.

    I've also had lots of problems when deleting sprite collections - suddenly all the objects that have a reference to the deleted sprite collection throw exceptions... they don't seem to check that a sprite collection exists before trying to index into it...

    I was really happy with this tool until I moved from the prototype phase of my project into the level building... then during some tidying up I started to find these problems.

    So, have I made some mistake or are prefabs containing sprites pretty much useless at the minute?

    UPDATE: I have done more testing and prefabs seem to not update in the scene - if this is correct I really will be wanting my money back.
     
    Last edited: Jun 29, 2012
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This should work - Ill investigate this and get back to you as soon as possible. I need a bit more info - which version of unity and 2d toolkit are you using?
     
  47. stuatk

    stuatk

    Joined:
    Nov 18, 2009
    Posts:
    53
    Hi - thanks for quick response,

    I believe I'm using the latest version available - 1.75.

    Unity - 3.5.2f2
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks. Investigating now. I'll post back when I have a better idea of what's going on here.

    Edit: That was a quick one. I'll have a proper fix for it very shortly. PM me your email address, and I'll send you a copy of the patch once its ready, or grab it from our forum. (www.unikronsoftware.com/2dtoolkit/forum). I'll release a new update tonight/early tomorrow to address this and a couple other issues.

    Explanation of what is going on -
    The sprites only ever update when changed in the inspector, or through the properties to avoid constantly polling the sprite for changes. The values are being updated correctly, but the mesh attached to the instance isn't. You basically don't see any update until the mesh is updated, either by reloading the scene, or pressing play in Unity.

    I'm going to be adding some code in the inspector to detect when its operating on prefabs, and when it is, iterate through all instances of the prefab and force a mesh update. That should sort the problem out properly without sacrificing any performance.
     
    Last edited: Jun 29, 2012
  49. stuatk

    stuatk

    Joined:
    Nov 18, 2009
    Posts:
    53
    Great - you found the problem - thanks for responding so quickly, I'll download and try the new version tomorrow.
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I find it rather bizzare that no one has reported this before. With us using it, we never ran into this because we always Instantiated prefabs rather than having prefabs of objects which exist in the scene. Anyway, it is fixed now, though it is still possible to "break" it by doing some combinations of things.

    One example is having a prefab instance, overriding the spriteId on the instance, and then going into the prefab master and changing the sprite collection on that. That will need to be manually fixed up, but that is generally the case with overriden parameters anyway.