Search Unity

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

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

  1. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    I think I get this.
    When you say the scale of the root object needs to be something like 1,1,1.001 this will change as I scale it up, right? Does this matter for the amount of draw calls? Or are you talking about the scale of the sprite in the sprite library?

    f.
     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I mean the scale in the Unity inspector, under transform. If you scale it up that is fine, as long as x y z aren't the same values.
     
  3. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Ok thanks! It works by the way!
     
  4. G_Koko

    G_Koko

    Joined:
    Aug 25, 2012
    Posts:
    30
    Hi Unikron, is there a way that can i know in wich frame the animation are when i running the game?

    Thanks
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, but do you really want the frame number or the time of the currently playing clip? Eg. if you want to sync two clips, then you want the latter - one animation frame could span more than one game frame.

    http://unikronsoftware.com/2dtoolki...sprite.html#ad910233369b4b3558ffa7fe645358410 <- that gives you the current clip time in seconds

    And this gives you the current frame.
    int frame = (int)(anim.ClipTimeSeconds * anim.CurrentClip.fps);
     
  6. covcomm

    covcomm

    Joined:
    Feb 18, 2012
    Posts:
    9
    Hi,

    I just bought 2D Toolkit and I'm trying to get some multitouch buttons set up. I keep getting this error when I try to add a script:


    "Assets/Standard Assets/Scripts/Button Scripts/JumpButton.cs(17,28): error CS0246: The type or namespace name `tk2dButton' could not be found. Are you missing a using directive or an assembly reference?"

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class JumpButton : MonoBehaviour {
    5.  
    6.     tk2dButton button;
    7.    
    8.     // Use this for initialization
    9.     void Start () {
    10.         button = GetComponent<tk2dButton>();
    11.         button.ButtonPressedEvent += ButtonPressed;
    12.         button.ButtonAutoFireEvent += ButtonAutoFire;
    13.         button.ButtonDownEvent += ButtonDown;
    14.         button.ButtonUpEvent += ButtonUp;
    15.     }
    16.    
    17.     void ButtonPressed(tk2dButton source)
    18.     {
    19.         Debug.Log("Pressed");
    20.     }
    21.    
    22.     void ButtonAutoFire(tk2dButton source)
    23.     {
    24.         Debug.Log("Autofire");
    25.     }
    26.    
    27.     void ButtonDown(tk2dButton source)
    28.     {
    29.         Debug.Log("Down");
    30.     }
    31.    
    32.     void ButtonUp(tk2dButton source)
    33.     {
    34.         Debug.Log("Up");
    35.     }
    36.    
    37.     // Update is called once per frame
    38.     void Update () {
    39.    
    40.     }
    41. }
    Is there a simple way to get rid of this error?
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  8. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    Thought id let ya know why i was prying so deep into your code

     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That's brilliant :) I hope you're making an awesome game with this tech.
     
  10. MaaS

    MaaS

    Joined:
    Mar 9, 2010
    Posts:
    51
    Hi!...

    I'm contemplating 2D solutions for a game i'm going to develop... and your asset looks like the best, although I miss a few features here and there. The main one should be, for frame based animation, a time property for each frame... so you can stay at a frame the time you want without having to duplicate the frame...

    ie. normal_idle_animation:
    frame 1 idle - 100000ms
    frame 2 blink01 - 25 ms
    frame 3 blink02 - 25 ms
    loop

    I would have asked something more like the ex2d timeline animation tool but I understand that it is quite harder :p

    I'm also looking for intregration with Spriter from brashmonkey (http://www.brashmonkey.com/)... Did you know anything about them? I hope it can be used by the time we start production :)

    But I came here just to ask for a bit more info about the tilemaps pipeline. The docs about them are a bit short so I cant see if I will be able to use them in my game... so please please see if you can extend a bit more on it (or record a video showing it's use). The same goes for multiresolution... :)

    Thank you very much and keep your hard work...
     
  11. unikronsoftware

    unikronsoftware

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

    You can set time per frame (the docs arent updated to show it, but you can "group" frames, and select how many ms / frames it should stay on a particular frame of animation). Pretty much how you've written it down there.

    The animation editor will be getting a bit of love in 1.90, so that will change to be a lot nicer then.

    I'm not sure about spriter integration - I know some people were working on it, but I haven't heard back from them in a long time. I don't know if its still in development.

    I'm setting up an evaluation version - drop me an email at support@unikronsoftware.com and I'll sort you out with some form of an evaluation when its ready.
     
  12. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    i have game that screen size is 1024x768. i use tk2d camera. afaik in unity one unit means 1 m. so my screen is 1024m x 768m for physics engine. i have a ball in this scene. to move this ball i have to add force like 3000 what is so high. what is the way to use coordinates around meters? for example my ball diameter is 60 px so it behaves like 60m. i want to see it like 0.3m.
     
  13. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @atmuc

    You can do a few things here. Personally I have no problem with adjusting global physics scale - in that case, you just rescale all physics units and forget about it.

    First and probably easiest is to just use an ortho camera - you aren't forced to use the tk2dCamera for any reason, though if you use a normal ortho camera, you'll have to handle resolution rescaling yourself.

    Second option is to use the overrides in tk2dCamera to scale things down. Drop me an email and I'll give you a patched version which has a global scale.
     
  14. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    do you adjust global physics scale manually or is there any setting on unity for this?

    i dont want to quit 2dtk features like tk2dcamera. maybe i can do what ngui does. it adds a parent to camera and set scale on this parent.

    i sent you a pm for my email address.
     
  15. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    i can set second camera and integrate ngui. it adds more drawcalls to my 2dtk game. if i use gui layer just for labels like score and health should i use ngui? i am not sure if i should make my gui standard as ngui. it is ok if i use settings panel with ngui, because i use sliders, checkboxes. i wonder what 2dtk and ngui owners do for gui workflows.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What I usually do is I have a set of preset settings I use for tk2dCamera, and a bunch of helper functions to scale everything correctly:
    tk2dCameraUnits = PhysicsUtil.ConvertForce( realWorldUnits )
    With a set of functions like that, it doesn't really matter what units you are using.
     
  17. MMO-Developer

    MMO-Developer

    Joined:
    Jul 2, 2012
    Posts:
    25
    Unikron it's possible to use acceleration in 2d toolkit . I create sprite anim and i want to move that animation with acceleration on ios.
    Please Help Help Help !!!
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Attach a rigid body and apply force to it
     
  19. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I think he meant to "accelerate" the animation of the sprite, not the acceleration of his rigidbody (or whatnot) - like have a guy running a few frames (as in animation frames not FPS of the game) per second, then slowly increase the animation speed more and more, so he appears to accelerate as his animation becomes faster. - like in sonic the hedgehog I think they did this sort of thing as sonic gained speed and slowed down yaknow.

    IDK could be wrong lol...

    Anyway 2D Toolkit looks awesome, I will watch through all the videos and decide if I could use this or not... but regardless it seems like a solid tool for the 2d developer.
     
    Last edited: Nov 4, 2012
  20. DavidS

    DavidS

    Joined:
    Aug 19, 2012
    Posts:
    30
    Hi unikron,

    If pressing on a spot then a boxCollider is created and the sprite ('normal' size) is shown before moving to the next screen. However if changing the sprite (from 'normal' size to 'high resolution' size) then it does not work anymore. The issues is that the created boxCollider is now created not at z = 0 but at z = -100000. How can this be resolved?

    Further, for the enemies the auto. box created is turned off as otherwise the z = -100000 issues appears. So the boxColliders have been created as children. For some enemies both boxColliders work, for some only one of them, and for some neither, but all are created in the same way and it looks like this is created on a random behavior when creating an enemy. Any idea how this can get resolved?

    Thanks!
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This happens because the sprite has collider type set to "None/ForceNone" in the sprite collection editor. Change it to "Unset / User Defined" for it to leave your collider alone.
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It can't do that but you can easily add the behaviour - you do get full source code after all :)
     
  23. ikaria

    ikaria

    Joined:
    Mar 31, 2012
    Posts:
    10
    Quick general question --

    Can 2D Toolkit be used as an animation manager of sorts for animated textures playing on 3d meshes? Or is it really just intended for flat sprites, in ortho views?

    thanks!
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It is intended for flat sprites, but not limited to 2d, or ortho views - you can place them on 3d geometry should you like to. That means you can't map it to arbitrary geometry - but you get a plane the right size, which you can position anywhere in 3d space.
     
  25. ikaria

    ikaria

    Joined:
    Mar 31, 2012
    Posts:
    10
    "...you get a plane the right size..."

    Do you mean that I can only map textures to planes or that my geometry needs to have the UV's set up to correctly display the animation?
    Ideally, I'd like to be able to use your Toolkit to play a sequence of frames over a curved surface and switch out the sequences based
    on what happens in game play via (perhaps) some of the classes that ship with 2D Toolkit. Doable?
     
  26. MMO-Developer

    MMO-Developer

    Joined:
    Jul 2, 2012
    Posts:
    25
    Hi Unikron it's possible to colide 2d animation and 3d box colider ? i have in debug.log good response.But i want 2d animation that does not pass through the 3d colider it's bug or something else ?I am using on 2d animation mesh colider.
    void GetInput ()
    {

    dir.x = -Input.acceleration.y ;


    // dir.z = Input.acceleration.x;

    if(dir.sqrMagnitude > 1)
    dir.Normalize();

    dir *= Time.deltaTime;

    transform.Translate(dir * speed1)
    }

    void OnTriggerEnter(Collider otherObject)
    {


    if(otherObject.tag =="RightColider")
    {

    Debug.Log("we hit right colider" + otherObject.name);

    }

    if(otherObject.tag =="LeftColider")
    {

    Debug.Log("we hit left colider" + otherObject.name);

    }
    }
     
    Last edited: Nov 5, 2012
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Not on a curved surface, unless you want to write some code / use a custom shader. You can switch things in and out no bother, but the geometry and/or UVs will have to be updated every frame.

    Having said that though, if you've got the frame time, you could put one of the animated sprites behind a camera with a render texture, then your main model won't need to know how complex the atlasing was, where the image was trimmed, or if it was rotated in the atlas, etc.
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I don't know how your meshes are set up, but if your player object is a rigidbody, you should never move it like that if you want it to collide properly with other objects. When moving rigidbodies, always use AddForce. Apart from that, the easiest thing to do is to use the character controller if you can.
     
  29. funasylum

    funasylum

    Joined:
    Feb 5, 2011
    Posts:
    48
    Hey Unikron -- is there a way to change a tk2d animated sprite's framerate procedurally? Thanks!
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @funasylum - sorry I missed your post. No there isn't in the current version but there will be in the next release due out in the next day or two.
     
  31. OldManMcD

    OldManMcD

    Joined:
    Jul 8, 2012
    Posts:
    3
    Hello, I am having an issue with sprite swapping.

    I'm looking for an easy way to switch between regular sprites and HD versions of sprites. I want to do this so my app can be deployed on both iPad 2 and iPad 3 without stretching the graphic. The way I'm trying to do this is that I have two sprite collections for each scene:

    SceneXSpriteCollection and SceneXHDSpriteCollection.

    Each sprite in SceneXSpriteColleciton has an HD version in the SceneXHDSpriteCollection name the same, but with "-HD" at the end:

    regular sprite:
    spriteX
    HD sprite:
    spriteX-HD

    What I'm trying to do is use tk2dSprite.SwitchCollectionAndSprite() to swap the collection and the sprite to the HD version. I am also trying to use tk2dSpriteCollectionData.GetSpriteIDByName() to find the sprite id of the HD sprite to pass into SwitchCollectionAndSprite(). I would like to be able to find the sprite's name and add "-HD" to the end and pass that into GetSpriteIDByName() to figure out what sprite to switch to.

    My problem is I can't figure out a way to get the name of the sprite that I am currently using to add that "-HD" to. I tried using .name, but that seems to only give me the name of the gameObject. I was looking through the scripting reference and was thinking of using tk2dSpriteCollectionData.assetName, but Unity tells me the collectiondata doesn't have that property.

    Is there an easy way to get the name of the sprite that I'm just missing?

    Thanks in advance!

    Edit: I should also mention I'd like to do it this way so my artist does not have to order both sprite collections the same way. I know that in a perfect world they should be, but we have a ton of sprites and it would be nice if they could just make sprite collections without worrying about the order in which they add sprites to them.
     
    Last edited: Nov 8, 2012
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,
    Why not just use 1.80? It has built in support for transparently switching sprite collections. Docs here:
    http://unikronsoftware.com/2dtoolkit/doc/advanced/platform_specific_sprite_collections.html

    Let me know if you dont wanna update, I'll go ahead and write a reply to your post here.
     
  33. jeffreyf

    jeffreyf

    Joined:
    Sep 22, 2012
    Posts:
    15
    Hey, is there a way to edit a tilemap after it's been "committed"? Can I move tiles around/delete/add them? Or do I have to recreate the entire tilemap after I commit?
     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    From code? Yes, but its "unsupported" and is very very slow if you have colliders set up. It isn't too bad if you don't use colliders at all.

    Code (csharp):
    1.  
    2. tileMap.Layers[0].SetTile(x, y, spriteId);
    3.  
     
  35. jeffreyf

    jeffreyf

    Joined:
    Sep 22, 2012
    Posts:
    15
    No, I actually meant in the scene editor. To me it looks like it's baked layers and chunks and I have no idea how to edit them. Is there more of a tutorial available besides this one in the docs? http://www.unikronsoftware.com/2dtoolkit/doc/tilemap/tutorial.html
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Just select the tilemap object (in the hierarchy not the scene view) and click "Edit".
    Selecting in the scene view will select the baked layer meshes which can't be edited directly.
     
  37. ikaria

    ikaria

    Joined:
    Mar 31, 2012
    Posts:
    10
    Just got 2D Toolkit -- and love it already -- but am running into a depth sorting problem --

    Question:
    How do I make sure my animated sprite gets drawn on top of other geometry when closer to camera?
    Currently, at certain depths, objects behind get drawn on top of the sprite.

    Thanks!
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Are you using a perspective camera? If so have you set camera.transparencySortMode = TransparencySortMode.Orthographic?
     
  39. jeffreyf

    jeffreyf

    Joined:
    Sep 22, 2012
    Posts:
    15
    Sorry for being a pain about this, but when I click the TileMap Render Data object in my hierarchy, I do not see an edit button in the inspector for it or any of its children (Layer0 which has Chunk 0 0 and Chunk 0 1). This looks like the only TileMap object in my hierarchy. Did I perhaps accidentally delete something or is this the right object?
     
  40. jeffreyf

    jeffreyf

    Joined:
    Sep 22, 2012
    Posts:
    15
    Oh you know what, I was trying to create another tilemap, and this works. I think what happened was I lost the TileMap Editor object... Good thing I was just testing and not doing anything serious.


    Thanks for your speedy response. This toolkit is great!
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad you found a solution!
    (and glad you like 2D Toolkit :))
     
  42. Nezabyte

    Nezabyte

    Joined:
    Aug 21, 2012
    Posts:
    110
    Is there a built-in way to handle z-fighting as part of TK2D and/or best practice to handle it? My enemies from the same game object prefab spawn at the same transform z axis level, causing them to fight for rendering order every frame.
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you think they'll overlap, you must have a determined preferred draw order right? If you're spawning them from prefabs, just keep a tab of what z values you've used and make sure you don't spawn 2 at the same z value. It sounds a bit counter intuitive, but all thats happening there is that you're giving it an explicit draw order. Even tiny z differences are sufficient.
     
  44. OldManMcD

    OldManMcD

    Joined:
    Jul 8, 2012
    Posts:
    3
    Updating does not seem to be an option for us, as doing so unlinks all of our classes and what not. Is there another option?
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Drop me an email and we can discuss this further. Yes, there are a few ways to work around this.
    support@unikronsoftware.com
     
  46. ikaria

    ikaria

    Joined:
    Mar 31, 2012
    Posts:
    10
    Thank you, Unikorn. That was partially it. The center point of a large piece of 3D geometry was still in front of the sprite, even in the ortho mode . Ended up chopping the 3D asset. Everything works fine now.
     
  47. jeffreyf

    jeffreyf

    Joined:
    Sep 22, 2012
    Posts:
    15
    So I tried switching from orthographic to perspective, and I'm having a bit of trouble with "shimmering" (aliasing I think it's called). In orthographic using the tk2dcamera, everything looked great. I could move the character and camera and sprites, and the sprites would stay looking sharp. Now that I'm in perspective, I'm having problems whenever the sprite or camera moves. Thin black borders around the edges of sprites show this best: they'll grow and shrink as they move, and it looks really ugly. Any suggestions on how I can get around this shimmering and make my sprites look as pixel perfect and as sharp as orthographic did? I tried playing around with 1:1 and the "Always keep pixel perfect" check box, but I'm having no luck...


    Edit: I just found this faq and my scales are not 1,1,1. I'm gonna have to try to get the scale fixed, and if I'm having problems still I'll come back here and ask
     
    Last edited: Nov 12, 2012
  48. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    i installed unity 4 and imported 2dtk again. i have a sprite that has a script. script translate transforms. when i play it, i can see on scene window collider moves but sprite does not. it was ok on unity 3.5. should i do more to work on unity 4?
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No, it should work fine. Drop me an email and we'll investigate this. Need more info, platform, target platform, etc. Also, does the animation demo work?
     
  50. alfarmer

    alfarmer

    Joined:
    Nov 16, 2012
    Posts:
    27
    Hello.

    My app needs to run on both Android and iOS, but I can't seem to get the aspect ratio to work. On Android (1280x800) it looks fine but on iOS the field of view isn't wide enough so I only see the center 80% of my background image.

    I currently have two sprite collections -- one with the background image and one with smaller button images. I'm using an ortho Unity camera (my only camera) and I'd prefer stretch-to-fit over letter-boxing, but either is preferable to losing data off the sides of the screen.

    Not sure what to do to fix this but hoping someone can point me in the right direction.

    Thanks!