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
    What version of Unity / 2D Toolkit are you running?
    You could have found a bug with a particular combination of the two.
     
  2. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Unity 3.5.7f6 and the latest 2D Toolkitversion!
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That is the main version we use for development. I can't reproduce this on my end. If you can send a repro case showing the issue, I would most appreciate it (support at unikronsoftware.com). I'd understand if you can't due to confidentiality issues obviously.
     
  4. chillypacman

    chillypacman

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

    Is it at all possible to set a texture size for 2D Toolkit to use when importing a texture?

    The reason I ask is because I have a very large texture and I want it to be imported as a 512x512 texture by 2D Toolkit so I can fit it in the texture atlas.

    Is this at all possible?

    Cheers
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It doesn't do that right now - it goes ahead and sets the maximum to 4096 before importing the texture. The reason for this is that Unity sets the maximum to 1024 by default when you first import a texture, and that kinda cripples it for those who want to import larger textures.

    You do have the source though, so its trivial to disable this -
    tk2dSpriteCollectionBuilder.cs
    IsTextureImporterSetUp
    ConfigureSpriteTextureImporter
    remove all references to maxTextureSize, and that should be it.
     
  6. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,823
    Question - does this system support creation/management/animation of hitboxes, or will I need to use my own system to manage that?
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You will need to extend the current system for multiple hitboxes. If you only need one, then you can use the box collider system.
     
  8. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Uh unfortunately I can't send you the project :/
    But it's not a big problem, as long everything is stable and working.

    Another question:

    Can I flip animations vertically like the Sprites? For example, when the character walks to the right and then to the left, that the "Walk"-Animations flips to the other side (a horizantol Flip), or do I have to make a whole new Animation?
     
  9. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup you can flip sprites using
    sprite.scale = new Vector3(-1, 1, 1); // to flip to the left
     
  10. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Yeah, but will the Animation play correctly? When I flip the character to the left and move him to the left, will the Animation also "flip" or do I have to make another Animation just for the opposite direction?
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Flipping flips the sprite, so the animation should appear flipped. Unless of course you have special sprites for the flipped animation...
     
  12. jayhatmaker

    jayhatmaker

    Joined:
    May 14, 2013
    Posts:
    7
    Hi, I'm looking for a 2D tile engine solution to my upcoming game, which have quite large number of tiles. (similar game would be Terraria.)
    The width and height of a regular world is 4096 x 1024. I'm looking at Orthello 2D Pro, and your 2D tool kit.
    Is there a draw call optimization for such large number of tiles (or sprites as I could say)?

    Also, I want to know... the version is 1.92, and almost 2.0.
    If I purchase your software now, do I have to pay again when you update it to 2.0?
     
  13. unikronsoftware

    unikronsoftware

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

    2.0 is a free update.

    You can do a terraria style game in it, I know of at least 2 people who have successfully created HUGE worlds, but you have to do a few things yourself.

    1. You can't use the built in physics mesh / collider system. Terraria uses block based physics - each tile is either on or off, so its not too bad to roll your own.

    2. You should manage streaming yourself - i.e. create a AxB tilemap centered in the screen, and then page the data in sync with the partitioning system. The 2D Toolkit tilemap system is clever enough to only rebuild the parititions that have changed, so you can be in full control over what changes and when. So - the player remains in the middle of the screen always, but the world "moves" around him/her. That way your actual world can be pretty much as big as you can fit in memory, which is very big indeed.
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  15. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Wow, the "Static sprite batcher" sounds pretty cool! Lookin' forward to it!
    Thanks for the update
    Pete.
     
  16. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    As always, Unikron rocks the app and takes it to a new level. Congrats, thanks and true respect and appreciation for the continued hard work, support and innovation. You're a 'Developer's Developer!'
     
  17. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Hey there. Is there a way to determine if an Animation finished playing?
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    animation.Playing returns true when an animation is still playing.
    animation.IsPlaying( clip ); returns true when a given clip is still playing.
     
  19. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Ah allright...hm, still got some problems in order to start the second animation when the first has ended :/
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What problems?
     
  21. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    I can't manage to start the second animation.

    Code (csharp):
    1. if (!playerSprite.IsPlaying ("attack")) {
    2.  
    3.             playerSprite.Play ("attack");
    4.         }
    5.         else
    6.         {
    7.             playerSprite.Play("idle");
    8.         }
    9.  
    I want the character to go and stay in the "idle"-Animation after the "attack" is finished. (The "idle"-animation os one single frame.)
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In version 1.x Play will restart a clip that is already playing. So your Play("idle") will keep restarting that indefinitely, i.e. be stuck on the first frame.
    Do this:

    if (!playerSprite.IsPlaying("idle")) playerSprite.Play("idle");
     
  23. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Do you mean like that:

    Code (csharp):
    1. if (!playerSprite.IsPlaying ("attack")) {
    2.             playerSprite.Play ("attack");
    3.         }
    4.         else
    5.         {
    6.             if(!playerSprite.IsPlaying("idle"))
    7.             playerSprite.Play("idle");
    8.         }
    9.  
    If so, tried that and it didn't work. BUT I looked up your Docs and tried this:

    Code (csharp):
    1.  void HitCompleteDelegate(tk2dAnimatedSprite sprite, int clipId) {
    2.        
    3.             anim.Play("idle");
    4.     }
    5.  
    6.     // Update is called once per frame
    7.     void OnClick ()
    8.     {
    9.             if (!anim.IsPlaying("attack"))
    10.             {
    11.                 anim.Play("attack");
    12.  
    13.                 anim.animationCompleteDelegate = HitCompleteDelegate;
    14.             }
    15.     }
    That way it worked :)
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yup that exactly.

    Since this has caused a lot of confusion with users, we have changed behaviour in 2D Toolkit 2.0, so calling play on an already playing clip will not restart it.
     
  25. Saroumana

    Saroumana

    Joined:
    Jan 20, 2013
    Posts:
    6
    Hello,

    I'm looking for a 2d engine. First i was oriented to xna, but like this engine is not supported anymore, i'm wondering if this 2d toolkit can handle a huge world. When i say huge, it's really really really huge like in Distant World with thousand of solar system
    , planets and more.

    In this case, only objets which need to be displayed should be instantiate. I have already tried Unity in the past, and it was not possible, but with 2d toolkit, it is ?
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is definitely possible with Unity, 2D Toolkit will help with the sprites, etc. - the thing is you will need to think it through properly - since the world is so big, you will need some form of a partitioning scheme, and creating it with gameobjects will probably not work due to floating point constraints. But you can maintain your world independently, and use some form of zoning system to isolate local objects - you can create and update your scene dynamically to allow virtually infinite sized worlds. You just need to be aware of floating point limits, etc. and you can easily work around the constraints.
     
  27. Saroumana

    Saroumana

    Joined:
    Jan 20, 2013
    Posts:
    6
    Thank you, i wasn't aware about floating problem in unity, but i'll definitly looking about that solution.
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't a floating point limit in Unity, but for large worlds, you'll have to deal with floating point limits in general.
    Some useful reading here -
    http://xboxforums.create.msdn.com/forums/t/103789.aspx
     
  29. inkbirdstudios

    inkbirdstudios

    Joined:
    Mar 12, 2012
    Posts:
    20
    Does this support/work with pixel art? If so how would the work flow be?..i've been looking for a pixel art solution.
     
  30. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Hey Unikron,
    Just starting to use the toolkit font system a bit more and I was wondering, at the moment the font texture is multiplied over the color. Do you have a version of the shader where the font texture is added over the colour? Or a way to mod that shader?
    Thanks
    Pete
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It is easy enough to mod the shader, but you should duplicate and rename it before doing so -
    Change the line
    fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
    to
    fixed4 col = tex2D(_MainTex, i.texcoord) + i.color;

    There are also a few more variants posted on our forum, eg. add for color, multiply for alpha, so you can still fade it out. Eg. this one:
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,391.msg1708.html#msg1708
     
  32. unikronsoftware

    unikronsoftware

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

    You can most certainly use pixel art with it. There are a few examples of pixel art games in our forum here:
    http://unikronsoftware.com/2dtoolkit/forum/index.php/board,9.0.html

    2D Toolkit doesn't include a pixel art editor, etc - you'll have to use whatever package you like there. It does do all the other things you'll need to make a pixel art game - eg. tilemaps, sprites, etc. There isn't really a specific workflow for pixel art - you'd just do it the same way you do normal sprites, except use point filtering to get hard pixel edges.
     
  33. yuewahchan

    yuewahchan

    Joined:
    Jul 2, 2012
    Posts:
    307
    Is 2dtoolkit can make sprite to be billboard ( always face to camera ) with shader instead of monobehaviour ?
     
  34. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    That's perfect,
    I'll check the thread out too!

    Thanks
    Pete
     
  35. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Ahh Damn, i ran into a bit of an issue with that material tweak :(


    Before mod (fixed4 col = tex2D(_MainTex, i.texcoord) * i.color)


    After Mod (fixed4 col = tex2D(_MainTex, i.texcoord) + i.color)

    Looks like it's loosing the font's alpha channel. Any ideas?

    Thanks
    Pete
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That shader is fully additive, including the alpha channel, which is why its gone solid + white :)

    fixed4 tex = tex2D(_MainTex, i.texcoord);
    fixed4 col = fixed4( tex.rgb + i.color.rgb, tex.a * i.color.a );

    Try this - this is more like that other shader I linked, color is additive, alpha is multiplicative, so you will be able to fade out, and 1 in alpha wont make it solid.
     
  37. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Great, thanks man! That's workin'.
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  39. Matt-Face

    Matt-Face

    Joined:
    Mar 24, 2013
    Posts:
    18
    Hi Unikron,

    i am importing tile maps from "Tiled" for use in "2DTK". I am trying to setup my colliders by setting specific sprites in my sprite collection to have a "box trimmed" collider type. the only problem is that i can't seem to find any info on the correct way to expand out the z depth of the resulting colliders? i managed to manually adjust the z scale but it seems that this gets reverted back to it's default value at runtime... do i have to change the transform.localScale.z at runtime?

    i am using unity 3.5.7 and 2DTK 1.9.2 final + patch 1

    Thanks in advance!
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The collider depth is set up in the sprite collection. Increase it in the "Settings" page, and commit. It will then update in your tilemap.
     
  41. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Hey unikron,

    just a question regarding the PlayMaker-Actions for 2DToolkit:

    With the latest 2.0 release, will the Actions work with this 2.0 release?
     
  42. unikronsoftware

    unikronsoftware

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

    I don't think the playmaker actions have been updated, but I don't know for certain. I've had a lot of requests for this - I'll get Playmaker some point soon to check it out.

    Edit: If you have any specific issues, post on our forums and I'll investigate.
     
    Last edited: Jun 3, 2013
  43. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,231
    As ex2D's development has stalled I am casting out feelers for a new package. Here's the main reasons we still stick with ex2D for reference or make our own 2D solution (thought it might be helpful for developer to have a couple of suggestions):

    1. ex2D has the concept of anim clips. There's a neat editor which lets us drag and drop frames in a sprite collection or atlas, and order them any way we like. In addition any clip can contain any number of unity anim events, so that we can call our own code if a footstep is needed etc -- best of all this is ARTIST driven, in the editor - kinda essential when you have a lot to do, you just make your functions, document them and artists or designers use them whenever they like. TOB uses this extensively. The best part though, is ex2D lets you specify how long each frame will be on screen for when animating, plus I am able to multiply the playback speed in code.

    2. for anim clips in ex2D, we really are missing the ability to add any number of hot spots which change per frame (the reason we'll probably roll our own solution) - ie for attaching a sword to a hand, or a hat to a head. All it really needs is scale, rotation and position per frame for each point, and a nice api for reading that back, ie currentPlayingAnim.GetTransform[0].position; or such.

    Forgive me if you already have unity anim event support / support for frames having different lengths, I couldn't find those parts on your site. Looking like a great 2D system though. What is the speed like vs ex2D?
     
  44. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @hippocoder, I'm pretty sure I replied to your email ages ago. Didn't you get it? If not please drop me an email (support at unikronsoftware .com) and I'll resend it - we've had issues with email bouncing a lot recently :(

    1. You can do all all of those (events frames), but you can't drop frame textures in there. We use a list instead of drag and drop, but theres a pretty editor (with quick search) to pick sprites in the list. It was an intentional decision to avoid drag and drop, as we use the atlas itself everywhere, and the source images for the atlas can be sourced from a spritesheet, etc. Also it means that when your project gets big(ger?) you won't need the source assets in the project itself.
    http://unikronsoftware.com/2dtoolkit/doc/2.00/reference/sprite_animation_190.html <- sadly doesn't show all the features there, but you can drag each frame to fill as much space as you like, or type in a value in seconds / frames. Internally it still is a list of frames, so you will have to pick an appropriate timeslice.

    2. This is very likely to be in 2.1, but it will be set up per sprite rather than per animation clip.

    Unsure about speed vs ex2D - we've never really bothered to profile against them. The sprite classes don't have an update function or any other repeatedly called function, so once created the overhead is minimal - thesame as any static object really. We also have utility classes, like the static sprite batcher, which makes it possible to merge large numbers of static gameobjects into one mesh, if GameObject overhead becomes a problem. For dynamic objects, the overhead of the animator hasn't been an issue in any of the things we've used it on.
     
  45. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,231
    Hiya,

    I think it might be my email clients aggressive spam settings - I will try to look for your mail - I'm sorry or I would have replied there! Regarding anim frames, I wasn't very clear from your reply here if I can set how long each frame is on for individually, or if you meant that it's just a global setting for playback (if that's the case we will just add 2 frames of the same to pad it out?)

    Another question - do you still process animations etc off screen? With ex2D I had to write additional code so that the 100s (yes 100s) of ambient animations around the levels like little screws turning or smoke etc didn't update offscreen. Do you handle this, or is it something we should take care of?

    Thanks for the quick response!
     
  46. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can drag out / set each frame individually. Internally its still an array, so you'll be limited by the granularity of the fps setting of the clip.

    Animations aren't stopped off screen - you're still responsible in disabling them. Its much easier when its game specific, rather than processed per sprite in here. Eg. group a bunch of sprites per "room" and disabling the root object is far more efficient than processing bits and bobs all over the place.
     
  47. limdorn

    limdorn

    Joined:
    Jan 5, 2012
    Posts:
    56
    Hi everyone.
    I´m buying 2dtoolkit time ago but now I begin to use it.
    I know the basic : create a spritecollection, animation , ... but I want to create a sprite but I can´t select its spritecollection by code. How can I do?
    Thanks
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You need to get a reference to the sprite collection. In order to do that you'll need to know how Resources directories work in Unity. http://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html

    1. Create a Resources directory anywhere in your project, and move the sprite collection data object (and only that object) into the resources directory. You can now load it at runtime.

    2. Use Resources.Load( "nameofprefab", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData; to load it.

    3. Assign it to your sprite, using sprite.SetSprite( spriteCollectionData, "name of sprite"));
     
  49. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,121
    Hey there.

    I got into working with bmGlyph for Ingame-Texts. So I generated a FontFile (the Texture and the txt File) and imported it to Unity. There I followed the steps of your Documentation. But I got a little problem with Colouring the TextMesh. Here is a Screenshot of my "problem".



    On the right you see your Demofont of 2DToolkit, and on the left my generated Font. So I coloured the right Text red, and as you see it changed it's colour to red. I did the same to the left text with my generated font and set it to the same colour-values. It only colours the outlines red, but doesn't fill the characters like the ones to the right.

    How can I achieve this?
    Thanks in Advance!
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Is your font black by any chance? If it were black to start with, then it won't be possible to tint it. If you want a black font, make it white, and tint it in tk2d to black.
     
unityunity