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

    Bertrand07

    Joined:
    May 21, 2012
    Posts:
    5
    Hi

    I'm trying to figure out how i can change, by script, texture image used in a exsprite object.
    I can use (SetSprite(Atlas, index, false), but it's not really interesting because everytime i add new texture in my atlas and rebuild it, the texture's index change.

    How can do that?
    Thank you!
     
  2. Bertrand07

    Bertrand07

    Joined:
    May 21, 2012
    Posts:
    5
    Or i can use "exSpriteAnimation.setFrame".
    But i don't know if it's the better solution...
     
  3. simone007

    simone007

    Joined:
    Oct 30, 2008
    Posts:
    221
    At runtime, you can get the sprite ID calling this method:
    atlas.GetIndexByName(textureName);
     
  4. robin_notts

    robin_notts

    Joined:
    Apr 7, 2010
    Posts:
    86
    Ex2D text often seems to have random jitter on the y position of each character. Is this a known issue? Any fix for it?
     
  5. Bertrand07

    Bertrand07

    Joined:
    May 21, 2012
    Posts:
    5
    Cool
    Thank you!
     
  6. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174

    Hey there Wu,

    That does help a little bit but it's still time consuming and annoying. When is v2.0 supposed to go live?

    Thomas P.
     
  7. johnny_karas

    johnny_karas

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

    Can you explain more about this, I'm curious and will check it.
     
  8. johnny_karas

    johnny_karas

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

    I plan to release it at September this year. The ex2D v2.0 changes a lot so it is not compatible with v1.0, after the first version finished, I'll write upgrade script so that people in v1.+ can convert their project to v2.0. But it won't be that easy so safely upgrading is not sure yet.

    I know this is a pain and make user frustrate, that's why I'm changes a lot in v2.0 which cost me much more workload. Before it comes out, let me give you some suggestion that we did in our project:

    1. Don't change one atlas at the same time for two or more peoples. This will cause the _ex2D_AtlasDB and _ex2D_SpriteAnimationDB file corrupt.
    2. Let only one person managing the atlas, the other artist just contribute raw pictures/textures.
    3. Keep in mind to rebuild scene and prefabs when atlas changed ( if only one person manage this, he can in charge of updating the scene )
    4. Don't ignore importing error when drag texture to atlas or sync from server triggered an atlas rebuild.

    Before v2.0 comes out, I think I can do a little change to help multiple people working together ----- change the _ex2D_AtlasDB and _ex2D_SpriteAnimationDB from ScriptableObject (binary) to xml file. This can prevent errors when more than one people changes atlas at the same time and put them into CVS server. I will start this at weekend, probably finished it by one to two days.
     
  9. Sinichi

    Sinichi

    Joined:
    Jun 1, 2012
    Posts:
    4
    Hello,
    I'm shinichi .
    Sorry, I don't speak english well.
    if I have mis ,sorry.

    I am using the ex2D now.
    And, I'm making the program by only C# and only class in library.

    I want to make the picture for sprite that I put the pictures on screen by class functions.
    I read api documents.
    And , I found the exBitmapFontUtility.Create.
    However, The Unity compiler generate the error that is "not found the class of exBitmapFontUtility".
    I can use the class of "exBitmapFont".
    However ,I coudn't use the class of "exBitmapFontUtility".

    What should I set the anything?
    If possible,please teach me these informations.

    Best regards.
     
  10. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    September release is too late for us. We need something that works now. ex2D NEEDS to work in a "Team" environment otherwise it's useless. Sorry to sound harsh but that's the reality. So please, look into changing it from Binary to XML and pray that it works. I would hate to have 30 levels at one point and continuously have to rebuild levels just because somebody added or rebuild an atlas. I am not happy at the moment.

    Thomas P.
     
  11. Froobzi

    Froobzi

    Joined:
    Dec 27, 2011
    Posts:
    6
    Hello, I have ran into a problem which I cant solve but I guess the answer is really simple...

    I worked quite a bit with ex2D already and its great, one thing when I add new sprites for example I create an empty game object, attach exSprite component to it and then add the texture ( by drag and drop ) I see the texture rendered by my camera in game view and I see it in scene view. Now how could I accomplish this through code? Basically I am trying to have an empty game object with exSprite attached to it and no texture, then I generate the texture programmatically and now I want to set the exSprite texture on that game object to my generated Texture2D.

    Here is an example on how I could do it not using ex2D:

    Code (csharp):
    1.        
    2.  
    3. Texture2D Terrain = new Texture2D(128, 128);
    4.         renderer.material.mainTexture = Terrain;
    5.      
    6.         for (int i = 0; i < Terrain.height; i++)
    7.         {
    8.             for (int j = 0; j < Terrain.width; j++)
    9.             {
    10.                 Terrain.SetPixel(i, j, Color.cyan);
    11.             }
    12.         }
    13.  
    14.         // Apply all SetPixel calls
    15.         Terrain.Apply();
    16.         guiTexture.texture = Terrain; // <-- exSprite here
    Now I tried so far to get the ex2D exSprite component from my game object through code and this worked well ( for instance)
    Code (csharp):
    1. exSprite Sprite = gameObject.GetComponent<exSprite>();
    but I couldn't figure out how to change the texture now ... something like Sprite.Texture = .. I couldn't find.

    Hope that I explained it well, if not feel free to ask any questions.

    Thanks in Regards ~Froobzi
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Using exSpriteText, if it is a child and offscreen when updating the text, it throws

    IndexOutOfRangeException: Array index is out of range.
     
  13. johnny_karas

    johnny_karas

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

    The exBitmapFontUtility is an Editor script. Which means you can not use this script in the runtime. If you want to reference the script, you need to put your script in an Editor/ folder so that Unity can help you import those editor script correctly.

    Regards,
    Wu
     
  14. johnny_karas

    johnny_karas

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

    After several test, I found XML file didn't solve your problem. The way to solve this problem can only be done in ex2D v2.0. However, to make people including me ease the work in ex2D v1.+, I wrote a script, which will loop the scenes you selected, and rebuild the sprites automatically in these scenes. Here is the picture to illustrate how to use it:

    When some one in the team build the sprite and found it corrupt the scene, he can run this script to easily rebuild all the exits scene.

    This change can be available in the later daily fix version (1.2.6 120602).
     

    Attached Files:

  15. johnny_karas

    johnny_karas

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

    Here is the documentation to show you how to change sprite by texture : http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:create_sprite_by_texture

    Remember, this method only works in Editor, cause all the function here are Editor Only. In the runtime, ex2D don't even know you have a texture.
     
  16. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I will check this, and update this post. Keep in touch.

    Update:

    Hi hippocoder, I've check it but nothing happend. Can you send me an example including this issue? Thanks in advance.
     
    Last edited: Jun 2, 2012
  17. Froobzi

    Froobzi

    Joined:
    Dec 27, 2011
    Posts:
    6
  18. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I can't, I don't have authorization. I wonder why this happens? And why should it stop when moving back on screen. Perhaps a unity bug? I don't know.
     
  19. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Can you create a simple scene that don't including any of your company resources for this problem ? I try it several times but still can't reproduce it.

    BTW: if you have trouble in creating such a scene, may be you can take some picture and instruction that help me create it step by step.

    Thanks in advance.
     
  20. robin_notts

    robin_notts

    Joined:
    Apr 7, 2010
    Posts:
    86
    Hi jwu. Sorry for the slow response. Hopefully you can see the issue about character vertical positioning from this image:

    It happens on all fonts. I'm really surprised no-one has flagged this up earlier.
     
  21. johnny_karas

    johnny_karas

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

    I'm very sorry, may be I'm not quite understanding the issue, I can't see problem based on this picture. Would you mind to point me out the problem and would you mind to send me an example including this font? Thanks in advance.
     
  22. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574

    Jwu, I think what robin_notts meant is the vertical positioning (in typography term it is called "baseline" of individual letters are wrong. In the picture you can see the letters are not "sitting" correctly on the light blue line (the baseline) - eg. the "f", the "h", the "i", the "k", the "l" and the "t" are sitting too low (past the baseline).




    I don't own ex2D (I am just interested in it and read the thread from time to time :)) so I don't know how ex2D handle the pixel fonts - I assume there can be two solution to this :

    1. Either the user do it themselves by inserting spacing in Photoshop (resizing individual picture font)..or
    2. You can probably create a system where individual font letterings can be adjusted according to their positioning (vertical, horizontal). It is also important to note that in Typography, vertical spacing ("leading") is important as well as "tracking" (horizontal spacing) and I assume the users would like these options if you ever want to implement such system.
     
    Last edited: Jun 4, 2012
  23. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    I downloaded the last build just now and I do not see that feature. Did you forget to include it?
     
  24. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Problem solved. Please download the fixed from another E-Mail.
     
  25. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I haven't check that more, will do this. Thanks for you explain!
     
  26. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This would be excellent.
     
  27. Sinichi

    Sinichi

    Joined:
    Jun 1, 2012
    Posts:
    4
    Thankyou for reply.
    I understood .
    however,I want to make the texture for ex2D to use only class of ex2D.
    For exsample:
    exSprite[] sprite= new exSprite[10];l

    for (i=0;i<10;i++){
    id=sprite.atlas.GetIndexByName(name); //name= texture file name;
    sprite= new exSprite();
    sprite.SetSprite(sprite.atlas,id,false);
    }

    However, The sprite is alway generated is null.
    Couldn't the exSprite make by "new" function?

    I want to not use the editor as possible.

    If possible, please teach me a way of making the program in only class function.

    Best regards.
     
  28. vvander

    vvander

    Joined:
    Jan 18, 2011
    Posts:
    72
    Are there any plans to add per-pixel collisions (sometimes called pixel-perfect collisions) to ex2D?

    There are two types:
    -The first type detects if ANY pixels overlap and then triggers a collision if they do.
    -The second type counts the overlapping pixels (if they exist) and reports HOW MANY pixels overlap.

    I just bought ex2D, and while I love everything else about it, these are sorely missed features. This is pretty standard in most other sprite engines, too - maybe not in Unity, but definitely in all other environments I've worked with. If it's already there and I somehow missed it, could someone point me in the right direction? Thanks!
     
  29. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Hi! You cannot do this in that way. Cause it's a MonoBehaviour based Class - it can be used only when attached to GameObject.
    You should do a few steps. It's simple:
    • Create an empty GameObject using Editor
    • Attach exSprite (or any other!) component to the GameObject
    • Make a Prefab!
    • Instinate the Prefab when you need like this
    Code (csharp):
    1.  
    2. // C#
    3. ArrayList mSprites = new ArrayList();
    4. for(int i = 0; i < 10; i ++)
    5. mSprites.Add((Instinate(<your prefab here>) as GameObject).GetComponent(typeof(exSprite)));
    6.  
    Sorry for syntaxis... More over it's better to use <List> instead of ArrayList. It's only an example.
     
    Last edited: Jun 5, 2012
  30. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Hi! Can you imagine how much it costs for you game? I allways split an object to get a few BoxColliders instead of MeshCollider.

    Regards.
     
  31. vvander

    vvander

    Joined:
    Jan 18, 2011
    Posts:
    72
    Actually if it's implemented in a library with easy access to individual pixel info (alpha and color values are important), its not too bad. I've implemented it several dozen times as an example when I taught XNA classes and have never had problems with efficiency. Granted, it's certainly more intensive than rectangle collision, but I'm sure implementing this for ex2D sprites would be much faster than using Unity's mesh physics system.

    Of course, if their BoxCollider system is implemented the way it should be, the splitting you're talking about should be as fast as 2D rectangle collision, which is better than per-pixel collision. Unfortunately this doesn't fit every use-case, though. Sometimes objects must know exactly when they've collided (in twitchy shoot-em-ups for example). Approximating it all the time with BoxColliders can't always work - again, unless there's something I don't know about the way ex2D handles collisions.

    EDIT: A good point to make is that per-pixel collision checking is in fact very expensive if it's the sole method used. It's always a good idea to check using rectangle collisions first to see if they bounding boxes intersect and then check per-pixel if they are.
     
    Last edited: Jun 5, 2012
  32. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704


    Hi Sinichi,

    Basically we use Prefab to instantiate ex2D objects. For example here you have 10 sprite, if you know the exactly atlas and index of the sprite, you can create a prefab for these sprites. In the runtime, all you need to do is:

    Code (csharp):
    1.  
    2. GameObject spGO = GameObject.Instantiate ( spritePrefab, Vector3.zero, Quaternion.identity );
    3. exSprite sp = spGO.GetComponent<exSprite>();
    4.  
    NOTE: Unity3D not recommend user use new function to create component.
     
  33. johnny_karas

    johnny_karas

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

    We plan to add customized collision shape late in this year. We never plan to implement per-pixel collision system before. The only thing I add to the todo list is let user access the pixel of the sprite. So what is, after v2.0, there will be a function help you get the color of the pixel based on your coordinate.

    exSprite.GetColor ( int row, int col ):

    Once you get the color, you can do you own detection calculation.

    The performance depends on your code, it won't cost too much for a simple GetColor call, but it will increase the CPU memory since you need to set Write/Read enable for the whole atlas, and that will make Unity save the pixel array in memory.

    I may consider adding this function in v1.+ depends on my time and workload, I'm not sure so I will give you a reply this weekend. Keep in touch.
     
  34. vvander

    vvander

    Joined:
    Jan 18, 2011
    Posts:
    72
    That sounds perfect! Thanks for keeping up with the community's suggestions. That's why I chose ex2D in the first place! I'm looking forward to the addition of the GetColor call, but I'm definitely not in a hurry. Like you said, there are a lot more important and fun features you guys are working on (like a GUI Editor, Tiling, Lighting, and of course the multiple resolution compatibility). I'm sure the customized collision shapes you mentioned will work well in the meantime anyway.
     
  35. sim88

    sim88

    Joined:
    Jun 6, 2012
    Posts:
    3
    Hi, I have downloaded the trial for version 1.2.5, but I'm not able to use it because when I try to import the package in my project, the assets get imported correctly and I have also the Sprite component, but it always crashes on importing ex2deditor.dll (I'm not sure about the name but it's a .dll file, I can't check now).

    Is it a problem anybody else had before?
     
  36. gerasim13

    gerasim13

    Joined:
    Jun 6, 2012
    Posts:
    3
    Hello. Recently i started making new game with unity and ex2d and faced with a one complexity. I want to blur sprite by using little shader program, everything just fine but blurred pixels did not fit in sprite shape.
    How can i create sprite with transparent pixel borders?

     
  37. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    I also can't find the way to make transparent border. I "baked" it into texture and I can use this texture for a sprite and disable Trim Texture flag, but when I add this texture to atlas it treams automatically and Trim Texture flag in sprite settings becoming disabled (grayed out).

    How can I disable trimming in Atlas?
     
  38. johnny_karas

    johnny_karas

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

    Which version of Unity3D you are using with ex2D v1.2.5? We test it on Unity3D 3.5.1 and 3.5.2
     
  39. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello gerasim13 and Ostin,

    I've add trim texture option in Atlas Editor which is in ex2d daily build v1.2.6-(120527). So please send me E-Mail to get this version if you don't receive News Letter of it.
     
  40. sim88

    sim88

    Joined:
    Jun 6, 2012
    Posts:
    3
    3.4.2, thanks I will try with the newest and I'll let you know ;)
     
  41. sim88

    sim88

    Joined:
    Jun 6, 2012
    Posts:
    3
    Yes, apparently the problem was caused by the outdated version. Thanks ;)
     
  42. lix

    lix

    Joined:
    Jun 8, 2012
    Posts:
    1
    Hi,
    I have Ex2d v1.2.5 (120510), I created a new scene, animation worked at first, after some further development and I did not pay attention to the animation, but now, it is not working anymore. the reason is during game running, the ExSpriteAnimation is deactivated automatically, if I pause and activate again and then run it, again it will be deactivated. it happens to all animation with ex2d. it happened before, what I did to fix was to delete all the ex2d generated files and start from beginning, luckyly it was still small work. I need to know where to look and how to fix. I checked all my scripts, there is nothing about disabling the exSpriteAnimation component.

    I did also sync and build all, atlas as well as animation. In the old scene where it copied from, the animation still working.
    Is it possible it is due to frequent crash of unity ?
     
  43. Sinichi

    Sinichi

    Joined:
    Jun 1, 2012
    Posts:
    4
    Thankyou for reply.
    I found a way that is to put exSpriteObject in Hierarchy by tool and duplicates it.
    I can make the 10 Sprites now.

    However , I am having a issue yet.

    if possible, please teach me following questions.

    I'm using exSprite and using textures in it.
    However, I want to use a part of texture.

    For exsample.

    ExSprite is setting a 1204x1024 texture.
    I want to draw it to clip the texture to cut (32,32,48,32).

    I tried it.
    For exsample.
    1:change the elements[0].trimRect
    2:exSprite.trimTexture = true;
    exSprite.trimUV=new Rect(0,032,32);

    However, It draw the all area of texture.

    How should i change the parameters?
    Best regards.
     
    Last edited: Jun 9, 2012
  44. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
  45. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    Hi everyone, i'm having a hard time using the setframe feature. I have the latest version of Unity and ex2d.
    First I start my animation playing....
    then when I want it to stop, I want it to display a certain frame from the animation so i use this code:

    spAnim.SetFrame(top, 1);
    spAnim.Stop();

    However, for a split second the original default sprite will flash and then it will display the one I set in the SetFrame...am I doing this completely wrong?

    thank you!
     
  46. johnny_karas

    johnny_karas

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

    It depends on your wrap mode and the stop function. Basically, if you stop the animation, the animation component will turn to disable. You can use exSprite.spAnim get this animation back instead of use GetComponent<exSpirteAnimation>() which is slower.
     
  47. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704


    Hi Sinichi,

    Like zafod said, you can use exSoftClip. Recently we developing exClipping for our new GUI framework. The exClipping is almost the same as exSoftClip but it use shader process clipping which allow you rotate the sprite in the clipping rect.
     
  48. johnny_karas

    johnny_karas

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

    You should stop the animation first, then set the frame. Other wise the stop function will reset the animation if the StopAction is DefaultSprite. So your script will looks like this:

    Code (csharp):
    1.  
    2. spAnim.Stop();
    3. spAnim.SetFrame( top, 1 );
    4.  
     
  49. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    Thank You!!
     
  50. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Question please:

    How do I set the Anchor dynamically on a sprite?

    Tried: newParticle.sprite.anchor = Anchor.botCenter;


    but anchor isn't a property of exSprite even though its exposed and everything in the editor..