Search Unity

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

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

  1. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    is not it possible to create and atlas sized 640x960? this is the size of my screenshots. when i create an atlas it makes it as 1024x1024 so i cannot use my 640x960 screenshots as an atlas texture. i think recreate an atlas or a sprite cost cpu. i am looking for an texture exchange solution.

    i examined sample #13. if there is no way to do it without coding sample #13 will solve my problem.
     
  2. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i cannot animate tk 2d camera orthographic size. i can animate this value on camera and tk 2d ui camera components added game object. is it normal?
     
  3. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    you are confusing the atlas size and the atlas target dimensions - the atlas texture may be even 2048x2048 but the sprites inside can be for 960x640 - to check your target height, go to the spritecollection settings - > target height.

    Atlas dimensions are always the power of 2
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The sprite from texture component will help if you want to do it without code.
    http://www.2dtoolkit.com/docs/latest/reference/sprite_from_selected_texture.html
     
  5. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Using the unity animator? Thats expected, as it can't animate properties - its a fundamental issue with the unity animation system.
     
  6. leissler

    leissler

    Joined:
    Mar 21, 2013
    Posts:
    18
    Hi,

    will it be possible to use animation states as in the video (http://www.youtube.com/watch?v=MoZlMGU99qk) starting at timecode 0:45?

    best
    Martin
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Not been tested, but I don't see why it wouldn't work (apart from animating sprites (changing sprites or tint) using that method, which won't work because Unity still can't animate properties).
     
  8. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    that's great thanks. it is easier than what i did; i created an atlas with single screen shot. atlas was 1024x1024. i changed atlas data uv parameters to read (0,0) to (1,1), then i changed material texture. sprite from texture looks better.
     
  9. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166

    unity animation can animate all float features. i removed tk2d camera and just used unity camera and it worked. maybe i did something wrong and it will work next time i try. sometimes playing game updates something. so after every change i should play and see the result.
     
  10. EvilNoodle

    EvilNoodle

    Joined:
    Nov 17, 2011
    Posts:
    31
    Hey,

    Me again - sorry to be a pain!

    I have two layers in my tile map and I have some particle effects that I really want to sandwich between them. It seems that this does not work as depending on where I put the effect in world space it either renders in front of everything or behind everything rather than between.

    Any ideas on how to achieve this?

    I know I 'could' use multiple tile maps instead of layers to achieve this but for the map size I am using I don't know if this would perform better or worse than layers.

    Edit: Hmm it seems that I was being stingy with the layer offset. With a value of 1 I could not make this work but with layers positioned 10 apart it seems to be OK.

    Cheers

    EvilNoodle
     
    Last edited: Oct 21, 2013
  11. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Its down to what Unity thinks the origin of the particle system is. You can probably work it out from renderer.bounds if you get stuck again. Glad you've got a workaround for now.
     
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    It animates the float backing variable, but not the property. All of these things use properties to avoid having an update loop on everything to detect changes. Thats why you probably see a change when you press play. The normal unity components have some internal thing to let them be animated, but it isn't possible on user defined components. Basically - you can't animate properties but you can animate variables on user written scripts.
    AFAIK there isn't any workaround for this, apart from an update loop.

    But incidentally, the tk2dCamera updates in LateUpdate.
    On the tk2dCamera, you should be able to animate the zoomFactor variable to zoom the camera in and out.
     
  13. TerraCo

    TerraCo

    Joined:
    Jun 8, 2013
    Posts:
    26
    Hi Unikron,

    I am having difficulty with the Lit shaders that come with your pack. They apply and function correctly to sprites but I can't get them to react with light when applied to tile maps.

    Is there a way to get tile maps to react with lighting in the scene?

    Cheers,

    TerraCo
     
  14. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    In the current public release, the tilemaps don't calculate normals - mainly for speed. If you need normals built, add the line in bold to tk2dTileMapBuilder.cs -


    chunk.mesh.RecalculateBounds();
    chunk.mesh.RecalculateNormals();
     
  15. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    i tried to change texture with code after i created it on editor. it does not update sprite. i looked scripting reference and could not found info about spritefromtexture class; http://www.unikronsoftware.com/2dtoolkit/doc/2.00/html/annotated.html.

    what should i do to update view?

    Code (csharp):
    1. var spriteFromTexture = screenSprite.GetComponent<tk2dSpriteFromTexture> ();
    2. var sprite = screenSprite.GetComponent<tk2dSprite> ();
    3. spriteFromTexture.texture = wwwTexture.texture;
    Edit; it worked like that. is this usage ok? is there any better way?

    Code (csharp):
    1. var spriteFromTexture = screenSprite.GetComponent<tk2dSpriteFromTexture> ();
    2. var sprite = screenSprite.GetComponent<tk2dSprite> ();
    3. sprite.CurrentSprite.material.mainTexture = wwwTexture.texture;
     
    Last edited: Oct 23, 2013
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Normally there will be a better way to switch, but since all your images are the same size, screenSprite.renderer.sharedMaterial.mainTexture = wwwTexture.texture;
    will be sufficient, and the most efficient thing to do. Geometry doesn't need to be rebuilt if the sprite dimensions are the same.
     
  17. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    what is this better way? maybe i will need it in future.

    also do not you sleep? you are always ready here to answer questions.
     
  18. chillypacman

    chillypacman

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

    After updating my project to the latest versionof Unity I've found my sprites have started to look broken, I uploaded a screenshot to show you what I mean: http://i.imgur.com/009oAUZ.png and this is how it used to look: http://a1.mzstatic.com/us/r1000/061...b42075/mza_3265083799329769318.320x480-75.jpg

    I've tried rebuilding the sprite sheets but that hasn't worked...


    edit: *nevermind I fixed it by changing shaders from premulvertex to blendvertex


    edit 2: unfortunately it still looks broken (in the same way) when I compile and run it as a windows store app...
     
    Last edited: Oct 23, 2013
  19. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    What version of tk2d, what version of Unity were you using, and what version did you update to?

    Also, what features of tk2d are you using on the atlas? Please email support at unikronsfotware.com with a bit more details to help narrow this down.
     
  20. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    This is better because it doesn't need to change the geometry, its much much quicker. If you need to change the size, use tk2dSpriteFromTexture.Create( tk2dSpriteCollectionSize spriteCollectionSize, Texture texture, tk2dBaseSprite.Anchor anchor ) to update it. This isn't documented yet.

    I have successfully cloned myself, so I can answer questions in different timezones :)
     
  21. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    2D toolkit is awesome! Our company uses it for many projects and it very user-friendly and versatile.
     
  22. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    I'm trying to fade out a sprite using the built in Unity animation editor. The property I'm targeting is the "Color" field in the "tk2dSprite.cs script. The animation seems to be running and I can see the color property in the inspector changing, but the game view doesn't appear to be updating. I did the same for the scale property and it was not working either, although the scale property in inspector was changing and I can see the gizmo handle box of the sprite in the scene view changing as well. Is this supported, or is there another way to fade out a sprite using the 2dToolkit? If I manually change then property in the inspector it shows up in the game right away (scale or fading), so it works in some ways.
     
  23. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    Nevermind, I just did a search and found a answer that you need to call Commit() because of how the 2dToolkit thing works for performance reasons with TextMesh or something and I need to write a adaptor behavior that mimics the color property and automatically calls Commit() for me every frame.
     
  24. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The issue with the Unity animation editor is that it can't animate properties, only values. In order to detect changed values, the script will need an Update function which will make things considerably slower. You can use an adapter script to do this - an example here.
    http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1604.msg11822.html#msg11822
     
  25. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    I got another issue I can't figure out. I'm playing around with the demo UI controls, and a camera. I followed this tutorial on how it is all set up.

    http://www.unikronsoftware.com/2dtoolkit/doc/2.10/ui/getting_started.html

    It uses a orthographic size of 1 for the camera, and the font used for the "BasicButton" control is part of a sprite collection. The sprite collection also uses a ortho size of 1, hence camera and sprite collection match up, and the button renders onscreen correctly. The issue occurs when I change the orthographic size of the camera to 4, and the ortho size of the sprite collection to 4 and hit commit. Now when the button renders, it renders fine with respect to be 1/4 smaller because of the ortho size change, but the text of the button looks like a jumbled mess. Then if I change the ortho size for both camera and sprite collection back to 1, and hit commit. The button renders fine again as originally in size, but the text for the button is still a jumbled mess, even though you would think I would have undone my changes in the first place. Now I'm thinking I need to update the font somehow, but looking at the sprite collection that holds the font, and trying to following the asset references leads me nowhere.

    Any ideas?
     
  26. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There was a bug in older versions that rarely broke the reference to the fonts when tk2d was upgraded. It wasn't 100% reproducible, but there is a fairly easy fix for it.

    1. Open up the sprite collection (TK2DROOT/tk2dUI_demo/Assets/SpriteCollection/UIDemoSpriteCollection, and if it isn't this skin, check TK2DROOT/tk2dUI_demo/Assets/Dark/UIDemoDark).
    2. Under the "Fonts" category on the left bar, you should see "Empty" there - this indicates that Unity has somehow lost a reference to the font. Click on it (there may be more than one depending on the collection you opened).
    3. Note that the BM Font slot will be Empty. This will need to be filled up again - the easy way to find it is, click "Font Texture". The thing that should go into the BM Font slot should be right next to the texture in the project window. Drag that into the slot.
    4. Repeat for the other broken fonts.
    5. Commit.

    That's it - the references need to be dragged back in again, commit, and once thats done the text should all fix itself.
     
  27. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    hello

    is it possible to programmatically get the collider for a particular tile ID in a tile map?

    what I mean is, when you've created a sprite collection for the tiles in a tile map it's possible to choose "Box Custom" in the collider type, then move around the corners of the collision box.

    is it possible to access this collision box somehow, for each of the tile IDs used in the tile map?
    $collider.png

    please say yes :p
     
    Last edited: Oct 26, 2013
  28. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Not with default behaviour - by default it simply merges as many colliders as possible to make one big one, back faces and inside faces are also removed. If you need the actual collider, you shouldn't merge those tiles - simply create prefabs for the tiles you need colliders for, and assign them in the data tab - they will remain as individual colliders then.

    Edit: If you only care about the positions - you can possibly get that info. Get the raw sprite id on the tile, and get the sprite from the tile map.

    tk2dSpriteDefinition def = tilemap.SpriteCollectionInst.spritedefinitions[ rawTileId ];
    Refer to tk2dBaseSprite.UpdateCollider() on how to get the boxcollider centre and size. Its not particularly pretty but straightforward.
     
    Last edited: Oct 26, 2013
  29. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    how can i use a compressed transparent image for a sprite? i use a transparent photo (it is a human photo and it is nearly half of my screen) in my main menu. i takes large area in my atlas. i also use some background images for my main menu. i try to reduce my build size.
     
  30. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    thanks, I think that works for me.
    nacho
     
  31. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
    How do you display scores, and other custom numbers, using the tk2dTextMesh system?

    I've tried:

    Code (csharp):
    1. textMeshGameObject.GetComponent(tk2dTextMesh).text = "Score";
    But it doesn't work and say Unknown identifier: 'tk2dTextMesh'.

    How do I access the 2d Toolkit text mesh system? Is it possible with JS?
     
  32. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Yes, you will need to set it up for JS first.
    http://2dtoolkit.com/forum/index.php/topic,33.0.html
     
  33. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    is it possible to apply gradient effect from bottom to top of line boundary. now it applies for current letter's visible area. for example "a" and "A" have not the same vision.

    Edit: does each different font means new draw call?

    Do you plan to add text fx like shadow, outline?
     
    Last edited: Oct 27, 2013
  34. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    I don't suppose there's support yet to export the tilemap we create in 2D Toolkit to a .TMX file, to use in Tiled? Would that be possible to add, or too difficult?
     
  35. BHS

    BHS

    Joined:
    Dec 21, 2009
    Posts:
    4,764
  36. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There isn't support, and no it wouldn't be too hard to add either. The main concern is that the sprite Ids would have to match the images in the TMX, and that isn't possible to guarantee in a generic way right now, which is why we didn't implement it with the import. If you'd like to implement it, I can offer some suggestions on how to go about it. Its considerably easier when you are in full control of the data.
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Not out of the box, it means changing the build code where the uv2 is calculated to clamp to line height. Its doable.

    If you create them as a normal font, yes. If you import into a sprite collection, then no.

    Not in the next release, but it has been requested a few times...
     
  38. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,166
    do you mean you will do it? :)

    how can i import it into a sprite collection?

    nowadays i decided to quit NGUI and use 2DTK UI system in my games. it will be nice to have similar effects here.

    Edit: at unity 4.3 RC 1 i get following error;
    tk2d Undo/Redo callback failed. Undo/Redo not supported in this version of Unity.
     
    Last edited: Oct 29, 2013
  39. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    That sounds good. Let's hear some suggestions. :)
     
  40. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Just change the lines where it gives LogError() to LogWarning() instead, until 4.3 is public and 2D Toolkit has support for the new redo/undo that Unity 4.3 uses.
     
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Maybe, but not anytime soon even if it did happen. I will keep it in mind when modifying code around it to see if I can fit it in if necessary.


    Check the docs here:
    http://www.2dtoolkit.com/docs/latest/tutorial/importing_a_font_into_a_sprite_collection.html

    We will be releasing a 4.3 compatible version in due time. Keep an eye out for a beta announcement soon.
     
  42. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    I noticed that when I can editing my tile map, and hit commit, it generates the tile map render data. What I'm trying to do is make the tile map + tile map render data, both children of a new gameObject called something like Map01. I then store Map01 as a prefab in my project for later loading. When I load Map01 dynamically during runtime, I expect the tile map and tile map render data to load correctly with all links in place. It was working initially, but now the tile map render data seems to have lost its data (tiles and collision data). So I basically drag my Map01 by into the hierarchy, delete the old tile map render data, regenerate it by hitting edit, then commit again on the tile map. Then I check the tile map render data to make sure my tiles and collisions are ok, then I drag the new tile map render data under my Map01 object, and update the prefab. But when I drag the prefab back into the scene hierarchy to do a sanity check, tile map render data seems to have lost all its data again. Initially when I set it up it was working, and now its not, so it seems inconsistent.

    Whats your process for storing the tile map and the tile map render data? What's wrong with my process?
     
  43. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    hello,

    do you plan on implementing animated tiles at some point?
    would be nice to have for things like lava/water tiles for example.

    thanks.
    nacho
     
  44. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The render data contains meshes. Unity doesn't save meshes, or anything that isn't a gameobject when you create a prefab. If you want to create prefabs out of tile maps, you should first update to the latest 2D Toolkit (2.2.3) - it changes a few behaviours with instantiating and destroying tilemaps. Only create a prefab from the tile map itself, ignore the render data. Dragging it in should create the tile map in the scene.

    Alternatively, you can set up multiple scenes with your tile maps in them, and then load scene additvely.
     
  45. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    At some point, yes :)

    The problem with animated tiles is performance - the perf updating the mesh every frame isn't good enough to be a general purpose feature - its far too easy to "break" it and end up with terrible perf. You can do it manually in a lot of few cases, but you'll need to run the animation timer manually. You can adjust the partition size to make it update more optimally.

    Alternatively, you can leave holes and have a water / lava sprite / plane behind it with an animated material - that will be really fast compared to modifying the tile map manually.
     
  46. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    ok thanks!
     
  47. sanjodev

    sanjodev

    Joined:
    May 29, 2012
    Posts:
    63
    I been trying out the camera overrides with aspect ratio, but noticed the code to check if aspect ratio doesn't seem to accurately match due to conversion inaccuracies. I noticed it when I was setting up aspect ratio override and was wondering why it wasn't taking effect. Then when I resized my game window up and down, I noticed in the inspector, it would show the override would become active briefly. Then I noticed when it was active, I just stopped resizing, and then it stayed active. By looking at the code and debugging it, the float calculations become pixel calculations, so error differences could be as much as a few pixels. I've tested 5 pixels as a error margin, and it seems to fix my issue though.

    case MatchByType.AspectRatio:
    float aspectTest = (float)(pixelWidth * aspectRatioDenominator) / (float)aspectRatioNumerator;
    return Mathf.Approximately(aspectTest, pixelHeight);
     
  48. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Cheers for that - I thought I'd covered that by forcing the multiply before the divide. Any ideas what resolutions it was failing on?
     
  49. hatem

    hatem

    Joined:
    Jul 17, 2013
    Posts:
    1
    How can I use Tk2d TextMesh to write: 10e-12.
    I Failed to found a solution to make 12 small and in the middle :(
    Can anyone help me ?
     
  50. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You'll have to implement it using 2 text meshes. Superscript isn't supported at the moment.