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

ex2D - the best 2D sprite solution for Unity [RELEASED]

Discussion in 'Assets and Asset Store' started by johnny_karas, Aug 24, 2011.

  1. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
    Very nice! Whats the ETA? :p
     
  2. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi duke,

    The v1.2.0 will be coming out this week.

    What nantas shows, is a basic GUI rendering tool, it can draw scale9grid sprite use the texture from ex2D atlas. It can place and resize these sprites in the scene easily. It provides user a good way to form their GUI system.

    We do have a plan in developing a full GUI framework which including animation, event handling and provides different GUI control directly for user. But we heart that Unity v3.5 have a new GUI framework. And we would like to see if the new GUI framework fulfill the demands. So we are hang on the GUI developing until v3.5 released. After that we will discuss if continue developing our own GUI add-on.
     
  3. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    The atlassing in ex2D is fantastic.
    I'd like to use it to atlas my textures with a similar workflow:
    drop the texture in the material and if it belongs to an atlas, point to the atlas instead and change the uv range for you.
    Do you have that ?
     
  4. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    Hi,

    Do you mean you want this texture tracking behavior to work for Unity mesh renderer component?
     
  5. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Exactly.
     
  6. AirCooled

    AirCooled

    Joined:
    Aug 31, 2011
    Posts:
    6
    JWU, can you tell us about your ex2D tilemapping? Will it also be in your 1.2 release?!
     
  7. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi llavigne,

    Since the texture tracking is a special code I designed for sprite, it is difficult to make it working for Unity's Material assignment.
     
  8. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi AirCooled,

    The TileMapping will be an Add-On of ex2D, and it is still not stable enough for us to sell it. So it will not included in 1.2 release. We aim to release a free beta version in the middle of October.
     
  9. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    The white around transparent texture, you can get rid of it by saving as PNG instead.
     
  10. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I am sure it is not trivial but so so so powerful.
    If the complexity comes from the UI (how to display the material), the simplest way is no UI : the code looks up materials, find the textures, looks them up in the atlases and then does the same replacement + UV coordinate work as your script but on generic shaders.

    In fact I think all your code can be generalized and the mesh generation separated. For instance today I wanted to do a manga mouth and I UV mapped the head to hold that texture, same for the eyes. Then I realized what a pain it will be to animate. If your scripts could be used for that purpose, imagine the power (pawa).
     
  11. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    I'm trying to get my sprites to fade in and out using iTween, but it's not working as expected. If my sprite component's alpha value is equal to 0, the sprite won't appear at all (as expected). However, if the alpha value is anything above 0, it will display at full opacity; there's no gradual fade in or fade out effect.

    Here's my code:

    Code (csharp):
    1. void FadeIn()
    2.     {
    3.         iTween.ValueTo( gameObject, iTween.Hash(
    4.                                                 "from", 0.0f,
    5.                                                 "to", 255.0f,
    6.                                                 "time", time,
    7.                                                 "delay", delay,
    8.                                                 "easetype", iTween.EaseType.easeInOutSine,
    9.                                                 "onupdate", "SetAlpha",
    10.                                                 "oncomplete", "FadeOut" ));
    11.     }
    12.    
    13.     void FadeOut()
    14.     {
    15.         iTween.ValueTo( gameObject, iTween.Hash(
    16.                                                 "from", 255.0f,
    17.                                                 "to", 0.0f,
    18.                                                 "time", time,
    19.                                                 "delay", delay,
    20.                                                 "easetype", iTween.EaseType.easeInOutSine,
    21.                                                 "onupdate", "SetAlpha",
    22.                                                 "oncomplete", "FadeIn" ));
    23.     }
    24.                                                
    25.     void SetAlpha( float newAlpha )
    26.     {
    27.         spriteComponent.color = new Color(spriteComponent.color.r,
    28.                                           spriteComponent.color.g,
    29.                                           spriteComponent.color.b,
    30.                                           newAlpha);
    31.     }
    SetAlpha() is receiving the correct values (newAlpha is interpolating as expected). But I'm not seeing the fade in/out effect.

    Any idea what I'm doing wrong? :confused: Thanks for the help :)
     
  12. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi bdjones,

    You need to turn the Use Animation Helper ON (in the sprite Inspector) to make the properties in sprite can work with iTween and Unity's Animation
     
  13. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi llavigne,

    It is a great idea. However, based on our task and milestone, I'm really don't have time to look deep into this and see if it is possible to use our own material assignment instead of Unity's. So I put this in my backlog list and once I have time, I will seek on it.
     
  14. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    Hi jwu
    Thanks for replying

    > "08 - demo_sprite_animation_helper.unity"
    yes! exactly. I forgot the sample had blinking.


    Hi, nantas

    >Do you mean you want to have 3 different sets of running animation and each has a different outfit color? Then you want mix them up in a >single running animation when your hero is charging up or has power up?

    Yes. I wanna mix 3 or more animation.
    I will create charging animation.

    >I think you can try the mixing with Play(string_name, int_index) and GetCurFrameInfo ().
    ok I'll try
     
  15. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297

    GREAT! I din't see that until now!

    The major problem is create one camera for each necessary item with cooldown effect, but THANKS a lot!
     
  16. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    There is some way I can rebuild all my prefabs? without one by one and click in rebuild? I try that but don't work:

    Code (csharp):
    1.  
    2.  
    3.     [MenuItem("MonsterJuice/Utils/Rebuild Ex2D Prefabs") ]
    4.     static void Execute()
    5.     {
    6.         foreach ( Object o in Selection.GetFiltered(typeof (Object), SelectionMode.DeepAssets))
    7.         {
    8.             if(o is GameObject)
    9.             {
    10.                 GameObject go = o as GameObject;
    11.                
    12.                 RebuildAllChilds(go);
    13.             }
    14.         }
    15.     }
    16.    
    17.     static void RebuildAllChilds(GameObject pGO)
    18.     {
    19.        
    20.         if(pGO.GetComponent<exSprite>())
    21.         {
    22.             //pGO.GetComponent<exSpriteUtility>.
    23.             pGO.GetComponent<exSprite>().Rebuild();
    24.             Debug.Log("Rebuild "+pGO.name);
    25.         }
    26.         if(pGO.transform.childCount > 0)
    27.         {
    28.             for(int i = 0; i < pGO.transform.childCount; i++)
    29.             {
    30.                 RebuildAllChilds(pGO.transform.GetChild(i).gameObject);
    31.             }
    32.         }
    33.        
    34.     }
    35.  
     
  17. AntLewis

    AntLewis

    Joined:
    Feb 2, 2010
    Posts:
    254
    Hey - just to report a bug ( I think).

    When I instantiate an object that has a sprite object and uses layer2D, it's Z value was often slightly inaccurate compared to what I set it to (when I turned off layer2D, all objects instantiated at exactly the position I set them to). The problem got worse with successive instantiations - for example the undesired z offset of the 5th instantiated object was larger than the 1st instantiated object. Are you aware of this bug? Thanks, great job!

    Note that my layer and bias were all equal.
     
    Last edited: Sep 27, 2011
  18. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello badawe,

    I read your code, it looks like it works for your selecting prefab. The rebuild button currently will not accept changing prefab I doubt. I thinking about change this.

    My purpose to disable prefab rebuilding is because it didn't generate mesh. But looks like this also disable atlas changes and things like that. I will change the code so it only skip rebuild mesh when it is a prefab.
     
  19. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi bishylewis,

    Is this happend in a running Game or the instantiate you mean is when you editing scene, you drag drop a prefab?

    If this is in a running Game. When you instantiate a sprite (with layer), you need to do the following code:

    Code (csharp):
    1.  
    2. prefab = GameObject.Instantiate( .. );
    3. exSprite sp = prefab.GetComponent<exSprite>();
    4. sp.layer2d.RecursivelyUpdateTransformDepth ();
    5.  
    Because the instantiate you do will pass a position which will make the game object not set in right depth of layer.

    If you are drag drop in a editor. Please do Alt + Command/Ctrl + l ( or Menu -> Edit -> ex2D -> Update Scene Layers ). Which will adjust all sprite to the right depth position.
     
    Last edited: Sep 28, 2011
  20. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    ex2D v1.2.0 is now available in the Asset Store!

    check the fixes, changes in the first Page
     
    Last edited: Sep 28, 2011
  21. Seokho

    Seokho

    Joined:
    Aug 31, 2011
    Posts:
    23
    Wow realease version!! Great!!
    Thank you~
     
  22. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    This Unity3.4.1 keep crashing all the time with me, i cant event open the Unity.

    Keep give me some crash, unexpected errors ans stuffs like that, someone know what is going on?



    The only way i can open my project is using this:


    But i can't open my old project!
     
    Last edited: Sep 28, 2011
  23. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I use Windows 7 and not a mac, but recently I had loads of problems with Unity crashing on start up, and when Unity auto compiles my scripts.

    I've since uninstalled my antivirus program and I cant remember the last time Unity crashed.

    Are you sure this is an ex2D related crash?
     
  24. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi badawe,

    Can you send me a package that crashed in Unity3.4.1 or something? We test v1.2.0 in both u3d 3.4.0 and u3d 3.4.1 but didn't meet crash problem. Is there a way to reproduce it? For example, if you create a new project and ex2D in U3D 3.4.1, will it still get crashing?
     
  25. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I'm currently using ex2D without using any animation. I'm using a lot of separate images for my gameobjects. What's the best way to optimise this?

    I read above that I should group the same sprites on the same Z axis to reduce draw calls, but I was also wondering would it be beneficial to make a bigger sprite sheet and use sections of that for my sprites? Does ex2D do this automatically already?
     
  26. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    There's two ways to arrange your non-animated sprites:
    1. You can store all images in a single SpriteAnimClip asset, and use exSpriteAnimation.SetFrame to switch the images.
    2. You can create a SpriteAnimClip asset for each individual image, and switch them by calling exSpriteAnimation.Play().

    Of course the 1st way saves you a lot of work but the 2nd way is better organized (you call the animation by asset name instead of magic number), and easier to expand. ( in case in the future you want to add animated frames for each image) So it all depends on what you plan to do and how many different images you plan to have.

    Regarding your second question, yes you can create sprite sheet to contain as many textures as you want (as long as they fit into the size). If all your sprites in the scene shares the same texture there will be only one draw call needed. (as long as there's no non-uniform scale for any of your sprite's transform component.)
     
  27. fued

    fued

    Joined:
    Sep 30, 2011
    Posts:
    3
    is ex2D set up for me to create sprites in the script, and then set up all details (which texture/position/size/layer) to use?
     
  28. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi Biggz,

    Just like Nantas explain to you. And I think what you expect more is a dynamic atlas in the runtime by section isn't it? Doing this is extremely slow in Unity and in Mobile device, I can't find a way to create dynamic buffer in GPU for texture writing in Unity. Plus a big texture sending each frame can still cause performance drop down I doubt.

    Hi fued,

    Can you explain this with more details? Basically when you create a sprite, you are free to assign texture, scale, layers. And if you make it as a prefab, you can save those value to asset.
     
  29. fued

    fued

    Joined:
    Sep 30, 2011
    Posts:
    3
    can i create a sprite object in the editor, pass that through to a script object, then using that script object/sprite object, close it and create multiple sprites in different locations on the screen?

    e.g. i have a button image, i create it as a sprite attached to a gameobject, i then pass that gameobject to the script, and need to populate the screen with 10 different buttons in different locations.
     
  30. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi fued,

    I think what you need is a prefab. So you first create this sprite and gameobject, drag it to the Project Window to create a prefab. Then in the script you reference this prefab then write the code:

    Code (csharp):
    1.  
    2. public exSprite spritePrefab;
    3.  
    4. void Awake () {
    5.     for ( int i = 0; i < 10; ++i ) {
    6.         GameObject.Instantiate ( spritePrefab, Random.UnitCircle * 100.0f, Quaternion.identity );
    7.     }
    8. }
    9.  
     
  31. fued

    fued

    Joined:
    Sep 30, 2011
    Posts:
    3
    ah of course, still new to unity its strange after using sdl/xna lol thanks a heap :)
     
  32. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    jwu and nanvas! Any news about rebuild automatically rebuild prefabs?
     
  33. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi badawe,

    I've fix the bug and you can see the change log here: http://www.ex-dev.com/ex2d/wiki/doku.php?id=misc:change_log in Bug Fixes section.
    But I'm not sure I fixed it in your demand. I'll send you a quick fix to verify the things.

    I just test it, and when I change the atlas, it will also update the changes in prefab. So I guess this works in your request.
     
    Last edited: Oct 1, 2011
  34. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Workflow improvement :
    setting the size of a sprite isn't easy because if you don't work in the scale they come in naturally, which is one unity unit per pixel, you end up with scales of 0.01 which can't be dialed with the mouse

    So I was thinking of this : auto convert the object's transform.scale into sprite scale
    For example if the sprite scale is 0.1, I scale the sprite in the scene view and the transform.scale becomes 2.35
    you click on Windows>ex2d> Normalize Scale and transform.scale becomes vector3.one and that scale is transferred to the sprite scale which becomes 0.235
     
  35. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi llavigne,

    This is a good idea to verify draw-call issues and advice user a better way. Let me try to implement it.
     
  36. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Can you send me again? In the email i receive didn't come with attachment!
    And can you make this work on unity 3.4.0?
     
  37. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi badawe,

    Currently all of my machine are installed u3d 3.4.1 so I didn't test it in 3.4.0. But based on the changes in 3.4.1, I guess the fix should also works in 3.4.0 without problem.
     
  38. imphenzia

    imphenzia

    Joined:
    Jun 28, 2011
    Posts:
    413
    Just bought it but I may be confusing things. I was hoping to use the bitmap font feature as a HUD and Menu system in my otherwise 3D environment which does not use an orthographic camera... What would be the best way to go about setting up ex2D so I can use it for the bitmap font feature?

    Ideally I'd like to create my font in BMFont and then modify it in Photoshop. Then I'd like to be able to use the font similar to normal GUI.Label and GUI.Button but rendered with ex2D and the custom font instead.
     
  39. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi imphy,

    I think you are free to use sprite font in your 3D game. So here is the topic and documentation about it:

    Font Editor
    Create Sprite Font
    Sprite Font Component
    2D Screen Coordination System
    Render In Pixel Perfect

    In general, I assume you already learn how to create bitmap font in ex2D from BMFont. It is free you change something in the photoshop, so you only need to set the bitmap font to pixel-perfect size in your Game, and use screen space which provided in ex2D render your font to the screen.
     
  40. imphenzia

    imphenzia

    Joined:
    Jun 28, 2011
    Posts:
    413
    Hi jwu,

    Thanks for your suggestion and links. I've tried to follow it but it appears as if Transform 2D = Screen, anchor, and Screen X/Y position configured for the Sprite Font object has little to no effect on where the text is positioned in relation to the camera.

    With the settings: Transform 2D = Screen, Ex Screen Position Screen X = 0 and Screen Y = 0) and anchor lower left, Camera = Main Camera, Use Pixel Perfect enabled...

    I would expect that my Hello World text should appear in the bottom left corner of my camera view, but it's still sitting near the middle of the screen?
     
  41. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi imphy,

    We just fix the ScreenPosition bugs in Perspective camera. This fix will included in ex2D v1.2.1 which are still under developing.

    We have a daily build that can help customer in emergency. So would you mind PM me your E-Mail address so I can send a daily build version if you bought the product.
     
  42. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    ex2D Documentation Updated!

    A beautiful theme and nice width for reading document.d nice width for reading document.

    Check it: http://www.ex-dev.com/ex2d/wiki
     
  43. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    It works so well ! Thanks !
     
  44. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Regarding Scale9Grid, it's fantastic to have it in, so useful !
    But as an artist I hate to not have a background to my window, or something more organic along the edges.
    So here is what I was thinking : an extension to s9g which repeats the middle section instead of scaling it. This way I can have my basket made of straw.
     
  45. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    regarding scaling, if you parent the sprites under a node and scale that node, it will not add draw calls !!
    Big surprise here
     
  46. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi LL,

    It is difficult to set tiling background in the center of s9g. I suggest you doing this by create another sprite which have the same size of the center, and put the tiling background on it.
     
  47. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Hi Wu,

    How do I tile a sprite ? entering tile in the material tiles the entire atlas
     
  48. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi LL,

    For tilling, those sprite must use the texture not in atlas, and yes entering tile in the material. The whole tiling method in ex2D is still under developing, and lots of things need to discuss.
     
  49. XxPleYxX

    XxPleYxX

    Joined:
    Jul 26, 2011
    Posts:
    41
    Hi jwu,

    Is there any way to change the texture of an exSprite at runtime?
     
  50. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi XxPleYxX,

    Yes, you can use exSprite.SetSprite( atlas, index ); change the texture.