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

    johnny_karas

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

    Can you send me the example so that I can check the problem.
     
  2. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    i am still unable to load an atlas. somehow i doubt my coding :p

    i did creat a new atlas and moved the atlas asset, the material and the texture into the Resources folder.

    after that i do the following:

    Code (csharp):
    1. GameObject aaa = new GameObject("aaa");
    2. exSprite sprite = aaa.AddComponent<exSprite>();
    3. exAtlas playeratlas = Resources.Load("playerAtlas.asset") as exAtlas;
    4. sprite.SetSprite(playeratlas, 0);
    but instead of loading the atlas from the resources folder i get this:


    Invalid input in SetSprite. atlas = null, index = 0
    UnityEngine.Debug:LogWarning(Object)
    exSprite:SetSprite(exAtlas, Int32)
    NullReferenceException: Object reference not set to an instance of an object



    what am i doing wrong? i thought all i need to do is load the .asset from the atlas and unity does the rest for me. but somehow i cannot get the atlas to load from the resources folder.
     
    Last edited: May 7, 2012
  3. RabidKitten

    RabidKitten

    Joined:
    Apr 15, 2011
    Posts:
    38
    Hello,

    I was wondering if there was a way to make the Sprite Font type itself out? If there was some variable I could manipulate over time to make the letters appear in the order they are typed?

    Thanks,

    Tyler

    edit: I have solved this by using ToCharArray on the input string. Then adding the char array via a Foreach loop over Time.
     
    Last edited: May 8, 2012
  4. johnny_karas

    johnny_karas

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

    If I remember, you don't need .asset in Load function. Do it as

    Code (csharp):
    1.  
    2. exAtlas playeratlas = Resources.Load("playerAtlas") as exAtlas;
    3.  
     
  5. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    it produces the same error with or without the .asset :(

    to make sure that i did nothing wrong: this it what everything looks like in my unity. do you see any error here?

    $atlas.png

    i have the feeling that the playerAtlas.asset simply does not return the type exAtlas but i am not sure how i can fix this (if it's the case)
     
    Last edited: May 8, 2012
  6. johnny_karas

    johnny_karas

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

    After my testing , I think you should write the script as:

    Code (csharp):
    1.  
    2. exAtlas playeratlas = Resources.Load("playerAtlas", typeof(exAtlas)) as exAtlas;
    3.  
    I test the code above and it successfully load the atlas.
     
  7. iossif

    iossif

    Joined:
    Mar 4, 2011
    Posts:
    332
    awesome, that works. thanks alot!
     
  8. lilymontoute

    lilymontoute

    Joined:
    Feb 8, 2011
    Posts:
    1,181
    Hey guys,

    I noticed a few people mentioned Spriter in this thread. I just wanted to hop in to say that I've created an import plugin from Spriter (beta format) to ex2D. It has full animation support, as well.

    Download:
    https://github.com/Thinksquirrel-Software/spriterdapi-unity-ex2d

    Web Player:
    http://dl.dropbox.com/u/33426743/SpriterUnity/SpriterUnity.html

    Note that both this API and Spriter are in beta. Currently, this tool creates one atlas per spriter character, with a fixed size of 1024x1024. I'll add support for adding a character into an existing atlas soon. Also, make sure your entire viewport window is visible in the editor (and not shrunk) or it will not import properly. There are a lot of features still planned, and some issues to work out.

    Thanks to the devs for this awesome tool. I literally bought ex2D on the same day that I implemented this - it was that easy to understand and work with!
     
  9. TorontoJoe

    TorontoJoe

    Joined:
    Mar 25, 2012
    Posts:
    32
    Hi jwu, great work on ex2D.

    I'm getting some errors when I replace the text on an exSpriteFont object.

    Here is the code:

    Code (csharp):
    1.  
    2. exSpriteFont sampleText = gameObject.GetComponent<exSpriteFont>();
    3. sampleText.text = "This is a test. Test. Test. Test.";
    4.  
    It works. It changes the text but I get this error:
    Code (csharp):
    1. IndexOutOfRangeException: Array index is out of range.
    2. exSpriteFontEditor.OnSceneGUI ()
    I also tried changing the text during runtime through the editor and i get the same error.
    Am I doing it wrong?
     
  10. johnny_karas

    johnny_karas

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

    This is an exciting news, cause we try to contact the author of Spriter and discuss with supporting Spriter plugin. I think this is a very good start and since I'm currently re-design some of the structure of ex2D to make it perfect to solve multiple-people cooperate problem, I think we can discuss the project later and see what we can do.

    I'm very happy about this and thanks for your share! I'll contact you later.

    Regards,
    WU
     
    Last edited: May 10, 2012
  11. johnny_karas

    johnny_karas

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

    It might be the font asset lacks of some character. Would you please send me a package includes this error, Thanks in advance.
     
  12. GilbertoVeiga

    GilbertoVeiga

    Joined:
    May 22, 2011
    Posts:
    4
    hey jwu, nice job om the ex2D, thanks!

    I was messing with it a bit and I think that the warming about the Mesh leak ("Cleaning up leaked objects in scene since no game object, component or manager is referencing them Mesh has been leaked 7 times.") comes from the SpriteBorder use.. take a look on this.

    Cheers,
    Gilberto
     
  13. johnny_karas

    johnny_karas

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

    I'm still finding the reason, will take a look at sprite border. This issue happen when I upgrade from Unity3D 3.4 to 3.5. In 3.4 I'm carefully test the leak one by one in my code. But after upgrading, everything goes wrong. I have to write simple code and test it from beginning.
     
  14. GilbertoVeiga

    GilbertoVeiga

    Joined:
    May 22, 2011
    Posts:
    4
    Oh, I forgot to mention, while dealing with prefabs that contains a SpriteBorder, beyond the warning while saving the project, the sprite disappeared while applying changes to the prefab; and It only turns back when I selected every sprite again...

    Good luck there!
     
  15. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Hi jwu.
    Is it possible to build atlas with custom font at runtime. I have (...ooh) VERY VERY multilanguage project at the time. So it would be nice to 'load' current language set (i mean bitmap font info) in the main atlas and 'clear' it from others. I dont really wanna use one more additional atlas for font (or fonts) because it breaks batching.
    I cant find anything about.

    Regards!
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Crash Bug


    Steps:

    1. play an anim clip which is set to 'Clamp'
    2. play an anim clip which is set to 'Loop'
    3. set following code: anim.GetCurrentAnimation().speed = 1;

    The 3rd line is the source of the error. It will work without null reference or compare errors if both clips are set to 'Loop'.

    It works fine if set to 'ClampForever'. So I use that for now.

    Please fix :)
     
    Last edited: May 11, 2012
  17. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    I have tried changing the paths here as you suggested, but it crashes on me. So, as a second test, I created a new empty Unity project, then created a folder called "ThirdParty" and then another one called "ex2d" inside of it. I dragged and dropped the ex2D files (_ex2D_AtlasDB, _ex2D_SpriteAnimationDB, ex2D folder) into this subfolder that I made. Unity doesn't crash, but then when I create a new Atlas Info, the preview pane is missing and something just isn't working right.

    Thoughts?

    (my stuff: Unity Pro 3.5.1f2, OSX 10.7.3, ex2D 1.2.4)
     
  18. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    I'm implementing destructible background. So, first of all I generate whole BG into one Color[] array, then I'm creating 64x64 tiles using parts of this array as a texture.

    So, I've made dymanically generated sliced background. Everything works fine except stiches! All my tiles have wierd crap on the edges.

    $_bug_sl.png

    How can I fix it?

    PS: Camera size is set to 1/2 of height (for pixel perfect) and all coords are integers. Texture filter is set to "Point" and no texture compression used. Wrap mode set to "Clamp".

    PPS: It seems that the topmost line of every tile has to be in the bottom and the leftmost - on the right.
     
    Last edited: May 12, 2012
  19. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
    Hello there,

    i got a little problem with animations. I am working on an iOS game.

    - I have a character with no scripts attached (okay, that ex2D script...)
    - That character has also one ex2D-Animation-Component attached (it's a basic Move-Animation, contains 5 Frames, Wrapmode is selected as "LOOP")
    - I made two Buttons (made them in Illustrator, exported them as transparent .png files), and using them as GUITexture-Files on the screen itself

    So now i move the character with my Right/Left-Button to the right and to the left. Works quite fine, BUT the animation doesn't behave properly with the Touchphases. The animation should play all the time, my finger is on the button, but when i release it, it should stop immediately. But when my finger touches one of the buttons, only the first frame of the animation is played and when i release the finger, the other frames are played. I looked up the Script-References of ex2D but it kinda didn't help (probably i didn't manage to find the right spot to look at :p )

    So, what could/should i do?
     
  20. johnny_karas

    johnny_karas

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

    To change the font in the runtime, you just need to set the exSpriteFont.fontInfo to the one you wish to.
     
  21. johnny_karas

    johnny_karas

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

    The GetCurrentAnimation() would be null if no animation playing or the animation is stopped. So I'm not sure if the problem caused by script or by your data. Can you give me an example including this error, I follow your step in my PC but nothing happen.
     
  22. johnny_karas

    johnny_karas

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

    You can not drag ex2D to other folder, it should exists in the Assets/ex2D, because lots of resource load follow this path. You can only set the path of atlasDB and spriteAnimationDB.
     
    Last edited: May 14, 2012
  23. johnny_karas

    johnny_karas

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

    It looks like the black line problem is caused when your atlas texture is bilinear or trilinear filter mode. In current version, you can only fix the problem by set it to Point filter mode. I'm trying to use a suggestion from github to fix the problem. But still under testing.
     
  24. johnny_karas

    johnny_karas

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

    I guess your script looks like this :

    Code (csharp):
    1.  
    2. if ( Input.GetKeyDown("LeftArrow") ) {
    3.     spriteAnim.Play("running");
    4. }
    5.  
    In ex2D, the if you put this code in the Update() function, it will keep rewind the animation and playing the first frame. The correct way to do it is check if the animation is playing or not and play it properly.


    Code (csharp):
    1.  
    2. if ( Input.GetKeyDown("LeftArrow") ) {
    3.     if ( spriteAnim.IsPlaying("running") )
    4.         spriteAnim.Play("running");
    5. }
    6.  
     
  25. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Lines are not black. Take a look - they look like texture is shifted by about 0.5 pixel and cycled.

    Take a look at this particular tile (I've zoomed it 300% in PhotoShop):

    $tttt.png

    You see - the leftmost line has to be at the right, and the topmost line - at the bottom. They are not black - they are pieces of texture from the opposite side.

    For now, I've fixed this issue by adding offset to my 64x64 tiles by x=0.0079, y=-0.0079. These values shift the texture back and everything is ok for now (until I try to change zoom).
     
    Last edited: May 14, 2012
  26. NateJC

    NateJC

    Joined:
    Apr 10, 2012
    Posts:
    58
    Yeesh, that is quite a bummer for organization to have it be so rigid. Can't this be changed? Can the paths be relative? Or based on a setting just like the database path is?
     
  27. johnny_karas

    johnny_karas

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

    Would you mind to send some of this texture to me, I can use it as resources for fixing this problem.
     
  28. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I think they can, I'll add this feature in the next version.
     
  29. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    ex2D v1.2.5 released on the Asset Store and Our Web Store

    I fixed several bugs. In the mean time I'm still developing the ex2D v2.0. I'm going to release the new GUI framework we are using right now based on ex2D which is free to update in the next version.

    We plan to release the first version of our GUI framework at the end of May.
     
    Last edited: May 15, 2012
  30. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    No, I can't. Please re-read my original post on prev page... The texture is generated by code.

    Code (csharp):
    1.         var go: GameObject = GameObject.Instantiate(tile_prefab, Vector3(_x0+x*tile_size, _y0+y*tile_size, _z0), Quaternion.Euler(Vector3(0, 0, 0)));
    2.         var spr: exSprite = go.GetComponent("exSprite") as exSprite;
    3.         var tx: Texture2D = new Texture2D(tile_size, tile_size);
    4.  
    5.         tx.SetPixels(pixel_data);
    6.         go.renderer.material.mainTexture = tx;
    7.         tx.filterMode = FilterMode.Point;
    8.         tx.Apply();
     
  31. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33
    @Thinksquirrel : Nice work Buddy !!!
     
  32. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Thanks! I found out it by myself. It's so easy to work with. I really love it.
    Thanks a lot for this asset. It's brilliance.
     
  33. TorontoJoe

    TorontoJoe

    Joined:
    Mar 25, 2012
    Posts:
    32
    After updating to the latest Unity version, which came out today, I get a TON of warnings when I build for device or web.
    All of them ex2D atlas related warnings such as:

    Code (csharp):
    1. Script attached to 'hiragino_kaku_atlas - EditorInfo' in scene '' is missing or no valid script is attached.
    2. UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
    I'm running the latest ex2D.

    Anyone else get this?
     
  34. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Hi,

    Some questions, please:

    1. How do I check if an anim has used all it's frames up for clamped animation as I want to disable it when it has finished playing.

    2. How do I query the current state of a sprite if it is flipped or not?

    Thank you :)

    ps. I don't understand why vital things for querying the state of a currently playing animation like if it is flipped or not, or if the animation has ended or not, are very hard to find or not exposed. Surely anyone making a decent game will want to query if this is the case. It is a bit too protected right now. That is my honest feedback :) perhaps I just can't find it in the docs. Btw your offline documentation link is broken.

    I would like less protected variables so I can quickly with efficiency query the state of sprite or animation if possible please, for mobile.
     
    Last edited: May 16, 2012
  35. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35
    I need to figure out how to do this. Where do I add the first part of this code? What do I have to alter to make it work in my script? I'm coding in JavaScript, and I can''t figure out how to change the text in a font object by using javascript.

    Also, how do I create/generate a sprite font object from scratch in javascript alone?
     
  36. johnny_karas

    johnny_karas

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

    1. You can add animation event at the end of the frame to trigger function call. This is under the design of ex2D, make every call back driven by data.

    2. If a sprite is HFlipped, the sprite.scale.x < 0.0f, if VFlipped, the sprite.scale.y < 0.0f.

    I think ex2D didn't protect things, I guess you didn't know ex2D Runtime is open source in github. So people who wish to add new feature can always go to github https://github.com/jwu/ex2D_Runtime fetch one and modify the code, compile it into dll and change the original one. And we are encourage people modify the script and share it in the folk, so that I can evaluate if this is good to add into master branch.

    Any problem, feel free to ask me.
     
  37. johnny_karas

    johnny_karas

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

    Javascript is same as C#. Just do

    Code (csharp):
    1.  
    2. var sampleText:exSpriteFont = gameObject.GetComponent.<exSpriteFont>();
    3. sampleText.text = "This is a test. Test. Test. Test.";
    4.  
     
  38. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I'll update the version and check the problem.
     
  39. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Fantastic wu, thank you :)

    Thank you, I finally worked it out. I must be getting very slow in my old age! We will talk about ex2D in the TA developer diary for The Other Brothers shortly as well. It will be praise indeed :)

    The SendMessage technique you have chosen is very powerful. One can add footsteps for example. Congratulations on your excellent design.
     
    Last edited: May 16, 2012
  40. TorontoJoe

    TorontoJoe

    Joined:
    Mar 25, 2012
    Posts:
    32
    Fixed it by Rebuilding the Prefabs. Thanks!
     
  41. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35

    jwu, that worked, but I'm getting the following red warning.

    "ArgumentException: You are not allowed to call get_gameObject when declaring a variable."

    What do I do about that?

    ***** Edit *****

    Found the answer. Changed the code to the following, and assigned the fontSpriteObject in the inspector.

    Code (csharp):
    1. var sampleText:exSpriteFont;
    2.  
    3.  
    4. function Update () {
    5.    
    6.     sampleText.text = "This is a test. Test. Test. Test.";
    7.    
    8. }
     
    Last edited: May 16, 2012
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It's faster to do:

    var sampleText:exSpriteFont = gameObject.GetComponent(exSpriteFont);

    ...in unity js. I know this 100% for fact, since 3.4. Eric did a lot of tests.
     
  43. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35
    Now, how do I create a fontSprite object entirely from JavaScript? Can someone show me where this is documented, or share the code with me?
     
  44. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35
    When I do this, it gives me the following error. Although, it works anyway with the error, but I don't want the error.

    "ArgumentException: You are not allowed to call get_gameObject when declaring a variable."

    I'm using Unity 3.5.2
     
    Last edited: May 16, 2012
  45. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Did you clear the console?
     
  46. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35
    Yes
     
  47. jdviz

    jdviz

    Joined:
    Nov 3, 2008
    Posts:
    35
    Is it possible to use ex2d sprites as a HUD for a First Person Controller in a 3D environment?
     
  48. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Sure, we did that before.

    About the javascript questions, I think most of them are about correcting syntax writing. There is no different in using ex2D for C# or Javascript indeed, so what we show in the documentation is equally the same for Javascript by converting the script under the syntax Unity provide for Javascript( I prefer call it UnityScript).
     
  49. simjeanny88

    simjeanny88

    Joined:
    May 17, 2012
    Posts:
    19
    Hi ! Please kindly help me.
    - I have create sprite animation by ex2d.I have 2 animation and i select Wrapmod as LOOP.
    -I want when i press key down (right/left), it runs animation right/left otherwise it runs idle animation, But when i press key down of right/left, it is not run animation all frame, it just run animation at frame 1.If i release pressing key down right/left, It runs animation full frame.

    this is my script:

    var sprite_ani : exSpriteAnimation;

    function Start(){
    sprite_ani = Getcomponent("exSpriteAnimation");
    sprite_ani.Play("idle_ani");
    }
    function Update(){
    if(Input.GetButtonDown("Horizontal") Input.GetAxis("Horizontal") >0){
    sprite_ani.Play("walk_right");
    }
    if(Input.GetButtonDown("Horizontal") Input.GetAxis("Horizontal") <0){
    sprite_ani.Play("walk_left");
    }
    else{
    sprite_ani.Play("idle");
    }
    }


    :( :(
     
    Last edited: May 17, 2012
  50. simjeanny88

    simjeanny88

    Joined:
    May 17, 2012
    Posts:
    19
    Hi ! Please kindly help me.
    - I have create sprite animation by ex2d.I have 2 animation and i select Wrapmod as LOOP.
    -I want when i press key down (right/left), it runs animation right/left otherwise it runs idle animation, But when i press key down of right/left, it is not run animation all frame, it just run animation at frame 1.If i release pressing key down right/left, It runs animation full frame.

    this is my script:

    var sprite_ani : exSpriteAnimation;

    function Start(){
    sprite_ani = Getcomponent("exSpriteAnimation");
    sprite_ani.Play("idle_ani");
    }
    function Update(){
    if(Input.GetButtonDown("Horizontal") Input.GetAxis("Horizontal") >0){
    sprite_ani.Play("walk_right");
    }
    if(Input.GetButtonDown("Horizontal") Input.GetAxis("Horizontal") <0){
    sprite_ani.Play("walk_left");
    }
    else{
    sprite_ani.Play("idle");
    }
    }