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

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

  1. badawe

    badawe

    New Member

    Joined:
    Jan 17, 2011
    Messages:
    277
    @jwu

    Can i use the uv mapping of ex2D, without using the ex2D Component? I have been using Batching Tools to make sprite of 3D Objects and reduce drawcalls, but he generate many Mesh and I animate some 3D objects textures, by change the mesh in real time.

    What i want to know is: Can i get the tilling of one sprite frame?
  2. amaranth

    amaranth

    Member

    Joined:
    Jan 31, 2012
    Messages:
    101
    Hi, I was wondering if anyone had the problem I have. I create an animation and attach it to a game object > I test the game > game object only animates if it's selected in the Hierarchy window AND in the Inspector window, the Ex Sprite (Script) section is visible. If I hide this section, the game object won't animate. If I spawn the game object during game play, this isn't a problem, but if it's in the Inspector window by default, nothing. :(
  3. Wu Jie

    Wu Jie

    New Member

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

    Can you send me the problem package, I test this and it works perfect here.
  4. Wu Jie

    Wu Jie

    New Member

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

    Yes you can. It is saved in exAtlas.elements.trimRect. So if you have exSpriteAnimClip, and get the frame, you will know the atlas and index that frame used, then use it get the trimRect. The trimRect will including the uv information that you need.
  5. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi amaranth,

    Can you give me more details. The animation you create is it a Unity animation or exSpriteAnimation ? If this is an Unity animation, you need to enable animation helper in exSprite inspector. If other problem, can you send me a package or give me some snap shot ? Thanks in advance.
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    10,458
    Hi jwu, could the problem be I am using unity js? I have too many deadlines to spare much time to create example, so I try this weekend to get something to you.

    Error was Unknown identifier 'Anchor'. (meaning the enum couldn't be found, which is fairly impossible to achieve unless it doesn't exist on js).
  7. trothmaster

    trothmaster

    Member

    Joined:
    Jun 8, 2012
    Messages:
    54
    Hi jwu, thank you again for helping with my problem the other day, I have another question maybe you can help with...
    I am using a perspective camera. I have "use pixel Perfect" checked on my sprites.
    i'm "looking down the y axis" to sprites that are rotated 90 degrees so they face the camera.
    objects move on the xz axis.
    What I want to do is this:
    give the illusion of depth with a 2d background image. LIke old adventure games.
    Like in this picture: http://agsarchives.com/gamecard/882/space-quest-iv-5.jpg
    If the character walks "below" the other characters his sprite will render in front of them, if the character walks "above" the other characters his sprite will render behind them.

    Here is my attempt to do this by moving the object on its Y axis. It works GREAT with the orthographic camera, but I want to use the perspective camera to add 3d effects that don't work in orthographic. Any suggestions? Thank you!
    Code (csharp):
    1.  
    2. baselineobjectY = baselineobject.transform.position.y; //the y position of object1
    3.    
    4.   if (baselineobject.transform.position.z > transform.position.z) // if object1 z axis is > this objects z axis {
    5.         print("baselineobject is above!");
    6.         transform.position.y =  baselineobjectY + 1;     //move this object Y position + 1 above the object1 y position
    7.          }
    8.      else if (baselineobject.transform.position.z < transform.position.z)
    9.         {
    10.         print("baselineobject is Below!");
    11.         transform.position.y = baselineobjectY - 1;
    12.        
    13.          }
  8. trothmaster

    trothmaster

    Member

    Joined:
    Jun 8, 2012
    Messages:
    54
    Never Mind I figured out how to do it!
    set all the 2d objects to a new layer called "2dObjects" and then add a 2nd camera that is orthographic and set its culling mask to the new layer of 2dObjects. then set its "clear flags" to depth only and it will project the 2d objects onto a 3d perspective background!

    EDIT *** I also seem to need to add a 3rd camera for another layer "ontop" or in front of the 2d layer....hmm is this the best approach to this???
    Last edited: Jun 13, 2012
  9. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Yes, if you are using the javascript, please put the ex2D Core in the Plugins folder, that will make sure your javascript compile after it.
  10. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Well, it depends on your game. If this is a pure 2D game, I would use exLayerMng and allocate a dynamic layer block. In your case, the 3D environment only affect in background. So nothing bad here.
  11. guitar1212

    guitar1212

    New Member

    Joined:
    Jun 14, 2012
    Messages:
    1
    hello~
    I use ex2d create 2d game

    There are 10+ Characters, and have 13 animations each character.
    every spriteAnimation need 40~50 textrues.

    When I import 3 characters, then Unity Crash!

    Please help me~~~
  12. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi guitar1212,

    I think you face a memory problem here. It is out of memory somehow.
  13. Sinichi

    Sinichi

    New Member

    Joined:
    Jun 1, 2012
    Messages:
    4
    Thank you a lot of informations for my questions.

    I have understood some questions.
    So,I will be able to make the game system for making the our games.
    However, I'm having a question that about the 2d scaling.
    When I draw the 2d sprite, it is scaling to 150%.
    if I draw the sprite at point of (100,100) and size of (100,100),
    It could put at the point of (100,100) .
    however,It was drawn until the point of (150,150).
    It seem that it was scaling to 150%.

    I change the program that the 2Dsprite is scaling to 66% now.
    If it is ok, I have no questions now.
    However, I might be having a mis.

    ★I've added the information.

    I asked the some questions.
    However, I might have a mis understanding about exSoftClip.
    Because, if I change the application's screen size by mouse drag, the exSprite and the exSoftClip are changed the scaling .
    (Draw position is ok. However, The clip area and the draw size is strange.)

    if I try to draw the full pictures, it is no problem.
    However, When I use the exsoftclip,it is happening.

    if possible ,please teach me.

    Best regards.


    ★It's fixed the issue when I calculate softclip size X ppfscale from base sprite.
    Best regards.
    Last edited: Jun 19, 2012
  14. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    jwu - did you have a chance to take a look at the font/text issue? Currently text is unusable in ex2d, and I'm having to look at other options because I can't be sure if ex2d will work in time to get this project finished. I would really prefer to use ex2d for text. Thanks.
  15. ZettaZete

    ZettaZete

    New Member

    Joined:
    Apr 28, 2012
    Messages:
    74
    jwu, I have purchased your ex2d plugin, loving it so far. However, I have having trouble changing the offset at runtime. This is the command I am using. Maybe you could lead me in the right direction.

    fenceSprite.offset.Set(-xOffset, yOffset);
  16. MarigoldFleur

    MarigoldFleur

    Member

    Joined:
    May 12, 2012
    Messages:
    1,353
    I'm thinking about switching to ex2D but I have a few (hopefully) simple questions before I take the plunge.

    1. Can I use sprite sheets as opposed to rebuilding sprite atlases whenever I change my sprite sheet layout?
    2. Can I set the z-position of each sprite individually?
    3. Are the bitmap font tools completely contained within the Unity editor? Like, can I import a font right there and then set it so it's rendered at 25pt without the use of an external application?
    4. Can I change the playback speed of a sprite given certain conditions? Like if I want a sprite to have a slower walk animation while underwater than if on land.
    Last edited: Jun 18, 2012
  17. Wu Jie

    Wu Jie

    New Member

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

    I've been keep asking you send me the font resource you show me in the post. Currently I'm not sure what cause the problem, we've checked our font and they are draw in line with perfect character-offset. So I need to check your resource and see if there is some data that ex2D miss reading ( actually it is the y offset).

    Please send me a resource and the error package.

    Regards,
    Wu
  18. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704


    Hi ZettaZete,

    I think you can't use Set function for sprite.offset. Cause this is define as a property, you need to replace the whole vector to trigger it I doubt. Like this:

    fenceSprite.offset = new Vector2(-xOffset,yOffset);
  19. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi MarigoldFleur,

    Let me answer your questions:

    1. ex2D doesn't support loading sprite sheet. This feature will be added in v2.0 which plan to release at September.
    2. Yes you can. ex2D also provide a LayerManager which can help you organize the scene.
    3. No, you have to use external application for this. ex2D support bitmap font generate by 3rd tools.
    4. Yes you can. In the exSpriteAnimation, you can adjust the speed of each animation clip instance (exSpriteAnimState)
  20. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    Hi jwu

    The font problem is very easy to reproduce:

    1) Open up the demo scene "05 - demo_atlas_font".
    2) Select the gameobject "font - normal".
    3) Change the font to "hiragino_kaku_atlas - hiragino_kaku_12"
    4) Look at the text close-up in the Scene view. It will look like this:
    [​IMG]

    Thanks.
  21. csotomon

    csotomon

    Member

    Joined:
    Apr 28, 2012
    Messages:
    2
    Is the website down?
  22. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    The website is down cause the host not notify us changing the IP. we are fixing it right now.
  23. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Have you try the other font? Check my attachment file. I think it is just because that font I provide not use the traditional Y offset. If this cause people confused, I will change it to other font resource.

    Attached Files:

  24. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
  25. Panajev

    Panajev

    New Member

    Joined:
    Mar 26, 2012
    Messages:
    42
    It looks to me like a compression problem (and maybe a blending issue related to alpha perhaps premultiplied by the PNG creating tool and assumed unpremultiplied by ex2D and Unity), disable compression on all the font atlases by setting the format to a RGBA uncompressed one or "Truecolor" if you set them as GUI textures.
  26. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    Panajev - I think you are missing the point. The one and only problem is that some of the characters y position is incorrect.
  27. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Messages:
    10,458
    Some font data isn't stored when using hiero or bmfont. I've rolled my own font systems using those 2 apps before, so I know it isn't always the code. Sometimes you'll just have to ditch that font and find one that does work (or manually alter the y offsets in your .fnt text file).

    Another alternative would be to try glyph designer (I haven't bought it yet, mac only) but it may yield more intelligent results. I doubt this is a code bug.

    It's also not just yoffset. Sometimes xoffset too. But these are manually repairable in the generated file from your font builder application.
  28. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi robin_notss,

    I check the A, a character in your font resource, it says:

    Code (csharp):
    1.  
    2. char id=65 x=28 y=137 width=11 height=18 xoffset=0 yoffset=-3 xadvance=10 page=0 chnl=0
    3. char id=97 x=40 y=147 width=10 height=14 xoffset=0 yoffset=0 xadvance=9 page=0 chnl=0
    4.  
    Based on the info above, the A(id=65) will have a yoffset=-3 which means it will go down 3 unit of the horizontal line and the a(id=97) will stay at the horizon 0. And the picture you show me correctly represent what the data told him. So I'm sure this is a problem of font resource.

    We are currently use Glyph Designer in our project in Mac, till now nothing wrong with it. Can you tell me the font builder you are using and would you mind to share this font to me for testing ? I can try to generate it through Glyph Designer and compare the result.

    Thanks in advance.
  29. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    hippocoder (Rob) - looks like you are right, I get the same result with my AngelFont code in monkey. The font program I've been using is bmGlyph on the mac to make my fonts. This sucks a lot. Thanks for your answer.
  30. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    jwu - thanks for looking at this. The font is here:
    http://beaker.powweb.com/AlternateGothicNo2.zip

    I'll be interested to know how Glyph Designer handles it.

    Something that is strange is that the HD version of the font doesn't seem to have the same problem.

    cheers
  31. Wu Jie

    Wu Jie

    New Member

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

    This is the result generate by Glyph Designer, it is correct.

    Attached Files:

  32. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    Hi jwu

    For some reason I can't see the attached image.
  33. robin_notts

    robin_notts

    New Member

    Joined:
    Apr 7, 2010
    Messages:
    84
    Thanks for that jwu. Would you mind trying it at a much smaller size. It only seemed to be an issue with fonts that were quite small (<20 I think). Thanks again.
  34. trothmaster

    trothmaster

    Member

    Joined:
    Jun 8, 2012
    Messages:
    54
    Hi Everyone, sorry if this is already answered but i'm wondering what your opinions are on how many sprite sheets and how big they are you can use if you are targeting iphone 3g and above. Is 3 sprite sheets at 2048x1024 way too much?
  35. Froobzi

    Froobzi

    New Member

    Joined:
    Dec 27, 2011
    Messages:
    6
    Hello jwu.. I know you have answered this already but I still couldn't figure out how to make it working :/.. here is what you said:

    Code (csharp):
    1. Hello Froobzi,
    2.  
    3. Here is the documentation to show you how to change sprite by texture : http://www.ex-dev.com/ex2d/wiki/doku...ite_by_texture
    4.  
    5. 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.
    First of all I couldnt find exEditorHelper in VisualC# so I had to manually add the reference to that DLL, then Unity couldn't identify it... so I tried copying the dll to the Assets folder from the ex2D folder and it worked.. Tho when I run this I get an instance of a game object with exSprite attached but no texture on .. (PS I didnt use AssetDatabase.LoadAssetAtPath() to load the texture2D from the disk because it couldnt identify it either, the error was: `AssetDatabase' does not exist in the current context)

    To clarify what I'm trying to do: I have procedurally created a 2D terrain for my game. All I want is to attach it through code to a GameObject which has the exSprite component on and then add my generated texture to that exSprite component (Basicaly instead to 'drag drop' the texture from my Assets folder I would assign it directly from code but I cant figure out how.. Perhaps I'm over looking something obvious.

    Thanks in Regards ~Froobzi
  36. Apiweb

    Apiweb

    Member

    Joined:
    Nov 26, 2011
    Messages:
    56
    Any predictions for when it comes to 2D Tile Map Editor and Editor Skinning?

    And you want to do some integration with Spriter?
  37. Froobzi

    Froobzi

    New Member

    Joined:
    Dec 27, 2011
    Messages:
    6
    Sorry for posting again but I managed to avoid drawing the terrain on a texture and then assigning it to a gameobject that has exSprite component.. Because my terrain is made out of little square tiles I made rather instances of those tiles attached the correct textures to each type of tile through the editor (dirt, sand.. etc) and built the terrain by instancing and placing the tiles on already calculated places in worldspace (thanks to a combination of Mid Point Displacement Algorithm and Bresenham's line drawing algorithm adapted to my needs.) with an average speed of about 0.2 seconds per tile (trying to improve the speed at the moment).

    I noticed something odd and I wanted to ask on the way. My laptops screen is 1366x768 wide. When I enable pixel perfect for my tiles, then go to the cameras exPixelPerfectCamera component and set the Width to 1366 and Height to 768 manually, then click Build Run , pick the 1366x768 resolution and Fantastic graphics I noticed that there is about 1 pixel space in between my tiles and I don't know why, setting the height on the exPixelPerfectCamera component to 767 (i.e one pixel smaller) fixes this problem but I am not quite sure if these things overlap now because that would be bad.

    More Information:

    All my tiles have 16x16 dimensions
    My cameras ortographicsize is set to 100 (default)
    Tiles are separated by 16 units in world space from each other for example lets say Tile1 is on 0, 0, 0 then Tile2 is on 16, 0, 0 etc..
    I made sure that my Atlas Import Settings are correctly adjusted so that it doesn't smooth the textures in any way..

    Thanks in Regards
    ~Froobzi
    Last edited: Jun 23, 2012
  38. Wu Jie

    Wu Jie

    New Member

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

    This is the font in size 18. Nothing wrong here.

    Attached Files:

  39. Wu Jie

    Wu Jie

    New Member

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

    You can only use max size of 1024x1024 size of texture in iphone 3g I guess.
  40. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi Apiweb,

    We plan in doing this after September, after we release the ex2D v2.0.
  41. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi Froobzi,

    You can't use the document i show you in runtime. They are for editor. As you know in runtime exSprite doesn't care your texture cause they are in atlas. If you trying to use single texture in exSprite. You can use

    Code (csharp):
    1.  
    2. exSprite.renderer.material.mainTexture = YOUR_TEXTURE
    3.  
    That's it.
  42. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi Froobzi,

    I doubt in current version you can only use Point Filter for your tile textures. We plan to solve the tiling problem after v2.0 but not very soon.
  43. unormal

    unormal

    Member

    Joined:
    Jan 10, 2012
    Messages:
    21
    Is there a way to build atlases at runtime, for example if I wanted to provide a workflow for an artist without re-compiling the project? (i.e. load assets at runtime into an atlas, rather than at edit/build time?)

    Are functions like CreateAtlasInfo for this use, or only for defining in-editor workflow?
  44. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hello unormal,

    No way to create atlas in runtime in current version. Cause all the generate script is designed for Editor. However, we've already add the runtime generate atlas as a new feature in v2.0. The new structure of ex2D make it feasible.
  45. unormal

    unormal

    Member

    Joined:
    Jan 10, 2012
    Messages:
    21
    Great, looking forward to it.

    In the meantime I just rolled my own simple 2d sprite engine. Of course performance will be slow compared to atlased spriting, but I can use it for in-game editing and workflow, and then bake the atlases once the animations/etc are complete. Thanks again, keep up the good work!
  46. d3gator

    d3gator

    Member

    Joined:
    May 28, 2009
    Messages:
    16
    does anyone know possibility to control Sprite animation speed in runtime?
    I want to make animation playing back faster when my character begins move faster.
  47. Wu Jie

    Wu Jie

    New Member

    Joined:
    Sep 20, 2010
    Messages:
    704
    Hi d3gator,

    You can do this by:

    Code (csharp):
    1.  
    2. exSpriteAnimation spAnim = GetComponent<exSpriteAnimation>();
    3. spAnim.GetAnimation( "your_anim_name" ).speed = your_speed;
    4.  
  48. Thinice

    Thinice

    Member

    Joined:
    Jan 20, 2012
    Messages:
    33
    Hi,

    I'm having the following problem: Randomly, a texture (or part of a texture) gets pixelated. Please have a look at the following image:

    $pixelated.jpg

    Look at the 1st and 6th rocks: both are in the same atlas, which is using POINT filtering. The 6th rock is the same texture that the 5th, but the 5th has no issues with pixelation.

    Also look at the crab: part of the texture is pixelated while the rest is not.

    None of the elements you see are rotated nor scaled.

    Why does this happen? How can I resolve it? I've just updated to the latest version of ex2d available in the asset store, by the way.

    Thanks very much!
    Last edited: Jun 27, 2012
  49. Wu Jie

    Wu Jie

    New Member

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

    Have you try Bi-Linearly filter? This problem caused by low-level rendering, and currently I have no idea how to solve it in script. If anyone have solution, please let me know, I'm happy to add it in ex2D!
  50. Thinice

    Thinice

    Member

    Joined:
    Jan 20, 2012
    Messages:
    33
    Yes, in fact I was using BILINEAR filtering from the start but there were black borders around some of the textures; your suggestion was to change filtering mode to POINT to avoid that.

    I changed it again back to BILINEAR now and here is the result:

    $blackBorders.jpg

    Look at the circled areas, you'll see some black lines there. This is much more visible in other textures of the game as well.

    It's strange because those black lines don't appear on ALL the textures of an atlas. I have some rotated, moved scaled elements in the game using bilinear filtering that don't show this issue, so may the problem be in the input files? I've tried all possible combination of file filtering atlas filtering with no luck, I either have black borders on SOME of the textures (bilinear) or I have pixelation on some of the objects (point).

    I'll try rebuilding some of the art assets that I'm using to see if it helps... :(