Search Unity

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

    johnny_karas

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

    I try to select a prefab but no error reports, can you give me the steps to reproduce it? Thanks in advance.
     
  3. decoy98

    decoy98

    Joined:
    Aug 30, 2011
    Posts:
    36
    Hi Wu Jie, I have checked your links and here's the code I came up with..

    function Update () {

    if (Input.GetKey ("right"))

    spAnim.Play ( "ninja_run" );

    }

    I was trying to make the ninja play the run animation when I press the right arrow button,
    but then gives an error: BCE0005: Unknown identifier: 'spAnim'.

    Would you please point me out to the right direction?
     
  4. johnny_karas

    johnny_karas

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

    I think it is because you didn't define the spAnim in your script. Try something like:

    Code (csharp):
    1.  
    2. exSpriteAnimation spAnim = GetComponent<exSpriteAnimation>();
    3.  
    You can define spAnim as your member data, and put the above code in your Awake function to improve the performance.
     
    Last edited: Dec 5, 2011
  5. nab477

    nab477

    Joined:
    Jun 14, 2011
    Posts:
    46
    what happened to the Upcoming Features ?
    I remember there was a prototype about the tile editor ?

    will they be included in this version ? or separate plugins that work well together ?
     
  6. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
  7. johnny_karas

    johnny_karas

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

    The upcoming features is delayed until 1.3.0 comes out. I'm currently designing the new structure and working flow in 1.3.0. There will be a big change to solve the problem in making ex2D working with CVS tools. Every new features will follow this new structure that's why they are hang on developing.
     
  8. johnny_karas

    johnny_karas

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

    It looks like those spikes relate with garbage collection in Unity3D. But the GC is not just relate with procedural mesh but also the whole scripts you wrote in a game. For sprite changes, yes they will cause heap allocation I doubt.
     
  9. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    How do we handle collisions with ex2d? Can we use Unity3d's physics system to handle them or does ex2d provide tools for this?
     
  10. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Humm

    I'm try to figure what is going on on our game, Runs pretty well on iPad 2 / iPhone 3GS / iPod Touch, but when runs in iPhone 4G, he get some issues, and i can't figure what is going on!
     
  11. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    @jwt gonna be realy nice if you can keep in somewhere, maybe in the wiki some otimizations of 2D ex2D like this things:

    - Third, the advice. When atlas is created or edited, you leave "Read/Write Enabled" setting switched on. This way texture takes double amount of memory (2048x2048 atlas is 16Mb, and it takes 32Mb in iPad memory then running app). It will be greate to switch it off after atlas creation, for thouse who don't know or just forget about it.

    - All sprite object must not keep Transform.Scale = (1,1,1). DO NOT touch it. Use exSprite.Scale instead. Because if Transform.Scale is not equal to 1,1,1. Unity will not add the object to batch

    - Camera NearClipPlane must larger than 100. I still seek the reason, but I just found this two days ago

    - Use more atlas as you can!

    Anyone know any more adices of otimization?
     
  12. decoy98

    decoy98

    Joined:
    Aug 30, 2011
    Posts:
    36
    function Awake () {

    exSpriteAnimation spAnim = GetComponent(exSpriteAnimation)();

    }

    function Update () {

    if (Input.GetKey ("right"))

    spAnim.Play ( "ninja_run" );

    }

    Is this what you wanted me to do?
    If so, then it still gives me an error: Assets/Scripts/run.js(2,18): UCE0001: ';' expected. Insert a semicolon at the end.
     
  13. johnny_karas

    johnny_karas

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

    ex2D is well support the Unity's physics system, so yes you can. Current version of ex2D didn't provide tools for customize the collider by picture, but will be done in the future.
     
  14. johnny_karas

    johnny_karas

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

    I think I've fixed the Read/Write Enabled problem. In current version, if you update the altas texture, it will turn back to Read/Write disabled,

    The rest of your advice can be found here:

    http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:less_drawcall
     
  15. johnny_karas

    johnny_karas

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

    Well, I think you are getting compile error which means you are not write the script in the right way. Let me show you the full answer:

    Code (csharp):
    1.  
    2.  
    3. public exSpriteAnimation spAnim;
    4.  
    5. function Awake () {
    6.      spAnim = GetComponent.<exSpriteAnimation>();
    7. }
    8.  
    9. function Update () {
    10.     if (Input.GetKey ("right"))
    11.         spAnim.Play ( "ninja_run" );
    12. }
    13.  
    Please if there have syntax error, try to fix it.
     
  16. decoy98

    decoy98

    Joined:
    Aug 30, 2011
    Posts:
    36
    Oh man, thank you very much jwu.

    I got to the point where when I press the "d" key the ninja moves to the right... but then the animation does not carry over.
    How do I change this code so that the animation carries over?

    void Update () {

    exSpriteAnimation spanim = GetComponent<exSpriteAnimation>();
    if (Input.GetKey ("d")) {
    spanim.Play("ninja_run");
    transform.Translate (400 * Time.deltaTime,0,0);
    }
    }

    Thank you very much for helping a newbie out. You have done an awesome job with the ex2D plug-in.
    I hope it becomes mainstream soon :).
     
  17. kevdotbadger

    kevdotbadger

    Joined:
    Sep 13, 2011
    Posts:
    82
    Do we have a timeframe on this? It seems the other popular 2d system provides this already. Are there any video's on using Ex2D with unity's physics engine?
     
  18. johnny_karas

    johnny_karas

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

    Since the Play will rewind the animation next time it comes, you should try:

    Code (csharp):
    1.  
    2.  
    3. void Update () {
    4.     exSpriteAnimation spanim = GetComponent<exSpriteAnimation>();
    5.     if ( Input.GetKeyDown ("d") ) {
    6.         if ( spanim.IsPlaying("ninja_run") == false )
    7.             spanim.Play("ninja_run");
    8.         transform.Translate (400 * Time.deltaTime,0,0);
    9.     }  
    10. }
    11.  
     
  19. johnny_karas

    johnny_karas

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

    Sorry, but no milestone for this yet. I'm currently busy in developing v1.3.0, other new features are hang on until v1.3.0 comes out.

    I think we treat physics in a pretty easy way. Here is the documentation about how to use collision with ex2D:

    http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:collision_helper_usage
     
    Last edited: Dec 6, 2011
  20. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33
    I am trying to use ex2d sprite object as Tap GUIButton.I Position the specific sprite using viewport value.

    So My question is how to identify touch position is inside the specific sprite's Area. (have to be resolution independent)

    With more detail,
    My sprite scales (x =1.5 Y=1.5)
    View port Position = (0.8, 0.2)
     
  21. johnny_karas

    johnny_karas

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

    ex2D provide the exSprite.boundingRect which is a rect calculate in local space. I think you can convert it to world space or screen space for hit testing. The easiest way is add a collision box and use RayCast function.
     
  22. Dwel

    Dwel

    Joined:
    May 31, 2010
    Posts:
    13
    Hello,

    I'm in the process of trying out the ex2D evaluation version, and I can't for the life of me get the collisions to work.

    I have two sprites on the scene, both on the same layer, and both with the collider helper set to box. I can see the box colliders on the screen just fine, but they don't collide at all (or cause trigger if I try it that way).

    Is there anything else I need to do that I'm missing?
     
  23. johnny_karas

    johnny_karas

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

    Check if they are put in proper z position. Also if you enable the Auto Length, don't make your camera near and far clip too large, 100 distance could be a good value. The Unity have problem when long length box collide with each other.
     
  24. Dwel

    Dwel

    Joined:
    May 31, 2010
    Posts:
    13
    Oh, I think I spotted what's going on. For instance, for moving right I am using:

    " transform.Translate (Vector3.left * 1 * Time.deltaTime * speed) "

    If I add a rigidBody to the sprite object, it collides, but it then gets sent sliding backwards as a reaction.

    I there another method I should be using for movement so it takes into account the collision? (without necessarily using the rigidbody, which makes everything get pushed around)

    Edit: Ok, figured out how to stop the pushing, though I'm still interested in knowing if there's another way to make the collisions work without a rigidbody on every sprite object.
     
    Last edited: Dec 8, 2011
  25. johnny_karas

    johnny_karas

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

    For more details about collider in Unity3D, you can check this documentation: http://unity3d.com/support/documentation/Components/class-MeshCollider.html. Just check the table in the last section, it will give you the full answer.
     
  26. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33
    Hi, Quick Question.
    Im want to pack the atlases for later download In game.
    So Im going to Do Assest Bundling. What i want to know is, when i bundle the atlus do i need to bundle atlus info files too ???
     
  27. johnny_karas

    johnny_karas

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

    I didn't do asset bundle yet. But base on the design, you need only bundle Atlas, Atlas Texture, Atlas Material. The Atlas - Editor Info is just used in Editor not relate to final game.
     
  28. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    I just decided to look further into what already seemed to be a great 2D solution, and holy cow this is impressive ...
    Outstanding work about ex2D. Tools are very pro. It really looks like the best 2D solution at the moment.
    (and the price is very reasonable for such quality)

    About the ToDo list and GUI Editor, I can't find a concrete list of said features on the site, like what will be implemented precisely (button touch management ? scrolling text containers ? etc). Do you have any info about it, plus a potential release date estimation ?
    (could definitely convince me to purchase ex2d if good UI solutions are available soon)

    Thanks :)
     
    Last edited: Dec 12, 2011
  29. johnny_karas

    johnny_karas

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

    Thank you for your kind words, we are great people like this tool.
    We currently very busy in developing the v1.3.0. Since it changes a lot in the base structure, we need to test it a lot after it can stably released. So before that, any plan of new features will be delay and on hold.

    About the GUI, we've develop some of the controls such as Button and Scroll View and test them in our project. It is good enough for our use but far more than publish for general use. I can't define a time on these features, besides Unity3D seem to introduce ScaleForm and their brand new GUI system recently. We would like to see how good they are. So the UI solution may not available soon.

    Hope these information can help you in developing.

    Best Regards.
     
  30. kheng

    kheng

    Joined:
    Oct 22, 2008
    Posts:
    126
    I'm having trouble setting one's exScreenPosition.x to another objects exScreenPosition.x. How would I go about doing this?
     
    Last edited: Dec 13, 2011
  31. johnny_karas

    johnny_karas

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

    Can you explain more about this ?
     
  32. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Thanks for the info !
     
  33. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Loving ex2D, and we have been using it for a number of games that are currently in production. However, we came across an odd problem, and after banging on it for a few hours, it seemed like time to ask the experts.

    What we have is 90 objects rendering to the screen, in a 3D ring (think of it like Coverflow on iOS devices). Each entry is a sprite. The problem we are finding, is that we are ending up with 91 objects getting batched, and 92 draw calls (this includes our UI elements). If we modify the code so that the sprites all use the exact same sprite image, from the same sprite atlas, we still have 92 draw calls - regardless of all sprites using the same shader, and the same atlas, and the same image from that atlas. We have never had an issue with draw calls in ex2D before, so this problem came as a bit of a surprise.

    In addition to reducing the images down to just one, we have tried a number of other tests including copy/pasting the sprites within the game while it is running. This is where things get even stranger - while we have 90 of the same sprite, each with its own draw call, when we copy/paste while the game is running, it does NOT add any more draw calls!

    Would anyone have any suggestions on what to try next as a solution?
     
  34. johnny_karas

    johnny_karas

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

    Base on your description, I think it might be one of these problems:

    1. The scale in transform is not equals to (1.0, 1.0, 1.0)
    2. Your sprite, in some how changes the material so they don't use the same material. (Probably from script you write "Material mat = renderer.material;" this line of code will generate a different material though they are same settings. Try to use sharedMaterial instead )

    You can also check this document to help you understand how batch draw setup in ex2D:

    http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:less_drawcall
     
  35. kheng

    kheng

    Joined:
    Oct 22, 2008
    Posts:
    126
    Nevermind I figured it out. I have to use GetComponent<exScreenPosition>();
     
  36. nab477

    nab477

    Joined:
    Jun 14, 2011
    Posts:
    46
    is there an alternative way to set a sprite ?
    I tried exSprite.SetSprite, but it seems after I add something to the atlas, it has the potential to change the index of the sprite !!

    is there a more stable way than going to the atlas finding the "current" index ( double checking everything after adding something !!
     
  37. johnny_karas

    johnny_karas

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

    The exSprite.SetSprite is working in the run time. If you hard coded it when init the game. You should try something like:

    Code (csharp):
    1.  
    2. exSprite sprite = GetComponent<exSprite>();
    3. sprite.SetSprite ( your_atlas, your_atlas.GetIndexByName("foobar_01") );
    4.  
    Even more, you can make an animation clip with sprite texture you would like to setup in this clip, and try

    Code (csharp):
    1.  
    2. public exSpriteAnimClip myDefaultSets;
    3.  
    4. ...
    5. ...
    6. void Awake () {
    7.     exSprite sprite = GetComponent<exSprite>();
    8.     sprite.SetSprite ( myDefaultSets.frameInfos[0].atlas, myDefaultSets.frameInfos[0].index );
    9. }
    10.  
    So in this two ways, no matter how you change the sprite, they will find the index correctly.

    In the v1.3.0, we are going to change the whole architecture, so it will still keep correct index for a texture in their texture information assets, and you can use these assets for setup.
     
  38. mntcarp

    mntcarp

    Joined:
    Dec 12, 2011
    Posts:
    25
    (Sry if my english isn't very good, it's not my native language :-|)
    Hi everyone!
    I'm having troubles with an input and exSpriteAnimation script, I hope you could help me :).
    What I want my script to do is when I press left ctrl an "attack" animation is played and then return to the default sprite even if ctrl is still pressed.
    But what's really happening is that when I hit ctrl the animation "jumps" stays in first frame of "attack", not playing the animation at all (btw, it has 6 frames and its supposed to be played once)

    Attack Script
    Code (csharp):
    1. if(Input.GetButton("Fire1") /* isMoving == false*/)
    2.  
    3.     {
    4.         isAttacking = true;
    5.         anim.Play("attack", PlayMode.StopAll); //If "PlayMode.StopAll" is not there, the animation stays in the first frame, otherwise it jumps to the last frame
    6.     }
    Movement Script (which is actually working)
    Code (csharp):
    1. if(Input.GetKey("up"))
    2.         {
    3.             //isMoving = true;
    4.             anim.Play("walk", PlayMode.StopAll);
    5.             if(posZ <= 670 )
    6.             {
    7.                 transform.Translate(0,Time.deltaTime*speed,0); 
    8.             }
    9.         }
    10.  
    11.         else if(Input.GetKey("down"))
    12.         {
    13.  
    14.             //isMoving = true;
    15.             anim.Play("walk", PlayMode.StopAll);
    16.             transform.Translate(0,-(Time.deltaTime*speed),0);
    17.         }
    18.  
    19.         else
    20.         {
    21.             anim.Play("stand", PlayMode.StopAll);
    22.         }
    23.  
    24.        
    25.  
    26.    
    27.     /*---LEFT AND RIGHT MOVEMENT---*/
    28.  
    29.         if(Input.GetKey("left"))
    30.         {
    31.             //isMoving = true;
    32.                         if(!facingLeft)
    33.             {
    34.                 transform.Rotate(0,180,0);
    35.                 facingLeft = true;
    36.             }
    37.             transform.Translate(Time.deltaTime*speed,0,0);
    38.             anim.Play("walk", PlayMode.StopAll);
    39.         }
    40.  
    41.         if(Input.GetKey("right"))
    42.         {
    43.             //isMoving = true;
    44.             if(facingLeft)
    45.             {
    46.                 transform.Rotate(0,180,0);
    47.                 facingLeft = false;
    48.             }
    49.             anim.Play("walk", PlayMode.StopAll);
    50.             transform.Translate(Time.deltaTime*speed,0,0);
    51.         }
    52.  
    53.    
    Any suggestion will be appreciated :D
    Thanks in advance!
     
    Last edited: Dec 18, 2011
  39. johnny_karas

    johnny_karas

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

    The exSpriteAnimation component didn't provide you any parameter of PlayMode.StopAll. So what is the exactly class here for anim?

    BTW: the play of exSpriteAnimation and Animation has different behavior. When you call exSpriteAnimation.Play("your_anim") you need to check if it is playing, other wise it will rewind the playing animation. The Animation will check this automatically, and don't do anythings if the desired animation is playing.

    Based on your code, I can only see that your Movement and Attack logic are handle parallel, but sprite animation only accept one state in one time. So if you keep working and doing attack, only show some frame of attacking and rewind to movement.
     
  40. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    @mnt

    If you don't want rapid fire when the button is pressed, make sure you are using GetKeyDown instead of GetKey.
    GetKey will return true very frame until you release the button.

    Make sure your script is not repeating unnecessarily before doing the debug for animation.
     
  41. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Hi,

    we have a problem with ex2d. Every time one of our team members gets latest from SVN and opens Unity to start the asset building / importing process (starts automatically when you select your project folder), it crashes - twice. Once for the ex 2d atlas file, and once for the ex 2d sprite animation file. The 3rd time we open Unity it finishes. I was surprised to find that the latest version did not fix this.

    Anyone else having this problem? It happens on both Mac and PC for us.
     
  42. johnny_karas

    johnny_karas

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

    Yes, looks like I have the problem, too. I'll try to fix it asap.
     
  43. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Cool, jwu.

    I was having another problem last night....it worked until I checked it in. And then when I nuked my entire folder and got latest, it was broken. I get the following error when trying to set the scale of an exSprite, even if I set it to its current scale (no change) which is (1,1):
    ------------------------------
    Mesh.vertices is too small. The supplied vertex array has less vertices than are referenced by the triangles array.
    UnityEngine.Mesh:set_vertices(Vector3[])
    exSprite:UpdateMesh(Mesh)
    exSprite:InternalUpdate()
    -----------------------------
    Any ideas? This is driving me nuts.
    Thanks :)
     
  44. CapnCromulent

    CapnCromulent

    Joined:
    Sep 7, 2010
    Posts:
    45
    Hey Wu,

    I've been pretty happy with ex2D so far, but I gotta say I'm not a fan of the new layer system in 1.2.2+. Can you explain the reasoning behind the change?

    Overall, I find it much more cumbersome to use the LayerManager, especially when spawning new objects that need to be added to the hierarchy.
     
  45. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33

    same with me. i will finds rather its easy to use manual runtime layering by

    mExSprite.layer2d.ForceSetLayer(mExSprite.layer2d.layer,current_bias);
    mExSprite.layer2d.UpdateDepth();

    But i didn't update my ex2d to 1.2.3 since layer2d is removed from newer editions.
     
  46. wesllg

    wesllg

    Joined:
    Jan 8, 2011
    Posts:
    18
    I haven't had a big opportunity to use the new layer manager, but I was using it for a prototype. I can see the general idea and where it is going. A unified way of managing layers for objects is a good thing, and is typically how I do it. Normally I have a layer property of a base object between 0-31 inclusive. This makes managing layers for objects pretty easy, and I can set them on the prefabs/templates/whatever.
     
  47. michaelkamms

    michaelkamms

    Joined:
    Nov 21, 2011
    Posts:
    7
    Hi,

    I am trying to follow the tutorial video: ex2D Tutorial I: Basic Sprite Animation, but could get the background image scale and make it fit perfect according to the camera viewable size.

    May I know what is wrong?

    The settings:

     
  48. undream

    undream

    Joined:
    Dec 24, 2011
    Posts:
    27
    Any news about premultiplied alpha ? Both of the other 2D tools have this, and this is the only thing that stops me buying this amazing toolset.

    Waiting for replies,

    Thank you.
     
  49. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    OK~~~~~~~~~~~, looks like you should carefully manage your folder. Current version of ex2D have so many things depends on each other, that's what we going to solve in v 1.3.

    I think your project should be nuked after those operation. May be you can think about reimport things and rebuild the atlas to solve it.
     
  50. johnny_karas

    johnny_karas

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

    I think you can remove the exLayer from the sprite if you don't need the new Layer system. We are working hard to improve it. In the latest daily build, we add Dynamic Layer and Abstract Layer.

    The Dynamic Layer can help you add objects in a specific range, the Abstract one will stick the object in same z value. We also fix some bug when calculate the layer.

    For spawning new object. you can use prefab to adjust the layer of this object. When it spawn, just set its parent to a specific layer that already put in the scene.

    For example:

    I usually put a empty game-object and add exLayer on it. Let's name it layerEnemy, and in the enemy spawner, I will expose a property for user set this layer. After that, when enemy spawned, it will do

    Code (csharp):
    1.  
    2. GameObject newObject = GameObject.Instantiate ( ... );
    3. newObject.GetComponent<exLayer>().parent = layerEnemy;
    4.  
    Hope this help you.