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

    Yeah looks like it, unfortunately. Looks like they haven't implemented any of the texture filtering settings yet (probably because you have to do it from within the shader in stage3d, as opposed to setting it to a texture sampler directly), but this is supported in stage3d as far as I can see.

    If you need it working now, I suggest using keelys shader below. Any problems, let me know and I'll investigate further.

    Cheers,
    unikron
     
  2. NoBloodyHero

    NoBloodyHero

    Joined:
    Apr 29, 2009
    Posts:
    54
    Shader worked great. Thanks everyone!
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can work around this by commenting out the contents of tk2dEditorUtility.UnloadUnusedAssets. I will have to find a more 3.5 compatible solution to the function, but probably about time, that function was hacky enough to start with.

    Please let me know if this fixes it, as I don't get that error, my version has considerably changed compared to the public one.

    Cheers,
    unikron
     
    Last edited: Jan 2, 2012
  4. ssfulfer

    ssfulfer

    Joined:
    Jan 26, 2011
    Posts:
    6
    Any idea when we will see that version : )

    Also, will the next version include the tile map editor?

    - Steven
     
  5. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi,

    This plugin seems really nice. Just one question, how are collisions managed? Are you using unity colliders/physics? I ask because for example in lower iphones this had a big impact in my 2d games.

    Thanks in advance.
     
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its getting there slowly but surely, so I wouldn't expect too much longer now. If I were to guess, I'd say before the end of the month, but please don't hold me to it!

    The next major version will include the tilemap editor. There may or may not be any interim releases, depending on whether there are any other critical issues which need solving immediately.
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We are simply using Unity colliders physics. We haven't had any issues with physics being a bottleneck so far, even on iPhone 3G. What kind of physics did you have?
     
  8. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi unikron,

    I'm building a little fast paced platform game. I need slopes and a good control over player to achieve good playability. My target are ipod touch 2G onward.

    From my tests (I did them 1 year ago more or less) I was a bit dissapointed. With just 10 entities on screen using unity physics (I was using just them mainly for collision detection) my game was pretty laggy and I had around 5 drawcalls. Don't know if it could be me though.

    I mainly would like to hear from people with experience with this kind of games in unity and confirmation that what I try can be done at a decente frame rate.

    Thanks for your time.
     
  9. undream

    undream

    Joined:
    Dec 24, 2011
    Posts:
    27
    Here is a weird bug I've found. Working with unity3.5 with the latest version of Toolkit2D, I'm not sure if this is a bug of unity or TK2D.

    I have animated my objects outside Unity, in my 3D package (Cinema4D). Imported them as FBX objects, and applied "tk2d sprite" to appropriate layers. In this case, everything works as it should.

    BUT, when I change the "sprite color" of those animated bits, things start to go weird, which makes it impossible to complete my game...

    Here you can see a video in real time. Sorry for the poor recording quality.

    http://dl.dropbox.com/u/3488525/20120104_1800_58.avi

    Urgently waiting for solutions and/or answers. Thank you very much.
     
  10. unikronsoftware

    unikronsoftware

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

    This is indeed very weird and not expected behaviour. Could you send me an email at support at unikronsoftware dot com, and we'll take it from there.

    Cheers,
    unikron

     
  11. undream

    undream

    Joined:
    Dec 24, 2011
    Posts:
    27
    Ok, I've sent an email through the support forum on the website.
    Cheers.
     
  12. unikronsoftware

    unikronsoftware

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

    One of our games had loads of colliders (30+) (though a bulk of them were sphere colliders), and we used that for tap detection, and turned on rigidbodies with a drag script as well. We had no issues on iPhone 3G, though with a large number of objects, we had to cap the framerate at 30fps as opposed to 60fps on the faster models.

    unikron
     
  13. rocket5tim

    rocket5tim

    Joined:
    May 19, 2009
    Posts:
    242
    I'm building a game for the Unity in a Flash contest and I'm getting the error at the end of this post when debugging the game build in Firefox. I'm using Unity 3.5, exporting to Flash and using the latest version of 2D Toolkit from the Asset store (I've even deleted the plugin from my project and pulled from the store again).

    I have a TextMesh in my scene that gets updated when the player collects an object. Here's the code:

    Code (csharp):
    1.     public void UpdateScore(int score)
    2.     {
    3.         totalScore += score;
    4.         txtScoreValue.text = totalScore.ToString();
    5.         txtScoreValue.Commit();
    6.     }
    This all works perfectly fine in the following 2 cases:
    1. In the editor (either playing the scene directly or loading it from the main menu)
    2. In the Flash build (firefox chrome) *if* I only export the game scene and play it directly.

    In the browser, if I load my game scene from the game's main menu, then the following error occurs each time the UpdateScore() function is called. So it seems that something isn't connecting properly when a scene is loaded from another vs. loading directly when the game initially launches. Any help on this would be appreciated, I'm up against a bit of a deadline.

     
  14. unikronsoftware

    unikronsoftware

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

    A few things to check -

    1. Is the score textmesh actually drawing correctly before you call update? From the callstack, it looks like perhaps the object hasn't initialised correctly.

    2. Spam a few Debug.Logs in tk2dTextMesh.Commit() - my guess is it takes the second path in there, but hasn't actually initialised everything correctly.

    One thing to try quickly -

    Create a prefab of your object, then instantiate it in game over the object in the scene effectively replacing it (and disable the one in the scene, etc).

    Hope that helps,
    unikron


     
  15. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi again,

    Unikron would you be so kind to answer some more litle questions?

    1) I have read that you for perfect resolution you advice to use an ortographic camera with ortographic size of 1 and the height of the screen we target. Is there any possibility to set sprites with pixel coordinates? Or at least in world units but configuring the camera to 1 pixel == 1 unit world. This is because I'm used to move things on screen for 2D games in pixels. If I set an sprite at 240,160 in a non retina display I want it to be placed in the middel of screen.

    2) Is it possible to use a camera size bigger than 1.

    3) Is it possible to create sprites at runtime based on an atlas? I ask because I want to create a little editor for my levels where the user could double click a "image" inside an atlas and create the sprite in the scene for fast prototyping of level creation.

    Thanks for such a great product :).
     
    Last edited: Jan 5, 2012
  16. okimoki

    okimoki

    Joined:
    May 13, 2010
    Posts:
    116
    basics (maybe covered somewhere in this thread allready..)..
    in JS, i try to do:

    var textMesh : tk2dTextMesh;

    and i get:
    Assets/_SCRIPTS/Global.js(4,16): BCE0018: The name 'tk2dTextMesh' does not denote a valid type ('not found').

    How do i change the text on the text mesh in the Update function in JS properly? There is only a C# version and i cant translate that :)

    Thanks!!
     
  17. mizardo

    mizardo

    Joined:
    Jan 5, 2012
    Posts:
    5
    Hi unikron, thanks for the 2dtoolkit you made great work.

    In our company we re working in a platform game with perspective camera for android / iphone and i found this same problem with z fighting. I set the renderqueues for each material fixing the problem, but i fear about the batching and performance loss. Could you post the second method without breaking the batching?

    Another problem is with the vertex snapping, for some reason when i snap a sprite with another i'm getting some space between them, you can see this in the attachment marked in red.

    Also in the next version would be nice to see two new animation wrap modes:
    Random 1 frame: when you instantiate a sprite and play this animation, select a random frame from the frames of the animation. I implemented in our project something like this for random tiles.
    Random Loop: when you play the animation, starts at random frame and play the whole loop from that frame.
     

    Attached Files:

  18. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    How can I create sprite animations that are layered? i.e. one layer of animations for the mouth, one layer of animations for the eyes, etc? Any help would be appreciated! Thanks
     
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. We have a new solution for this in the next version, so perhaps you might want to test this. The new solution lets you use screen coordinates for everything, but its not 100% complete. Send me an email at support at unikronsoftware.com and I'll send you this script if you would like to test it. It works, btw, just needs a few more bits and bobs implemented before it can be released.

    2. Yes, just set it up to whatever size you like, and if you want automatically created 1:1 sprites, set the same ortho size in the sprite collection too.

    3. Yes. The easiest way to do this is to create a prefab for the sprite collection (doesn't matter which sprite you pick for this). After you instantiate it you simply call sprite.spriteId = sprite.GetSpriteIdByName("..."); to change the sprite.

    Cheers,
    unikron
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You simply create individual animated sprites, and attach them to a parent object. That way when you move the parent, the child moves too. You can simply animate them using the Unity built in animation editor. Check the spider sample - same concept, except you use animated sprites instead of regular ones.

    Cheers,
    unikron
     
  21. unikronsoftware

    unikronsoftware

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

    You need to move a few files into a different folder to work with JS. The files are listed in this FAQ page:
    http://www.unikronsoftware.com/2dtoolkit/wiki/pmwiki.php/Main/JavaScript

    What you're doing is pretty much correct - apart from the files not being in the right place.

    Cheers,
    unikron
     
  22. unikronsoftware

    unikronsoftware

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

    Renderqueues are definitely the best option for now, as are much easier to control than any other option. We tried the other more seamless option, and the CPU overhead was quite high, and not worth it with a large number of sprites. It was only a win with 5-10 sprites, whereas having renderqueues gave far superior results with higher counts.

    This vertex snapping error you are getting is likely one of two things.
    1. There is a very tiny z difference in one of the components so Unity doesn't complain about not being to compute an inertia tensor. If you pick this vertex and try to snap to another one there will be a tiny z difference. You can check if this is happening by looking at the z layer value.
    2. You don't have pixel perfect point sampled turned on, and the edge is filtering across the last texel. The default padding is black, so try setting it to Extend in the sprite collection editor.

    Feedback taken with the animation wrap modes, those will be in the next version. About random loop, say, you have 1, 2, 3, 4, 5. and the random picked frame is 4. Should it loop back to 3 or, stop at 5?

    Cheers,
    unikron
     
  23. Rob4507

    Rob4507

    Joined:
    Aug 29, 2007
    Posts:
    53
    Yeah, I found this bug too.

    For some reason, a LoadLevel upsets the mesh vertices generation for the text and it gets out sync.

    The way I got around it was to delete the contents of my scene first, and then use LoadLevelAdditive instead. Not pretty but it seems to work.

    -Rob.


     
  24. Rob4507

    Rob4507

    Joined:
    Aug 29, 2007
    Posts:
    53
    Hi Unikron,

    Not sure if this feature has been suggested or already possible, but it would be great to be able to change a sprites texture coordinates and size so that you can do things like a health meter which needs to expand and shrink. I know you can do it with using the scale but that gives a squashed look rather than a nice truncation of the pixels.

    Cheers,

    -Rob.
     
  25. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    How do I make the layers stay in position? Sometimes it seems that the eyes and mouth randomly are hidden behind the layer for the body.
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Offset in z slightly from the base mesh. Are you using a perspective camera?
     
  27. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi!,

    It is not possible for me to test your not final version. I would really like but we are in a rush project and need to stick to waht we know work ok. Sorry for the inconvenience, and thanks a lot for your answers.

    Keep 2Toolkiting :D
     
  28. mizardo

    mizardo

    Joined:
    Jan 5, 2012
    Posts:
    5
    Thanks for your help.

    for the animation loop if the random picked is 4 then should it loop 4, 5,1,2,3,4,5,1,2,3,...., this is useful for desynchronized animations like a group of birds spawned at the same time.
     
  29. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    No, I'm using an ortho camera.
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Simply offsetting the z of the eyes, etc so it displays in front of the body should do the trick then.
     
  31. Loud

    Loud

    Joined:
    Jun 5, 2009
    Posts:
    88
    Hi Unikron,

    I'm seeing the same behavior as shown in the video uploaded by undream. I'm getting it on my text meshes. Whenever I have a color with a reddish tint it shows up as blue.

    *time passes as I do some more testing before posting*

    Ok, so get this. The color goes blue only when I modify the color of an existing TextMesh (It's a button that changes on hover) and the scale of that TextMesh is anything but Vector3(1, 1, 1)

    If I scale the button transform to (1.1, 1, 1) I get blue. If I change it back to (1, 1, 1) I get orange (the correct color).
     
    Last edited: Jan 6, 2012
  32. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
  33. unikronsoftware

    unikronsoftware

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

    This is a bug in Unity, the vertex color is affected on any mesh (red blue channels are swapped) when scale is modified. I have tested this on other standalone meshes (independednt to 2d toolkit, and even fbx imported meshes) and this bug exists there too.

    You can work around this by setting textMesh.scale or sprite.scale instead of transform.localScale. You should be using this anyway, as it will not break batching unlike transform.localScale. Try to keep transform.localScale to 1.

    If you are using the built in unity animation system, you could use a script like the one attached to fix the issue temporarily.

    Cheers,
    unikron


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. public class ScaleFixUp : MonoBehaviour {
    4.    
    5.     tk2dSprite sprite;
    6.     Vector3 startScale;
    7.     Transform _transform;
    8.    
    9.     // Use this for initialization
    10.     void Awake () {
    11.         _transform = transform;
    12.         sprite = GetComponent<tk2dSprite>();
    13.         startScale = sprite.scale;
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void LateUpdate () {
    18.         Vector3 localScale = _transform.localScale;
    19.         sprite.scale = new Vector3(startScale.x * localScale.x, startScale.y * localScale.y, startScale.z * localScale.z);
    20.         _transform.localScale = Vector3.one;
    21.     }
    22. }
    23.  
     
  34. Loud

    Loud

    Joined:
    Jun 5, 2009
    Posts:
    88
    All good to know! Thanks!
     
  35. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi again,

    One more question about the creation of sprites at runtime. I want from the editor show to the level designer the atlas t2toolkit generated from a sprite colection. As he moves the mouse over the different sprites (that are baked into the atlas) draw a rectangle around it as the selected one that will be created on the scene if he double clicks it. I have coded all the editor funtionality as this is what I used for a previous game, but the information about sprite rects where extracted from a xml I wrote my self. Is there any possibility to extract the diferent atlas sprites rects from the sprite collection in order to know what sprite is the user hovering over?

    Thanks in advance.
     
  36. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    This has been driving me crazy last few days. I'm glad someone found a pattern when it occurs. I already submitted a bug report and I'm sure you have done it too earlier. Btw the colors don't flip in Flash build.
     
  37. Kaspar-Daugaard

    Kaspar-Daugaard

    Unity Technologies

    Joined:
    Jan 3, 2011
    Posts:
    150
    I'm fixing this, and adding a test so we don't break it again. Thanks for investigating.
     
  38. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    Is it ok for me to place the TK2DROOT directory inside my PLUGINS directory?
     
  39. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    If I use 'tk2dAnimatedSprite' in a class inside Standard Assets, I get this error:
    How can I use 'tk2dAnimatedSprite' in Standard Assets folder?
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hopefully it'll be fixed in the next build, since Kaspar is looking at it below. Not many things we can do to work around it for now. My script to rebuild geometry when scale changes is not particularly efficient, but perhaps it could work for your stuff too?
     
  41. unikronsoftware

    unikronsoftware

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

    In order to use 2d toolkit with JS you should follow these steps rather than move the entire folder into Standard Assets, etc.:
    http://www.unikronsoftware.com/2dtoolkit/wiki/pmwiki.php/Main/JavaScript

    After that, you can grab the sprite, etc by doing
    var sprite : tk2dSprite = GetComponent(tk2dSprite);

    The code after that is very similar to the C# code. I built a JS example a while back - I've been trying to dig it up but I'm not sure where it has gone, looks like every trace of it has vanished, including from source control, which is very odd indeed. I'll post it on the wiki if I find it, otherwise I will have to write a new one.

    Cheers,
    unikron
     
  42. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, you can get the information about sprites in a sprite collection by getting a pointer to the tk2dSpriteCollectionData class. You can obtain this from sprite.collection.

    The information you want is in the tk2dSpriteCollectionData.spriteDefinitions array, simply iterate through it and grab the uvs array in each. You canget more information, like names, etc. from there too.

    Cheers,
    unikron
     
  43. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    This worked great! Thanks @unikron
     
  44. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Thanks a lot unikron, as you state in your site top notch support.
     
  45. camham

    camham

    Joined:
    Nov 8, 2011
    Posts:
    13
    I can't get the HitCompleteDelegate() to work in javascript either. Unikron, do you have any examples of that?
     
  46. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Hi again,

    Unikron, sorry for the offtopic question about 2D programming on unity. Do you use the Unity built-in character controller for entities in the game? For example for the player, or did you roll your own controller? It is a bit hard to get good results with the Character controller don't you think?. To put you in context, I'm talking about 2D platform games for example.
     
  47. unikronsoftware

    unikronsoftware

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

    In all the games we've done, we simply roll our own character controller - the built in one is geared more towards a 3d character, and is far more complex than the ones we have done.

    Cheers,
    unikron
     
  48. unikronsoftware

    unikronsoftware

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

    The syntax for HitCompleteDelegate in JS is simply:

    function HitCompleteDelegate(sprite, clipId)
    {
    if (walking)
    {
    anim.Play("walk");
    }
    else
    {
    anim.Play("idle");
    }
    }

    I've added a one click JS set up option for the next version, it'll be much easier to move stuff to the right locations then.

    unikron
     
  49. hexdump

    hexdump

    Joined:
    Dec 29, 2008
    Posts:
    443
    Thanks for the info. DId you just used some ray cast?
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, thats what we used for most cases - in some we knew exactly where the ground was, so didn't need a raycast for that.