Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. thecosmicboy

    thecosmicboy

    Joined:
    Mar 29, 2012
    Posts:
    2
    Thanks man, will do.

    Would just like to say 2dtoolkit is a fantastic addition to unity,
    very high quality plug-in and well worth the price :)

    Keep up the great work.
     
  2. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    I've been away from Unity for a while, so I installed Unity 3.5 and the most recent version of 2d Toolkit. When I import 2d Toolkit I am getting the following error:

    Assets/Standard Assets/tk2d/Fonts/tk2dTextMesh.cs(602,26): error CS0103: The name `tk2dCamera' does not exist in the current context

    The line of code it is referencing is:

    else if (tk2dCamera.inst != null)

    Any thoughts on what could be causing this?
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes.

    I'm guessing you're using JS? If thats the case, then you will need to move the tk2dCamera tk2dCameraAnchor files to the same directory all the rest of the runtime scripts are. Please let me know if that fixes it for you.
     
  4. gamefools

    gamefools

    Joined:
    Apr 9, 2011
    Posts:
    35
    Yes, using JS. This fixed the problem for me. Thanks!
     
  5. hidingspot

    hidingspot

    Joined:
    Apr 27, 2011
    Posts:
    87
    Well, we're doing more complex camera motion than just scrolling. So a perspective camera is more or less a necessity.

    Nevertheless, I was able to develop my own solution. It is similar to the Owlchemy Labs "RenderQueueSetter", but gets around the fact that 2d toolkit reverts any user specified material on a sprite. It does so by creating the a unique material instance at runtime for each unique renderqueue. In the end, it basically does the same thing as RenderQueueSetter. The nice thing is that it doesn't require you to create a bunch of material copies in the editor for every render queue (as is needed by RenderQueueSetter). However, since it only happens at runtime, the game view in unity doesn't display the correct laying until the scene is played. But it does the trick.
     
  6. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    Hello,
    how does 2D Toolkit handle collisions while an sprite animation is being played?
    Is it possible that the collider changes with the animation per frame?

    Soul :)
     
  7. nikolic

    nikolic

    Joined:
    Oct 15, 2011
    Posts:
    162
  8. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    currently we are having problems with the following:

    our background for a pixel perfect 2d game is 10kb in size after photoshop. when we import it into unity and use ARGB 32bit (since we need no compression but alpha) it gets up to 4mb in size. this of course is bad since our game gets big after 5 backgrounds.

    can 2d toolkit help us in this matter? (meaning will it give us pixel perfect graphics with lower filesize inside unity)
     
  9. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    thank you very much nikolic :)
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can animate box colliders but not polygon colliders. Support for poly colliders will not be added due to the performance constraints, but there are plans to extend box collider/sphere collider support.
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No it won't. 2d toolkit uses unitys texture formats, so if you want no compression the best you're going to get is 16 bit with dithering. One thing to keep in mind though, is that the texture may be 4 mb in memory, but that's how much memory the png will take up when loaded anyway. Also, the 4mb is then compressed when you build to target, so actually check the final logs to see how much space it's REALLY occupying. If your texture is 10k I'm guessing it has a lot of the same - in that case it should compress nearly as well in unity.

    The other alternative is to load the png using the www Api. This can work, but keep in mind that the textures must be decompressed in memory and managed there.
     
  12. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    i actually checked the size when i build the app but it also shows me 4mb inside the build and not only in memory.
     
  13. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This shouldn't really happen. I'll investigate this for you - what platform were you building on?
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Ok. The log doesn't really show you the final sizes unless you're building a webplayer. Also the compression on the webplayer seems to be significantly better than the normal standalone ones. Its still there nonetheless. Comparing a standalone win/mac build with 1 vs 2 1024x1024 textures, the size the second texture has added is around 500k. This is obviously very dependent on the content of the texture, etc. I'm not sure what compression they use, but it is certainly compressed.

    The webplayer on the other hand compresses much better - 1 texture taking around 170k or so.

    Its worth checking if you can live with these kinds of sizes - loading PNGs directly, while it will work, is a lot more inconvenient. There are two options there - either use the www class, or get your own png decoder and feed the Texture2D directly.
     
  15. adam718

    adam718

    Joined:
    Mar 11, 2012
    Posts:
    58
    Hi!

    I have two questions.
    1. When BMFont size is 4096(for cjk font), does it work well in android?
    2D Toolkit and Other BMFont related product have error like following image when font texture size is 4096.

    $SC20120405-005312.jpg
    2. How do you get the bmfont?
    I try to change another bmfont but outlining always fails.
    For outline font, what should I do additionally?

    Thank you,
    Adam.
     
  16. unikronsoftware

    unikronsoftware

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

    This looks like it may be caused by your device not supporting 4096x4096 textures. Unity does this on iOS, for instance on an iPhone 3G which only supports 2048 textures. You will have to downscale to 2048x2048 for it to work correctly.

    With regards to the border, you need to set it up during export in bmfont. This page lists the settings:
    http://unikronsoftware.com/2dtoolkit/doc/tutorial/Preparing_a_font.html

    So to get outlines, you should set it up in the Export Options menu - A = outline, R,G,B = glyph. In font settings, simply increase Outline thickness.

    Edit: it is possible to have the font on 4 2048x2048 pages and automate the mesh creation process, but the performance will be erratic at best, the number of draw calls can change between 1 and 4 for any line of text.
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You've probably mixed-up ex2D and 2D Toolkit - you should ask that question in the ex2D support thread.
    Cheers,
    unikron
     
  18. DenninDalke

    DenninDalke

    Joined:
    Jun 13, 2011
    Posts:
    5
    Thanks for the fast reply @unikron forgive me for the mistake!
     
  19. Zencraft

    Zencraft

    Joined:
    Jul 18, 2011
    Posts:
    6
    Hi!

    I'm converting a Cocos2D game to Unity to speed up development time.

    In Cocos2D i used Zwoptex (atlas generation tool) for making sprite atlases. Zwoptex has this feature called "Find Make Aliases" in which all sprites are compared on a per-pixel level, sprite doubles are removed from the atlas. Instead the "missing" sprite is referenced with a string-alias in a .plist. My artist duplicates sprites a lot, so this "Find Make Aliases" feature greatly reduces atlas size.

    Texturepacker (atlas generation tool) has this feature as well. Texturepacker manual describe it in this way: "TexturePacker automatically creates aliases for sprites which are the same after optimization. E.g. if use an animation which has the same images in some phases – but perhaps just shifted – TexturePacker will only save one version of the image"

    - Is this "Find Make Aliases" feature available in 2D Toolkit?
    - ... or can I use the atlases and .plist files i created in Zwoptex directly in 2D Toolkit?

    Cheers!
     
  20. unikronsoftware

    unikronsoftware

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

    Just to make sure I understand this correctly - you're talking about source sprites which are identical on a pixel level, but saved to a different file? 2D Toolkit doesn't support it natively, but it does walk the pixels of every texture - it could easily compute a hash while it does that and use that to mark duplicates. 2D Toolkit already supports duplicate textures within the same atlas (as long as they're the same file) - but this could be easily extended to use these hashes instead.

    Could you please elaborate on why your artists do what they do?

    Cheers,
    unikron
     
  21. Zencraft

    Zencraft

    Joined:
    Jul 18, 2011
    Posts:
    6
    Hi unikron.

    Thanks for a quick reply! To your question: "Just to make sure I understand this correctly - you're talking about source sprites which are identical on a pixel level, but saved to a different file?" - then answer is yes.

    The artist is very fast at creating animations by hand-drawing each frame in a sequence like old school flip-book animation. Since the artist animation program uses a fixed time length pr. frame, the artist sometimes duplicates frames in order to control the timing.

    As an example the artist wants to make an animation of running person that accelerates:

    In order to have the persons legs moving faster and faster, the artist e.g. uses two frames "left.png" (for left leg moving forward) and "right.png" (for right leg moving forward). Then the artist makes an animation by putting in the frames like this:

    left.png > left.png > left.png > right.png > right.png > right.png > left.png > left.png > right.png > right.png > left.png > right.png

    When he export the frames from his animation program i get a folder containing the following files:

    run01.png, run02.png, run03.png, run04.png, run05.png, run06.png, run07.png, run08.png, run09.png, run10.png, run11.png, run12.png

    Now all these files only contains two different bitmap data.

    In Zwoptex i would first dump all the "runXX.png" files into an atlas. The atlas would contain all 12 files. Then i would click "Find and make aliases" - Zwoptex then would optimize the atlas to contain only "run01.png" (first occurring of bitmap data from left.png") and "run04.png" (first occurring of bitmap data from right.png") and a plist that contains string aliases for the rest of the runXX.png files.

    In Cocos2d i would then create a sprite animation by adding the frames "run01.png, run02.png, run03.png, run04.png, run05.png, run06.png, run07.png, run08.png, run09.png, run10.png, run11.png, run12.png". When Cocos2d lookup the run02.png information in the atlas, the atlas gives the coordinates of run01.png since they contains the same bitmap data.

    The nice thing is that I can just use the original sequence of frame names (runXX.png) the artist gave me and the artist does not need to worry about duplicating frames. The "Find and make aliases" optimizes the atlas sizes greatly, without changing the workflow.

    Another option is that the artist become more aware of not duplicating frames, but we use this kind of animation because we want to have a messy hand-drawn look. From this perspective the artist is much better at creating good-looking timings than me as a coder.

    Cheers,
    Zencraft
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thats a fair request, and thanks to your explanation I understand why someone would want to do something like this. I can see how this could be beneficial to not just yourself, but many other devs. I will put it on the backlog for 1.70 beta 1 - I still have a few more features which I will need to implement, but in the event that all of that is done in time, I will try and squeeze this in.
     
  23. Zencraft

    Zencraft

    Joined:
    Jul 18, 2011
    Posts:
    6
    Thanks! :)
     
  24. adam718

    adam718

    Joined:
    Mar 11, 2012
    Posts:
    58
    Hi unikron!
    Could you kindly explain in more detail?
    And somebody also said that I could use several textures>
    Any idea?

    Thank you,
    Best Regards,
    Adam.
     
  25. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    Just want to double down on this Thanks! I work with artists that animate in flash and export to png's pretty regularly - a lot of manual work at the moment finding identical frames and deleting them / referencing the first version of that frame to lower memory usage. If tk2d could automatically detect the identical frames that would be an incredible time saver!
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That is a possibility, thought 2D Toolkit doesn't support it now for the reason I mentioned - the draw calls become really erratic and very hard to control. We try to avoid things which are most certainly going to affect performance adversely.

    I can tell you what needs changing to make this work with the current code, but if you're running on an android device, you are probably going to have issues with draw call performance anyway. Is there any reason in particular you need a 4096x4096 font texture?
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I have put it in the backlog, but I really can't commit to a date on it. I'll try my best to get it out for 1.70 final, but again, no promises! It really depends on what my priorities are and how much work is required on the tilemap editor.
     
  28. adam718

    adam718

    Joined:
    Mar 11, 2012
    Posts:
    58
    Thank you for your reply.
    I am from asia and try to use CJK font.
    But it requires at least 4096 texture to involve whole korean characters.
    That's the reason why I need 4096 texture.
    I hope you help me with my problem.

    Thank you,
    Best Regards,
    Adam.
     
  29. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'm not sure how normal software manages this - a 4096x4096 texture occupies a significant amount of memory. Eg. 4096x4096xA8 = 16MB and 4096x4096xRGBA = 64MB. Even 16MB is a substantial portion of memory for a font in a game. Would it not be possible to split this up somehow and manage it like that? The reason I'm avoiding the multi material support mentioned before is performance. Performance will significantly drop if you did that - there is no way around that, except by manually deciding where to split to minimize the draw call overheads. I can't comment on that as I don't read/write Korean. Can anyone with experience on this please comment?
     
  30. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    Hi again

    I'm trying to resize the box collider on an animated sprite, but it resets the z scale to 0.2 at runtime, even if I have 'create collider' unchecked. Is there any way to avoid this?
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you want to resize it you will need to do it on the sprites themselves. If its resizing the zscale to 0.2 then its probably because its set to that value in the SpriteCollection. If you are on version 1.60, simply open up the Sprite Collection Editor, bring down the settings panel and change collider depth there.

    If you'd like to manage the collider yourself entirely, simply multiselect all those sprites, set Collider Type to None and click Apply to set it to all of them. (Dont forget to commit the changes after)
     
  32. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    821
    If that doesn't work, you probably want "Unset" not "None" for the collider type (none will remove your colliders, unset ignores them entirely) unless something has changed recently.
     
  33. bfoddy

    bfoddy

    Joined:
    Mar 27, 2012
    Posts:
    85
    Brilliant, thanks
     
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No it hasnt, it was an oversight on my part. Thanks for pointing it out.
     
  35. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Unikron,

    Quick Question... I'm going to be setting p a series of characters for a 2d-ish game... (character construction ala battleheart/mikamobile).

    I have the separated psds from the artist, but would like the freedom to animate textures (say hand shapes, eye blinks, muzzle fire...)
    One of the other 2d animation packages allows texture swapping, This would be amazing. Do we have that capability with 2DTK?

    Also, I'm pretty sure we can't do animation clips, but is this something you've considered including in 2DTK? i bought it recently, and it's some much easier to work with than the now dated sprite solution I purchased long ago. But to be able to animate, swap textures, and save animation clips would be terrific.

    MY other thought was to do that stuff in Maya old school, but I noticed another 2d package allows it, figured Id ask.

    Great product.
    B.
     
  36. unikronsoftware

    unikronsoftware

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

    Most of this is actually possible - texture swapping is possible using a simple script to set up mirrored animations. So the workflow is you set up everything on one spriteanimation, and then you have a script which will generate the rest of the SpriteAnimations (and the clips) by swapping sprite collection but retaining sprites of the same name. There is some code to create a Sprite Animation in code in the private support forums. Feel free to grab that and tweak it to your needs, and just get in touch via email / forums if you run into any trouble with it.

    You can also animate objects using the Unity animation editor (with or without hierarchies). Pretty much everything works, and again, there is some sample code for a helper class to mirror colors, etc. which can be extended really easily to support animations.

    We do have plans for some real high end 2D animation tools longer term, but I'm really gauging demand for it. Its going to take a significant amount of effort to do it properly, and I don't know if there really is a market for something like this.

    Hope that helps.

    Cheers,
    unikron
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  38. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    741
    Great stuff... Thanks Unikron!
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi Adam,
    Apologies - I must have missed this post somehow, only noticed it while going through the older posts. I've sent you a PM requesting for more info, could you please check that?
     
  40. PixelFish

    PixelFish

    Joined:
    May 4, 2011
    Posts:
    12
    Can 2D Toolkit be used with touch input, swipe gestures, etc.?
     
  41. unikronsoftware

    unikronsoftware

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

    2D Toolkit provides a system to generate sprites, colliders - you are free to attach your own touch behavior scripts to these sprites, or you should be able to use the excellent FingerGestures with it too.
     
  42. mobilegamelabs

    mobilegamelabs

    Joined:
    Apr 11, 2012
    Posts:
    26
    Just bought it. I like the workflow of it. Nice Tool... :)
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad you like it :)
     
  44. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    327
    When will the tile mapper be out of beta / ready for general consumption?
     
  45. richard2812

    richard2812

    Joined:
    Feb 26, 2009
    Posts:
    16
    Hello,

    I've some problem to import the 2dtoolkit 1.60 patch 1 on my project, I'm using javascript for scripting language. The error he gave me is the following:

    Assets/TK2DROOT/tk2d/Editor/Camera/tk2dCameraEditor.cs(47,6): error CS0616: `MenuItem': is not an attribute class
    Assets/TK2DROOT/tk2d/Editor/Camera/tk2dCameraEditor.cs(47,6): error CS0246: The type or namespace name `MenuItemAttribute' could not be found. Are you missing a using directive or an assembly reference?

    I've tried to move him and also the other two script of the camera (tk2dCamera.cs tk2dCameraAnchor.cs) everywhere but he continue to give me errors connected to the tk2.

    Can you help me?

    Kind Regards,

    Riccardo
     
  46. unikronsoftware

    unikronsoftware

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

    You will need to move just the tk2dCamera.cs tk2dCameraAnchor.cs classes to where the sprite classes are to work around this. You shouldn't move the tk2dCameraEditor class, or any other class in the editor folder.

    Drop me a support email if you still have issues with this.

    Cheers,
    unikron
     
  47. unikronsoftware

    unikronsoftware

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

    I'm taking it easy with the tilemapper and trying to get it as stable as possible before releasing a final version. I expect to do that by the end of the month, with at least one or two more betas in between. There are 2-3 more non-essential features missing, but for the most part, I've not received any serious bug reports about it so far. The core data structures have been finalized, so any further versions will be backwards compatible with this one.

    Cheers,
    unikron
     
  48. mobilegamelabs

    mobilegamelabs

    Joined:
    Apr 11, 2012
    Posts:
    26
    Hi Unikron,

    I am new to Unity 3D and 2D Toolkit. I am sorry if my questions don't make sense. I will elaborate if they are not clear. Thanks.

    I am trying to make my sprites pixel perfect. I have made a script to round the x and y screen positions to rounded values plus a fine tuned offset, and then update the world positions according to the corrected screen positions. The sprites looked pixel perfect in Game Mode. However, the sprites have rigidbody and would be given velocities and accelerations to move. Do you think updating the positions of transform by scripting in this way would affect the movement and force calculation by the PhyX engine? Is it possible to update the relative positions of Mesh Renderer instead of the whole game object?

    I guess a solution is to enable Point Sampled in the settings of Sprite Collection Editor instead of adding the script to modify positions, but I don't know if I will use it because I may want the sprites to blur a bit (by not using Point Sampled) when the sprites are rotating.

    Thanks very much for your time.
     
    Last edited: Apr 12, 2012
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't update the positions of the MeshRenderer alone - if you want to do what you're describing you'd have to mirror the sprite hierarchy and update individually. Another option is to explicitly update into a larger mesh, and perform transformations, etc. on CPU, but I'm guessing the former approach would be faster ultimately - I'm guessing Unitys dynamic batching code has an optimized path there to sort this out.

    So, what you're suggesting is probably the best bet here.
     
  50. mobilegamelabs

    mobilegamelabs

    Joined:
    Apr 11, 2012
    Posts:
    26
    Thanks very much for your help.

    Since it's the 1000th post in this thread, to celebrate I am sharing a set of my placeholders which are quite good for doing pixel perfect in perspective camera. Everyone please feel free to use them if they help. :)

    Contains:
    placeholder_1x1.png
    placeholder_2x2.png
    placeholder_4x4.png
    placeholder_5x5.png
    placeholder_8x8.png
    placeholder_10x10.png
    placeholder_16x16.png
    placeholder_24x24.png
    placeholder_32x32.png
    placeholder_64x64.png
    placeholder_128x128.png
     

    Attached Files:

    Last edited: Apr 14, 2012