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. AdamWaters

    AdamWaters

    Joined:
    Aug 30, 2011
    Posts:
    94
    We are seeing some sprite flicker. It only happens in release builds. In the debugger it doesn't happen at all. It gets worse when large numbers of sprites are on screen. It doesn't seem to be a problem with performance, draw calls, polys, and frame rate remain in good positions even with lots of sprites.

    Any suggestions of things to look into for this? I kind of don't know where to start.
     
  2. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Can you please mail a webplayer or a video demonstrating the issue to support@unikronsoftware.com? It's hard (impossible?) to guess what this could be without actually seeing it.
     
  3. BeardOfFury

    BeardOfFury

    Joined:
    Sep 4, 2012
    Posts:
    18
    Hey guys we here at Dime Studios just launched our debut IOS title Tasty Fish. Tasty Fish has been using Toolkit 2D from 1.6 and this is the result:

    http://itunes.apple.com/us/app/tasty-fish/id542310685?mt=8











    Defy nature through addictive Tap-n-Play arcade-survival gameplay, and keep your school of Tasty Fish alive for as long as possible. Turn the tides by unlocking Exotic Fish to add to your school and with them increase your survivability to compete in global leaderboards or just prove how much better than your friends you are.

    We think we have got something really cool going on and we're always looking for feedback so let us know what you think!

    Big thanks to the guys at Unikron software for making our lives much easier!
     
  4. AdamWaters

    AdamWaters

    Joined:
    Aug 30, 2011
    Posts:
    94
    Email sent with a link to our build. I can post example code as well if needed.
     
  5. zcstover

    zcstover

    Joined:
    Sep 1, 2012
    Posts:
    4
    hi, i keep getting this error and i have gone through a lot of different steps trying to fix it, if you could help me fix it or just show me a better way to use the commands that would be great

    error CS0120: An object reference is required to access non-static member `tk2dAnimatedSprite.Play(tk2dSpriteAnimationClip, float)'

    i am trying to load a different clip when you press d but it keeps getting that error ^^^

    public static string "WalkLeft" = tk2dSpriteAnimationClip.WalkLeft;
    void update()
    {
    if(Event.current.Equals (Event.KeyboardEvent ("d")))
    {
    tk2dAnimatedSprite.Play("WalkLeft", 0.0);
    }
    }
     
    Last edited: Sep 11, 2012
  6. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    The hint is in the error message: An object reference is required to access non-static member

    Meaning, you have to have a reference to an object. Assuming the script is attached to the same object as your animated sprite, refer to this tutorial on how to set it up:
    http://unikronsoftware.com/2dtoolkit/doc/tutorial/Scripting_an_animated_sprite.html
     
  7. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    163
    Hi Unikronsoftware,

    I bought this package last week and am converting a friends project to Unity. I haven't done much with 2d, but wanted to say it is a great tool so far. The only suggestion I have is pull down the old tutorials and replace with new ones. When I went through the tutorials, they were outdated, but was able to figure it out quick enough.
     
  8. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thanks for the feedback, it is much appreciated.
    Do you mean the old video tuts or the text ones?
     
  9. ddesmond

    ddesmond

    Joined:
    Feb 9, 2010
    Posts:
    163
    The old video tuts, still good but the UI has changed alot.
     
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It has. I'll get around to updating/fixing them sometime, promise! I only left them there as the core concepts still remain the same, even though the UI has been improved loads.
     
  11. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
  12. zcstover

    zcstover

    Joined:
    Sep 1, 2012
    Posts:
    4
    sorry for this stupid question but how can you set an animation clip as a variable?

    i am trying to set up something that checks whether a certain clip is currently playing and if that clip is playing then do something
     
    Last edited: Sep 13, 2012
  13. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't really do this - they don't exist outside the collection. You can always use the name or actual clip itself to compare, though. eg. animSprite.CurrentClip.name. Wouldn't that work in your case?
     
  14. cagezero

    cagezero

    Joined:
    May 8, 2012
    Posts:
    20
    Hi There. Thanks for the great library! Is there a way to change the scale of an animated sprite without breaking dynamic batching?
     
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @cagezero - use tk2dSprite.scale instead of transform.localScale.
     
  16. zcstover

    zcstover

    Joined:
    Sep 1, 2012
    Posts:
    4
    well, is there a way to see if a certain clip is currently playing? because the current clip only checks what current clip is playing and not if A certain clip is playing
     
  17. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    @zcstover, get a reference to the clip you want to compare with -

    tk2dSpriteAnimationClip clip = animatedSprite.anim.clips[ animatedSprite.anim.GetClipIdByName("...") ];
    or store the clip id somewhere and use that instead of resolving by name
    now you can compare clip == animatedSprite.CurrentClip


    The one thing you can rely on is that the clip IDs will never change. You can store them within your behaviour and treat them as a reference should you wish.
     
  18. Azuri

    Azuri

    Joined:
    Jul 23, 2012
    Posts:
    5
    hi, 2dtk is awesome. I love it :D

    But I have a problem with special characters.
    If i write some special letters like ÖäÜß into the textfield it works fine, but it is not working when I set the text with my script.
    The special characters simple doesn't appear in the textmesh and the textfield in the inspector is showing some strange symbols instead of the special characters.
     
    Last edited: Sep 16, 2012
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  20. YUSHI

    YUSHI

    Joined:
    Jul 7, 2012
    Posts:
    19
    Why does it appear that?
    $2012-09-16_175257.jpg
     
  21. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    increase atlas size or/and select multiple atlas.
     
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In this case, you've got only one texture and your texture looks rather large. Your atlas must be at least that size for it to work properly.
     
  23. Azuri

    Azuri

    Joined:
    Jul 23, 2012
    Posts:
    5
    thanks for your quick response
    It seems like it is a js bug

    the js code is not working
    Code (csharp):
    1.     gameObject.GetComponent(tk2dTextMesh).text = "wäs";
    2.     gameObject.GetComponent(tk2dTextMesh).Commit();
    the c# code is working
    Code (csharp):
    1. gameObject.GetComponent<tk2dTextMesh>().text = "wäs";
    2. gameObject.GetComponent<tk2dTextMesh>().Commit();
    is it possible to fix this?
     
    Last edited: Sep 16, 2012
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We need to identify the issue first. What happens when you do a Debug.Log("wäs") right before that line, and once from tk2dTextMesh.text? Are they the same / changed?
     
  25. Azuri

    Azuri

    Joined:
    Jul 23, 2012
    Posts:
    5
    I found the problem. It was not 2dToolkit related. I didn't save the file in the unicode format.
    sorry for the trouble and thanks for your help :)
     
  26. YourUncleBob

    YourUncleBob

    Joined:
    Jun 11, 2012
    Posts:
    55
    I can't figure out how to get the 2D toolkit to support additive blend with premultiplied alpha. If I understand it correctly, for an additive premultiplied alpha blend, you want something in RGB and 0 in A. If I tell the 2D toolkit that my atlas uses premultiplied alpha it premultiplies alpha for all of my textures, so there's no way I can have a texture with 0 in alpha and anything other than 0 in RGB.

    Is there a way to tag an individual texture so that it doesn't get auto processed by the premultiply alpha step?
     
  27. YourUncleBob

    YourUncleBob

    Joined:
    Jun 11, 2012
    Posts:
    55
    Ok, perhaps the additive checkbox right there on the texture. Don't know how I didn't see it. I went looking through the code and saw it was being done before noticing it on the texture settings screen.
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad you found it. If you have any suggestions on making it clearer, I'll be happy to hear them. This doesn't seem to be a widely used feature, though we do use it extensively.
     
  29. YourUncleBob

    YourUncleBob

    Joined:
    Jun 11, 2012
    Posts:
    55
    Nope, don't know how I missed it.

    The only thing I did struggle with was figuring out what format the source texture should be in. I couldn't find it documented so had to dig through the code.

    It looks like the expectation is that the source texture has its alpha set to one. The code then forces it to zero. I was giving it a texture with alpha already set to zero. The texture code still does a premultiply with the alpha before forcing it to zero, so I ended up with no visible pixels.

    What I was hoping for was a flag to just skip the texture premultiply processing so that I could setup the alphas externally. This would allow me to have a single texture with some additive and some normal pixels.

    I just modified the code locally to do the processing I want. It might be worthwhile to have an enum instead of a bool (or a second bool I guess, to keep from breaking any existing data) for the additive setting so that you could have more flexibility with how the premultiply was handled. Now that I've seen how the additive works, it's certainly easier to setup fully additive textures your way. I just have 1 texture currently that combines additive and normal pixels that needs to have the premultiply processing entirely skipped.
     
  30. brain56

    brain56

    Joined:
    May 18, 2012
    Posts:
    4
    Noob question. Haha. I'd like to extract the tk2dSpriteCollectionData from a given tk2dSpriteCollection. How do I do this? I can't seem to find any methods related to this. Thanks!

    I posted this question at the 2D Toolkit forums but no one's replying. :(
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    Hey I've replied to this on the 2D Toolkit forums.
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I found it hard to explain to artists how to create properly premultiplied textures with additive built in. I had a hack in there at a time, where you put in two images, one normally blended and the second as an additive overlay. The build simply processed the 2 images and formed one final premultiplied sprite which it used for the rest of the process. It was easy to use and behaved reasonably predictably, but it never made it in for one reason - the user could put in 2 images with different dimensions. Maybe I should put it back in with a #define or something.
     
  33. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    @unikron can you add version number to the name of readme file on root.i want to understand which version of 2dtk on my project. i always delete and reimport to update an asset Store product.

    also i get this error when i try to import package. how can i correct this error?

    invalid sprite sheet
    Sprite sheet 'explosion_44FR' doesn't match tile count.
     
  34. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    @unikron i have 2 folders in my project. Atlases and Images. i generated a spritecollection from into Atlases folder using images in the Images folder. i copied both folders to another project. i select spritecollection and click open editor editor. it opens an empty spritecollection. can not i reuse my spritecollections?


    Edit: Export package/import package solved my problem :)
     
    Last edited: Sep 20, 2012
  35. YourUncleBob

    YourUncleBob

    Joined:
    Jun 11, 2012
    Posts:
    55
    Yeah, that took some doing. It definitely isn't intuitive. Merging the two textures when building the atlas is a lot more straightforward. I'd use it here if it were available (with the understanding that the textures need to be the same size).
     
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Renaming files isn't really possible with unitypackages (which the asset store uses), and neither is deleting them, so there isn't really a practical way to do this. Eg. if I create a new file every time, you'll be left with loads of orphaned files left over - its just how the unitypackages work.

    About invalid sprite sheet - that bug has been fixed and will be in the next version. It is from a demo file, so it is probably safe to ignore unless you want to see that demo.
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Never copy files between projects - unless you have meta files turned on. Its best practice to just use unitypackages though, as you've found.
     
  38. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    as you said with package update it is not possible to delete outdated/unwanted files. some products suggest to delete all for old version and reimport it because there can be delete requirement. so i always delete folder and reimport it. unfortunately on unity there is no auto notify/update function.

    at least can you add version number inside readme.txt?
     
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hmmm... reply didn't get posted.

    I'll add it in a future version, it must be kept in sync with the main system, otherwise it'll be pointless - I need to add some deployment scripts to sort this out.

    Anyway you can view the version number by looking at the "2D Toolkit > About" menu.
    You can also find it in the following file: TK2DROOT/tk2d/Editor/tk2dEditorUtility.cs

    Hope that helps for now.
     
  40. DavidS

    DavidS

    Joined:
    Aug 19, 2012
    Posts:
    30
    Hi,

    I am using Toolkit 2D and have some questions.

    If I am creating a sprite collection, and if there are to many sprites or one sprite is to big, it tells me: Unable to fit in atlas. However if I select ‘Point Sampled’ then it works in some case. What does ‘Point Sampled’ do? Should it be used for iPhone and iPad devices?

    Further, what is the max. allowed ‘Atlas’ size for the iPhone/iPad device to be used.

    Is it better to use e.g. 2 big atlas instead of 4 small ones or vice versa?

    Last question, is it better to put sprites for a level in one atlas, and sprites for the other level in a different atlas, or can the sprites of both levels be mixed in those two atlas; does it matter? Is there any difference in performance?

    Thanks!
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Point sampled doesn't interpolate pixels, i.e. when you upscale the image, you will still see the pixels in there. This means that you won't need padding pixels around the original texture to display correctly. When you don't tick this, some padding will be added around the individual images comprising your atlas, which is why it sometimes fits when you turn it on. Either is fine, depending on your needs - if you're going for a pixelated look, then use point sampled.

    The max allowed atlas sizes vary with different devices. In iPhone 3G its 1024x1024, on iPad3 its 4096x4096. If you don't care about iPhone3G, 2048x2048 will be a good number to go for.

    About your last question, the answer is "it depends". If you use one image out of an atlas, the entire atlas will be loaded in. If you're tight on disk space, but not on simultaneously loaded textures (i.e. RAM), then you can share like you described. If not, try to keep all content from a level in an atlas for best batching performance. Sprites from different atlases wont batch, and the rules for this are basically "sort by distance from camera first, and then group same textures". Try to keep everything in one atlas, but if you need more, try to group spatially related bits together. Eg, all background elements, all foreground elements, animated characters, etc.
     
  42. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,151
    @unikron I have an empty face and eyes sprites. these are transparent png from a real photo. when i place eyes on face i can see eye border has problem like jpeg compression noise. when i select point sampled this noise disappear but this time it is like pixellarized. what should i do for transparent compositions with sprites having smooth borders?
     
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hard to say what this is - send me a screenshot to support@unikronsoftware.com and I'll try and work out what it is.
     
  44. DavidS

    DavidS

    Joined:
    Aug 19, 2012
    Posts:
    30
    Hi,

    Thanks for the detailed reply. I have one last question regarding this.

    In an atlas I combine the BG, the enemies, items, etc. for a level. In the next level I would have the same enemies, same items, etc. except the BG would be a different one. Would it be best approach to:

    1) Making a big atlas for one level, which would have the enemies, items, etc. and the BG. Then making the next big atlas for the next level which would have the same enemies, same items, etc. (as the atlas before) except the BG would be a different one.
    or
    2) Creating a smaller atlas for all enemies, items, etc., used in both levels; and create two smaller BG atlas one used in one level and the other one in the other level.

    A similar question regarding the BG. If the BG is put together using different sprites, but only some BG sprites are changed in the levels, the other sprites are used for all the levels. Would it be best to:

    1) Doing a bigger atlas for each level, having in it one larger BG sprite (all the different BG sprites for the level in question are combined in one big sprite).
    or
    2) Creating a smaller atlas for the different BG sprites that are used in all levels; and create another smaller atlas which holds only the BG sprites used for the level in question.

    Thanks!
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This really depends on many different factors - how many levels you'll have vs how CPU limited you are.
    1. This will reduce draw calls at the cost of disk space
    2. This will reduce disk space at the cost of increased draw calls.

    For the background, I think option #2 would be best as the balance would be pretty good - 2 draw calls (more or less) for all background.
    If you can fit all your enemies, items and stuff into a third sprite collection, then that would work well.

    Again, this is just a suggestion, I don't know what your game is like and what bottlenecks you''ll run into. Its a sensible place to start though.
     
  46. liven410

    liven410

    Joined:
    Dec 23, 2010
    Posts:
    36
    Hi Unikron,

    I need help related to make a game UI (using tk2dcamera or any other technique), to work perfectly on various many resolutions, like iphhone 3gs, iphone 4, ipad2, andorid small wide, android big wide, mac with all various many resolutions.

    To try out this. What i did is:-
    1) I created a scene for iPhone wide (i.e 3GS) 480wX320h, created a sprite altas with few sprites (two buttons, one character, etc). And set the sprite collection to use tk2D camera.
    2) now, when i create a sprite and press 1:1 button it gets scaled up and looks bad. so i leave it as it is, as just created by tk2dSprite.
    and its looks good and works pixel perfect on iphone 3gs. Great
    3) Now, i run the same without any change on iphone 4, and as expected, the UI do not scales it remain at the same resolution for 3gs.
    4) Now, i add a resolution overide for iphone 4 (giving width: 960, heigh: 640, scale: 2). i.e I double the scale for a 2x resolution.
    And wondered it again worked great. Not pixel perfect, as the sprites were of low resolution, but still it look great. Atleast workable.

    Question:
    So, now the simple question is , do i have to add a resolution overide for each and every resolution, setting scale to 0.5, then 1 then sometimes to 2 or 4. Its something, not a good options, Am I right!. for ios you can set resolution overide for 3gs, 4s, ipad2, its okay.
    but in case of android and mac, there are lot many resolutions.

    So, please suggest me some best work out on this issue. That can make development fast, give better graphics on each resolution and at the same time not dropping the performance.

    Many Thanks :)
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    1. With regards to "pixel perfect", you are expecting a blocky look when upscaled, correct? On the sprite collection, go into Settings, and tick Point Sampled and Commit. Now your #4 should look sharp (but pixel doubling, obviously).

    For other resolutions, you should try the default "Resolution override", with Width = -1, Height = -1, Auto Scale = Fit Visible, and Fit Mode = Center. This should automatically fit and center your content on whatever resolution its displayed at. This might not be perfect, as if you were scaling to oddly scaled resolutions, it will scale to fill the screen.

    You can mix and match Overrides - so add all your default ones so they look good, and the very last one should be a Wildcard override and it will catch anything that didn't pass the previous criteria.
     
  48. liven410

    liven410

    Joined:
    Dec 23, 2010
    Posts:
    36
    Hi Unikron,

    You have the best support. I did not expected this much of a quick reply. Appreciate very much. :)

    Well, thanks for the "point sampled" information. I didn't knew it before. great.
    But, about the default "Resolution Override". Can you pls give more details, step by step something.
    What i am doing is I set the Resolution overide size to 1 (by default it was 0)
    then, i entered in the 'Width' = -1 and 'height' = -1 and for 'scale' what should I enter?
    How can i set scale = Fit Visible and Fit Mode = Center?

    Also, pls explaing your last two lines "You can mix and match overrides - so add all your defualts"
    and "Wildcard overide" how to do this.

    Many thanks :)
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    What version of 2D Toolkit are you using? If you're not on the latest, I suggest updating. A newly created resolution override is given -1, -1 dimensions, and is called the Wildcard Override. This will match all resolutions. You will also need to set up the native resolution 480x320 in there.
     
  50. liven410

    liven410

    Joined:
    Dec 23, 2010
    Posts:
    36
    Hi Unikron, I am using 1.7 . I did not updated to latest beacuse i don want to get in any trouble related to my sprites, assets or camera settings.
    I also have NGUI in my project, coz i started someting with it so to avoid re-work i am using both. Other than this i have Gamecenter and inapp package as well.

    So, the question is if i update, is there any hidden or visible possibility that will affect any of the other packages?

    Many Thanks :)