Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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
    Its probably because half texture size is set in the quality settings for iOS and not android.
    http://2dtoolkit.com/forum/index.php/topic,612.0.html
     
    game247org likes this.
  2. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    54
    Thanks for your answer. The texture quality was already on full resolution, so the problem still exists. Only the textmeshes are blurry, not the sprites. Do you have any idea how I can solve this?

    On some earlier versions of both unity3d and 2dtoolkit I didn't have this problem.

    Thanks
     
    Last edited: Mar 27, 2014
  3. chris200x9

    chris200x9

    Joined:
    Mar 22, 2014
    Posts:
    8
    I'm looking to make 2D menus very easily, the kind in an early final fantasy game can toolkit 2d do this?
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Try this -
    Find your texture (atlas texture in this case, maybe the source textures too) then click look at the texture size limits at the bottom of the inspector. Click on the iOS tab, is there anything mad set up in there? Unity 4.3 does some pretty crazy stuff when running in 2D mode, eg. it sets the texture to 16 bit for iOS and only that platform. Is there anything set up in there?
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    2D Toolkit doesn't come with any game specific UI examples, its more geared towards touch / mouse driven UIs.
     
  6. ThomasVandenberghe

    ThomasVandenberghe

    Joined:
    Feb 28, 2014
    Posts:
    22
    I'm currently looking for something to be able to bend my text. I assume there is nothing build in so I started looking around and found Mega-fiers. I'm just wondering if this would work well with the tk2dTextMesh or sprites, since every character is 1 quad. Has anyone worked with 2D Toolkit and Mega-fiers together?
    I know it probably won't work on sprites which are only 1 quad, but would dicing solve the problem?
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi there is nothing built in. I can't comment about megafiers as I haven't tested them together, but I vaguely remember someone saying something about conflicts with who runs first - i.e. since megafiers and tk2d modify the meshes, there could be some sequencing issue. If you want to implement this yourself, I can point you to the correct parts of code.
     
  8. ThomasVandenberghe

    ThomasVandenberghe

    Joined:
    Feb 28, 2014
    Posts:
    22
    Hi, so I've tested them a bit, and it indeed seems that 2d toolkit runs last. However I got it working at runtime by calling an update on megafier. I might have to do this every time I change my text, but haven't tested that yet.
     
  9. OceanBlue

    OceanBlue

    Joined:
    May 2, 2013
    Posts:
    251
    Hi
    I'm in the process of switching over from Unity 2d's sprite system (because, quite frankly, I think it's not very good/powerful) to yours, and so far I love it.

    However, I've noticed in the editor stats that there appears to be no batching when I run my scene. I have 94 draw calls, saved by batching 0.


    There are 16 actual sprites in my scene. I am using my own shader so that my sprites accept lights and cast shadows, and I have a few point lights and directional light in the scene (i'm using an ortho camera) - would this be it? Am I missing something in the tk2d process?

    Thanks
     
    Last edited: Apr 10, 2014
  10. Mr_Cad

    Mr_Cad

    Joined:
    Dec 7, 2013
    Posts:
    27
    I managed to get scrolling works with a list of buttons inside but what I couldn't make it work is although I have put a UIMask and it successfully masked the area that I dont want it to be shown but I noticed when I click on the mask area, the input still get to send to the button and the button still working eventhough it's not visible.
    How should I prevent the button receive touch event whenever it's not in visible area?
     
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287

    If nothing is saved by batching it is likely the lights. Try switching to vertex lighting in the project settings, it can help.
    Also check if gizmos is turned on in the game view. Unity counts those too when counting draw calls...
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Add a collider to the mask (it should already be there if you used the prefab) and make sure that the collider is occluding everything behind it.
     
  13. jgalvezpa

    jgalvezpa

    Joined:
    Dec 27, 2012
    Posts:
    36
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi, you will need to write some custom solution for the cutting of the images - they seem to have a border around the cut out areas. 2D Toolkit will help with most other areas but not that specific thing.
     
  15. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    Hello,

    I'm building a custom character controller for 2dtk's tilemaps.
    I ended up writing my own little collision system and simple physics.

    In order to make the character controller simpler I need to pre-process the tile data from the editor and flag tiles on specific positions of the tileMap with some attributes, which get stored as part of the scene and are used at runtime by the character controller for collision detection.

    These attributes are unrelated to tileIds, because you can have two tiles with the same tileId on two different positions of the same tileMap, and they may have different attribute values (or for example one of them might not have attribute values at all). So these attributes are added to specific tiles on a particular coordinate of the tileMap.

    Summing up:
    -I need to store a Dictionary in each tileMap which takes in an (i,j) coordinate pair and returns a struct.
    -I need to be able to call a Preprocess() method from the editor, which will populate the Dictionary.
    -The Dictionary needs to be somehow saved as part of the scene as well.
    -The Dictionary needs to be accessible at runtime.


    I'm pretty sure 2dtk doesn't support custom attributes on specific tiles, but how would you go around adding this functionality?

    I'm not sure if inheriting from tk2dTileMap to add the Dictionary as well as a Preprocess() method is a good idea.

    It might be better to put all this outside tk2dTileMap using a ScriptableObject or something like that, but I can't really tell because I'm not familiar with this kind of scripting.

    What do you think would be the best approach?

    Thanks!
    -Nacho.
     
    Last edited: Apr 18, 2014
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't serialise dictionaries in Unity, and it really doesn't sound like you need a dictionary here anyway, just an array of ints should suffice. You can keep that in a separate component to the tile map, and then populate that when the tile map is built. You can keep all this localised to your own component and only need to hook into the tile map system after building.
     
  17. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    ok, one more question, how would I know when the tileMap is built?
    how would I hook my Preprocess method into this?
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This function is where the tile map gets built -
    tk2dTileMap.cs -
    public void Build(BuildFlags buildFlags)
    {

    You can insert a callback to do what you need there.
     
  19. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    cool, thanks.
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  21. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    I was interested in using your BlendVertexColor shader on a regular MeshRender within my scene because of how it uses additive color. If I wanted to change the color of my mesh material in code similar to how changing the color on a sprite/slicedsprite, is it possible to do so by accessing a variable in the shader, or is it a bit more complicated than that?

    I tried both the usual methods to change colors on materials:

    material.color = Color.Red;
    material.SetColor("_Color", Color.Red);

    But neither of them seem to work, thus I'm assuming it's a bit more complicated than that.

    EDIT:
    It looks like getting the meshfilter and the mesh, then setting the mesh's color seems to do the trick. Though I'm not sure if that's the most optimized way of doing it.
     
    Last edited: May 2, 2014
  22. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Thats not the most efficient way to do things - its fine with a sprite when theres 4 vertices, but if your mesh has a large number of verts, this approach will be very inefficient. It will probably be more efficient to use a normal material, and MaterialPropertyBlocks on the renderer to set the color per instance. This will have to feed into the _Color property, and will likely break batching, but for any non-trivial number of verts this will likely be more efficient overall.
     
  23. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    For me the mesh is just a quad I use to fade the screen out to black, display loadscreens, and show comic cutscenes, so 4 vertices is all I'm using for now. It's definitely worth looking into a more efficient method for more vertices though.

    Sorry to ask this, but regarding "normal material", do you mean a normal map material, or do you mean normal as in the usual or plain material?
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If its just a quad, that mesh trick will work just fine.
    By normal material I mean one of the Unity materials, eg. Self Illum/Diffuse or any other material that uses the _Color parameter.
     
  25. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Why is tk2d overriding the max size of my textures? I quite deliberately set them to a smaller size!
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Because Unity sets the max size to 1024 by default, and its then impossible to import anything bigger by default. Its the lesser of 2 evils, and you can modify the source to change the behaviour if you prefer it the other way -
    tk2dSpriteCollectionBuilder.cs, IsTextureImporterSetUp and ConfigureSpriteTextureImporter
    Remove the test for importer.maxTextureSize < 4096, and the line that sets it importer.maxTextureSize = 4096;
     
  27. Danz112

    Danz112

    Joined:
    May 20, 2014
    Posts:
    39
    I reckon this is a bit of a newbie question, and I'm sorry for this.
    I was wondering if it's possible to make something like this with 2D Toolkit.
    I know that usually thin and long stripes are used to make the track though, and then through scripting they are moltiplicated. I'm not sure if I can use 2D toolkit and still achieve this.

    I am a very average programmer though, so I was wondering if I could have a suggestion if there is a way to still replicate the "depth" effect anyway - I'm referring to the fact that the track has a perspective like this.
    Basically my problem is that so far my track is flat - because if I made a tile with a diagonal line in it, the track itself will get narrow, while what I need to achieve is just the illusion of depth. Like in the last image.

    I also need to make hills and slopes and I'm not sure if I can achieve all of this :(

    Thank you in any case, and sorry if my question is quite generic and not easy.
     
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    If you really want to do this in 2D, yes I suppose 2D Toolkit could help. You'd have to create each strip of road (excluding the lines) as a sprite, then scale appropriately for the perspective distortion. Since every step is pretty fixed anyway, it should be fairly straightforward. It probably will be considerably easier to do the road itself in 3D though, sprites are fine for everything else.
     
  29. Danz112

    Danz112

    Joined:
    May 20, 2014
    Posts:
    39
    sorry, can you clarify me what do you mean by "lines" ? which ones?
    Sorry, I know this isn't exactly to place to get help with a game but nobody is giving me a hand anywhere else *sigh*

    This is also something I considered. But, it would mean I couldn't use 2Dtoolkit's camera and the tilemaps, I guess? I don't have unity at hand at the moment. I thought about using this one http://www.youtube.com/watch?v=yLi-Lp23j7Q maybe, especially for hills and downhills...

    thanks a lot for your help anyway, I wouldn't be able to move forward without understanding what I can and can't do unfortunately...
     
  30. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The road is constructed out of horizontally scaled pieces. Well, it was the scanline on the device, but at the original resolution (240 high, AFAIK) you can do this with thin sprite strips.

    What do you want to use tilemaps for? From what I can tell the roads curve quite a bit, and I can't see how you could build that with a tilemap. I strongly recommend learning how to create a custom mesh in unity and using that to create the road.
     
  31. Danz112

    Danz112

    Joined:
    May 20, 2014
    Posts:
    39
    Thank you for your answer again.

    Yeah so I tried to make some very thing stripes for the road and it worked, currently I am using 2D toolkit for the sprites + animations, and with Rotorz's system I was able to place the stripes respecting their dimension. Also, I could even rotate these "tiles" so I was able to make hills and downhills for example. Basically the 2D sprites are actually moving on Z axis.
    The reason is simple, it's that I can barely script.

    The problem, as you said, is that the roads do curve and I know that in the original games it was obtained with some kind of maths effects, while at the moment I could do it only by placing them as pre-made PNGs which isn't exactly the best.

    The main problem is that my sprites gets distorted if I rotate the camera even for a bit using the perspective one, so I think that the ortographical camera would be more suited to create the original "outrun-like" feel, but currently I do not understand how I can replicate the illusion of the narrowing of the road with that camera.

    sorry for my small wall of text :(
    I will also look into the custom meshes, thank you.
     
  32. someunityguy

    someunityguy

    Joined:
    Jun 28, 2011
    Posts:
    35
    Helping a student with his project but he his being held back by a error
    error CS1955: The member `tk2dBaseSprite.FlipX' cannot be used as method or delegate
    anyone know how to rectify this ?
     
  33. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its a property, not a method.
    i.e.
    sprite.FlipX = true;
    not sprite.FlipX();
     
  34. ChewyWaffles

    ChewyWaffles

    Joined:
    Jul 3, 2013
    Posts:
    5
    I'm having some major problems with the 2D Toolkit dialogs in Unity. Specifically, there are certain UI elements I can never see no matter how I reposition the windows. For instance, when creating a font sprite collection I get a message saying "A data object is required to build a font...etc etc" and apparently I'm supposed to see a "Create" button to the right of this message. I cannot see it, and no matter how much I resize the SpriteCollection window I am not able to see it. It's getting very frustrating to work with 2D Toolkit.

    edit: I pressed "UI > Fix Selected Item Bounds" in the 2D Toolkit menu and it fixed it? Hurray!
     
    Last edited: May 26, 2014
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    I'm not sure how you fixed it by clicking on that button - if the data object doesn't exist, it will not be accessible. If you're still stuck with this, email support at unikronsoftware.com with some screenshots - I'm not sure what is going on here.
     
  36. ChewyWaffles

    ChewyWaffles

    Joined:
    Jul 3, 2013
    Posts:
    5
    Thanks for answering. I meant that (for whatever reason) the "Create" button was not visible in the Font creation dialog in the SpriteCollection GUI. No matter how I resized it, it never showed up. Something I pressed (I assumed it was "Fix Selected Item Bounds" but I guess I was wrong) finally caused it to show up.

    On a different note, do the 1x, 2x, 4x platform-specific assets work with fonts stored in a Sprite Collection? How can I check to ensure that the proper font is being picked up when switching, for instance, to 2x through the 2D Toolkit prefs?

    edit: Ah, nevermind, I forgot to add platform support for my font sprite collection.
     
    Last edited: May 26, 2014
  37. mheydlauf

    mheydlauf

    Joined:
    Nov 1, 2013
    Posts:
    10
    Hello,

    I have 2 layers of background in my side-scrolling 2d game that are parralaxed. Each layer has its own spritecollection. All of the background elements are monochrome. My question is, what settings should I use when I create the background pngs, or settings I should use on the spritecollection to take advantage of, from a memory efficiency standpoint, the fact that my background sprites are monochrome?

    Many thanks,
    Mike.
     
  38. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You could try compressed for the background, it will be considerably smaller and might look acceptable. If the background is solid and doesn't require alpha, even better - compressed should pick DXT1 on pc which will be really quite small. You can improve quality by using a custom shader (mid grays in dxt1 look greenish), but see if its acceptable first.
     
  39. Eklavyaa1

    Eklavyaa1

    Joined:
    May 6, 2014
    Posts:
    3
    Hey Guys,

    I am developing a fast moving platformer game like Gravity Guy. in Unity . Using tile maps, I want to create multiple levels which would be loaded one after the other quickly in a seamless manner.

    But I am concerned if fast scrolling platform as in Gravity guy can be achieved using XML maps and reading them at runtime. Actually right now I am using an Open Source framework for same which allows me to create multiple maps and load them one after the other, but while loading a new map at runtime it causes lag and most probably this lag is due to in efficient way of reading the map files.

    So I want to know if reading the maps in 2D Toolkit can be quick , so that I can load them in run time without any lag.
     
  40. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It depends on how you load it. For a game like gravity guy you'd probably want all the sections prebuilt and loaded into memory. I personally wouldn't constantly creating and destroying anything unless its for a switching worlds or something like that, where you're loading in a second set of independent chunks. The tk2d tilemap system loads quickly, as the geometry is pre built before you press play. You can load in scenes using loadsceneadditive and thats fairly quick too (way way faster than parsing xml or whatever), but even that will probably hitch every now and then due to gc.collect - which is probably why you should try to manage this without any loading or allocation at runtime.
     
  41. Eklavyaa1

    Eklavyaa1

    Joined:
    May 6, 2014
    Posts:
    3
    We just bought 2d ToolKit :)

    If I am able to understand , I have to create one big level in one scene ? and as this level is about to finish I have to load another scene which is again one big level ? But in this case while loading the second scene it may take some time ?
     
  42. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes that is correct. Try to keep as much in one scene, just move them about to show and hide
     
  43. Eklavyaa1

    Eklavyaa1

    Joined:
    May 6, 2014
    Posts:
    3
    Ok thanks for support :)
     
  44. Eklavyaa

    Eklavyaa

    Joined:
    May 4, 2014
    Posts:
    17
    So I created two maps with big level and at the end of first map I loaded second map using Application.LoadLevelAdditive , but still there is little lag. Could not find loadsceneadditive in unity :(
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Sorry I did mean LoadLevelAdditive not loadsceneadditive. A little lag is expected with that, which is why you should stream using Application.LoadLevelAdditiveAsync. This will load the level in the background and not block while loading. If its still hitching with that, which may be possible - check the unity profiler to work out what the bottleneck is.
     
  46. MaxB

    MaxB

    Joined:
    Jun 13, 2013
    Posts:
    13
    I'm not seeing "Create > Clip" in the Sprite Collection editor window though all the tutorials say it should be there, is there a new workflow for creating animated sprites or am I missing something? (First time user)

    edit: Disregard, looks like it was a UI bug in Unity.
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Glad you've got it figured out . I've not heard any reports of similar so it could just have been a one off.
     
  48. Eklavyaa

    Eklavyaa

    Joined:
    May 4, 2014
    Posts:
    17
    Using Toolkit I painted a simple level in the scene.

    I scroll this scene from left to right , but while moving there is a jerkiness in the motion. I tried following ways to move the level .Some begin to work perfectly in unity player but not in iOS simulator :-

    Case a) Tile map created in the hierarchy does not have any rigidbody attached.

    a.1] moved by changing position directly , i.e. transform.position -= scrollLeftBy * Time.deltaTime; -> lots of jerk

    a.2] transform.Translate(newVector3(m_Velocity*Time.deltaTime,0,0)); -> no jerk in unity player , but still jerks in iOS simulator.

    Case b) Added rigidbody to the chunk of layer , isKinemtic=true. Velocity iteration : 8 and Position iteration : 3

    b.1] inside FixedUpdate / Update , moved using velocity , transform.rigidbody2D.velocity = m_Velocity; :- > jerks in Unity Player , as well as iOS Sim

    b.2] inside FixedUpdate / Update , moved using , transform.rigidbody2D.transform.position -= scrollLeftBy; :-> No jerks in Unity Player but jerks in iOS Sim.


    Moving script is applied to the chunk itself not to its parent .

    Please find video here , running on device

    Can you please guide me what I am missing ?
     
    Last edited: Jun 10, 2014
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You should not move the level, but rather move the player. The tilemap has complex colliders that are expensive to move. You should also wrap the player around after he reaches a certain point.

    E.g. assume that A B C and D are loaded tilemap chunks. P is the player.

    Code (csharp):
    1. A B C
    2. p
    3.  
    4. D A B C
    5.     p
    6.  
    7. C D A B C
    8.         p
    9.  
    10. C D E B C
    11.   p
    and so on. Basically you have a fixed number of paged tilemaps that dont ever move beyond instantiation. The player moves and wraps around after a certain distance, and you replace the chunks as you move forward.
     
  50. Eklavyaa

    Eklavyaa

    Joined:
    May 4, 2014
    Posts:
    17
    oh great !! , this is what I planned to try next , good to hear same thing from you :) . Thanks for descriptive answer.
     
unityunity