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

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    jwu!
    The Rebuild Sprites, don't get Prefabs right? on Project right? Some way to do that?
     
  2. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I have had a quick look through this thread and couldn't find the answer to his on your website.

    I have a couple of fonts, one contains "Score:" and the other contains "0". How am I able to change the value of 0 via script?

    The game object I want to alter is "font_iScore" which is also tagged "font_iScore"

    I have also noticed that as soon as I hit play in the editor, all the fonts disappear.

    Are there any tutorials on how to use fonts with ex2D?
     
  3. johnny_karas

    johnny_karas

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

    The rebuild sprites will skip rebuild Prefabs. But it will rebuild the instance of the prefab. Am I right?
     
  4. johnny_karas

    johnny_karas

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

    In ex2D package, there have two demo shows you how to use the font (demo 6 and demo 7). And here are the documentation relate with it:


    In short, if you want to change the text of font in script, just do:

    Code (csharp):
    1. spriteFont.text = "Hello World";
    Can you give me more information on this, such as screen shot of the your settings of these fonts, and the exBitmapFont asset you create. Thanks in advance.
     
  5. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    Hi Jwu,

    Thanks for your time.

    All the font files should be in this .zip http://dl.dropbox.com/u/28570639/Fonts.zip

    And the font settings:



    I have noticed that the font appears fine in the Game view and Scene view, and only disappears from the Game view when I click play.. I can still see the font in the Scene view.
     
  6. johnny_karas

    johnny_karas

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

    The settings are all right, and based on your description, is it possible that you modify the Z when running the Game? You can check if your z value changes.
     
  7. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    Hmm for some reason the Z is changing to -9.7
     
  8. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    OK, so are you doing some z calculate in your script ? or is there any chance you change the camera z pos?
    Another way, try to set Use Layer 2D to false and see if the z value not changed any more.

    Looking forward to see your feedback.
     
  9. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I've unticked Use Layer 2D and the fonts Z now stays at 0. I'm pretty sure I've not done any Z calcs on the fonts, or moved the camera, but I will double check when I get more time.

    Is it generally best to keep Use Layer 2D set to true?

    Thanks very much for your help.
     
  10. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Generally, the Layer 2D can help you organize the Z-order of sprites by layer number. This is good for artist design the scene. And ex2D calculate layer depends on your camera position and the near-far clip.

    You can read more in this article: http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:use_sprite_layer

    In ex2D v.1.1.1, if you have more than one camera. The layer will calculate by the Camera.main.
    In next coming version (v1.1.2), the layer uses the camera setup in the sprite, default is Camera.main. So hopes this help you locate the problem.
     
  11. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I'm still not getting how to script the font change.. it could just be because this is my first usage of C# and Unity. I cant find, in the game demos, where any font is changed via script. They all seem to be static and never change.

    Have you got the above "in long" version? ;)

    Edit: ok, I have it worked out. My problem is that I'm not up to speed with how Unity works. I've now got the text changing.. the text align isnt right but that's another matter ;) Thanks again JWU!
     
    Last edited: Sep 7, 2011
  12. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Happy you solve the problem.

    What makes it not right ? Is this a bug or something I can help you?
     
  13. Biggz

    Biggz

    Joined:
    Aug 29, 2011
    Posts:
    23
    I don't think it's a problem with ex2D... more a problem of me needing to learn how to use ex2D (and Unity). I am assuming my "problem" is text alignment.

    I have spriteFont.text = "0"; but when I change this to spriteFont.text = "12345"; the text grows larger from the center, and digit 3 I need the first digit to always be left aligned where I placed it in the scene.

    It was more that I didnt have time to have a look at how it is dont, but I've just had a play around with the Anchor setting and that looks to be working fine now
     
  14. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Hi jwu,

    I'm losing detail in my textures when I import them into Unity with ex2D. Everything is crisp and perfect in Photoshop, but it's slightly blurry when I create an ex2D sprite object out of it.

    I checked the import settings on my texture. I tried both GUI/Truecolor and Advanced/Automatic Truecolor. Both produce a slightly blurry texture.

    How do I keep my imported texture looking as crisp and detailed as the source file?

    Thanks for all the help :)

    Edit: Sorry, I should have included an example:



    You'll notice that some of the detail on the lines and splatter is lost when displayed in Unity. Also, the colouring is slightly different. Any idea why? :\
     
    Last edited: Sep 7, 2011
  15. johnny_karas

    johnny_karas

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

    Have you checked the Generate MipMap settings ? Just disable the Generate Miamap Texture option.
    Plus it also depends on your Filter Mode. If you are perfect in pixel, choose Point Filter Mode will make your texture sharper.

    The above settings must be done in Atlas Texture not the source one.

    If you are working on iPhone platform and use OpenGL ES 1.1, it must not import a texture larger than 1024x1024.
     
  16. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    Recently there's an interesting article from 41 Post Blog discussing how to set up texture import setting for 2D game:
    http://www.41post.com/4286/programming/unity-scaling-pixel-art

    And there's a screenshot show you how to make sure the texture is crisp:


    Also as jwu said, if you use texture atlas, the final quality of your graphic depends on the atlas texture import setting, not on original textures.
     
  17. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Very helpful responses! Thank you both! I used the settings in that screenshot and the blurriness is gone :)

    I'm still noticing one other discrepancy, though. It seems like Unity is increasing the saturation in my texture's colours ever so slightly. Again, the difference is subtle, but it makes me uncomfortable knowing that my textures aren't being displayed as designed :)

    Here's an example:

    Source Texture from Atlas
    As Displayed in Unity

    You'll notice the difference in the green colours.

    Is this a lighting or shader issue? Any ideas? :-\
     
  18. Scarlier

    Scarlier

    Joined:
    Aug 28, 2011
    Posts:
    5
    Hi,

    could not find a answer in this huge thread :eek:. i am looking how to change a sprite.
    what i saw in the doc there was a function SetSprite() but how do i need to call it within a gameobject
    is that the method i should use? or am i looking in the wrong direction?

    and does that method to the same as setting a texture in inspector such as pixel perfect
     
  19. johnny_karas

    johnny_karas

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

    I test it the whole morning, and YES you are right. It do have some slightly color bias in my computer. But not as strong as yours. See my attachments. (I do this in Mac OSX Lion)

    I believe this relate with the API Texture2D.EncodeToPNG(); that unity3d provide. So basically, the atlas will read the pixels in source texture, and call this function to generate a PNG texture and let Unity import it to get the final result.

    The only thing I'm not sure in this process is how unity Encode PNG file, and is it the same algorithm we ued in the source png picture.

    Should ask Unity for help :(
     

    Attached Files:

    Last edited: Sep 9, 2011
  20. johnny_karas

    johnny_karas

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

    You can change sprite by using exSpriteAnimation component or use SetSprite function as you said. In using the function, I think you need to add your script component, and inside it write code as:

    Code (csharp):
    1.  
    2. exSprite sprite = GetComponent<exSprite>();
    3. sprite.SetSprite ( the_atlas, the_index );
    4.  
    If you are using an exSpriteAnimation, you can arrange a series of frame, and use the code below to change the sprite texture:

    Code (csharp):
    1.  
    2. exSpriteAnimation spAnim = GetComponent<exSpriteAnimation>();
    3. spAnim.SetFrame ( "my_anim_name", index );
    4.  
    Sorry but I'm not sure what you mean. In the inspector, if you enable the Use Pixel Perfect button, the sprite will be pixel perfect in the game. Is this what you expect?
     
    Last edited: Sep 9, 2011
  21. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Thanks for looking into this, jwu. I posted a thread in the main support forum. Hopefully I'll find some answers there :) I'll keep you posted!
     
  22. Scarlier

    Scarlier

    Joined:
    Aug 28, 2011
    Posts:
    5
    Hi Jwu

    [/quote]

    thanks for the quick reply got the sprite changing working. what i was trying to ask is
    when i dont choose a texture in the inspector and add a texture on runtime with
    exSprite sprite = GetComponent<exSprite>();
    sprite.SetSprite ( the_atlas, the_index );


    the texture is not visable. so what is the difference between setting a texture with the inspector and the function setSprite. do i need to call different methods to get the same behavior.
     
  23. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I want to anchor a UI element to a corner of the screen but screen/view position don't do relative position.
     
  24. johnny_karas

    johnny_karas

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

    Actually you can't set texture in Runtime I think. Because ex2D generate the atals texture, and in the runtime it won't reference any raw-texture you import to atlas. Which means it won't include any of them in your final build to save your app size. Based on this, you only can change sprite texture by atlas and index, which will translate to altas texture and the uv coordination of sub-texture in render phase.

    What you see in Inspector is all work at editor. That's the technique ex2D used to help user connect from raw-texture and atlas in sprite seamlessly.

    Hope this help you understand the theory behind it. Any problem, let me known.
     
  25. johnny_karas

    johnny_karas

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

    I think you can use exViewportPosition component by select Viewport Position in the exSprite inspector panel, under the option of Transform 2D.

    After you select it, you will see a exViewportPosition component added to your sprite, and you can type your relative value there.
     
  26. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Hey jwu,

    Problem solved! My texture had an embedded colour profile in it which Unity ignores. Removing the colour profile in Photoshop cleared up the issue :) Thanks again for helping out!
     
  27. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    bug with layer when in edit mode : when changing the ortho cam size to 10, layer # 8 sends the sprite to z=2490 instead of something more sane
    when playing the scene it works fine
     
  28. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    The values are a remap from screen size to 0-1 and are mapped from the upper-left corner, what if I want to pin the button to the lower middle ?
    what is needed is a corner pinning similar to what exists in EZ : example of pinning : horizontal=Middle, Vertical=Bottom. A re-use of your anchor grid would work marvelously.
     
  29. johnny_karas

    johnny_karas

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

    I can't reproduce this problem in my version of ex2D. I've submit ex2D v1.1.2 to the asset store, and please wait for it and see if the problem still exists.

    Yes you are right, the value is 0-1 start from upper-left, in v1.1.2 it will start from bottom-left. So if you want to have Middle-Bottom position, just type x = 0.5, y = 1 (in v1.1.1) or type x = 0.5, y = 0.0 (in v1.1.2).

    I don't think you need an anchor to help you do this. 0, 0.5, 1 are represent to everything.
     
  30. johnny_karas

    johnny_karas

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

    ex2D v1.1.2 is now available in asset store.
     
  31. figbash

    figbash

    Joined:
    May 13, 2008
    Posts:
    60
    Hi, do you think you could add some kind style template for text objects? I would like to use gradiated text with a certain font in a ton of places in my game (menu/interface mostly), but whenever I want to modify the look of the text I have to go change every single text object in the game. It would be great if there was just an object type that let you define the initial font, colors, size, etc that could be shared between multiple text objects.

    Anyway thanks for the great tool, it's been very useful!
     
  32. Aranir

    Aranir

    Joined:
    May 23, 2011
    Posts:
    16
    I just bought the framework after jwu gave me such great support to solve one of my problems I had when using the other frameworks.

    This was my problem:


    Can you see those tiny black lines between the textures? Those appeared depending on where I set the camera, and if I moved the camera around these lines appeared at different positions.

    But jwu came to the rescue and solved my problem.
    The trick is to set the FilderMode of the Texture atlas to Point instead of Billinear (which will not make the texture blurry anymore when you get close as this apparently cause the black lines to appear)

    His support was fantastic and I really wonder when he is sleeping as he always answered within a few minutes when I had questions about his framework.

    For the price, the quality and the amazing support its really a great product created by a developer who puts his heart into it.

    I just wanted to share this, as maybe someone else will run into the same problem.
     
  33. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    You have a button that's 64 pixel wide and you want its right corner to be exactly 30 pixels from the right corner and its bottom corner to be 100 pixel from the bottom of the screen. How do you do that ?
     
    Last edited: Sep 10, 2011
  34. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    When I select ex2d in the asset store the update button isn't there, I know it worked in the past because I upgraded to 1.1.1 but I don't remember the secret steps.
     
  35. johnny_karas

    johnny_karas

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

    Indeed, the style/effect of the font in ex2D is for prototyping, and user should avoid do outline or shadow effect in the runtime because it is too expensive. Instead, you should use tools such as Glyph Designer to generate font effect in the bitmap and use it directly in ex2D.

    But your advice are really great! Plus it is too waste to carry these data in Sprite Font Component, so the style/effect asset can help solve the problem by share same settings in different fonts even more can leave them as null if user don't want these effects.

    So far I'm busy in developing TileMap editor, but I'll go back to this. And I think it could be even better if I can use shareStyle/Effect and style/effect in the exSpriteFont. In this way, user can modify the color dynamically in the runtime and don't worry about affect the other fonts use the same style.

    I add an issue in ex2D github page: https://github.com/jwu/ex2D_Runtime/issues/1
     
  36. wesllg

    wesllg

    Joined:
    Jan 8, 2011
    Posts:
    18
    ex2D is looking great, good work. I'd really like to see ex2D have it's own (relatively simple) built in collision mesh editor for creating simple mesh colliders. There is already something similar on the asset store as a separate tool (search for Polygon Tool). Incidentally, this would also be similar to TGB/Torque2Ds built in poly editor.

    Keep up the good work.
     
  37. johnny_karas

    johnny_karas

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

    Based on your description, I suggest you doing it in this way:

    1. Set the anchor of the button as Right-Bottom.
    2. Select "Screen" in Transform 2D option in your sprite inspector
    3. In the Ex Screen Position component set Screen X = Your_Screen_Width - 30, Screen Y = Your_Screen_Height - 100

    I guess you not want to know Your_Screen_Width and Your_Screen_Height in the last step, and want the value of 30 and 100 start from a specific corner you choose am I right? Em.... this is a good idea, I'll do it. Let me know if I misunderstand your problem

    Have someone already updated to v1.1.2 ? Anyone have the same problem ? If this is a problem in common, I'll send email to ask Unity Team for help.
     
    Last edited: Sep 10, 2011
  38. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    That's it :)
     
  39. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    I want to say that ex2D is a joy to use.
    Having switched to .dll is a very good move and I don't know how you handle #ifdef for mobile platform, I like that I don't have to understand.
    And Jwu, your support is fast.

    I am eager to use your GUI extension and skeleton deformation.
     
  40. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    @Aranir

    I'm touched T_T, and thank you for your share Aranir, this can help lots of people solve tiling problem. Actually I always get your mail when wake up in the morning :)

    @wesllg

    Hello wesllg, thank you for your kind word. I do use TGB 2D and I do know the Mesh Physics Editor in it. Actually I wrote one in QT framework last year, and even more I ported to html5, but it is full of bug and no time to finish it. Though the physics is in low priority in ex2D's milestone, your advise just remind me this important feature! I add an issue relate to this feature here: https://github.com/jwu/ex2D_Runtime/issues/2, but not in recent milestone, hope you can understand.
     
  41. llavigne

    llavigne

    Joined:
    Dec 27, 2007
    Posts:
    977
    Soft clip are great, so easy to use.
    But if the child is at an angle, the clip doesn't handle that.
    In this image, the clipping should be horizontal and clip the red laser beam when it reaches the ground

    $Screen shot 2011-09-10 at 4.23.58 PM.png
     
  42. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    I could download ex2D 1.1.2 without any problem from asset store...

    6R
     
  43. johnny_karas

    johnny_karas

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

    I add a issue https://github.com/jwu/ex2D_Runtime/issues/3 for the screen position placement problem.

    Em... in current code, there is no #ifdef platform specific codes. I can see this when writing Touch scripts for GUI. This are belongs to runtime so I have to carefully design the code to include only no #ifdef scripts in the dll.

    If the scripts includes these macros, they need to design in some override functions and only virtual one in dll,
    In this way, the source and dll can exists together and build depends on user's target platform.
     
  44. johnny_karas

    johnny_karas

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

    Sorry I haven't finished the SoftClip documentation yet (too busy these days T_T). The soft-clip only can works with Sprite/SpriteFont that didn't rotated and sheared. This is because it only resize the mesh and apply the proper uv coordination. All this are computed in CPU that's why we call it soft-clip.

    Current version of Unity didn't provide perfect solution in using GPU doing clip. I do find some way use shader but not perfect for designing phase :(.

    So the soft-clip is more like a GUI helper component, especially for font rendering in a dialog box.

    I'll do more research in doing a perfect clip using shader, need more time :)
     
  45. WonkyWooGames

    WonkyWooGames

    Joined:
    Dec 31, 2010
    Posts:
    63
    Hello,

    Can anyone confirm if this is compatible with Megafiers plugin ?

    Cheers...

    D
     
  46. johnny_karas

    johnny_karas

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

    I didn't buy MegaFires plugin, so I can't give you an answer on this. Based on the screen shot of this plugin, I think it will change the shape of the mesh by divide it into small pieces.

    ex2D will rebuild a sprite mesh when you change the scale, shear or other settings. So each time you doing this, your MegaFire meshes will turn back I doubt.
     
  47. wesllg

    wesllg

    Joined:
    Jan 8, 2011
    Posts:
    18
    Great news, hope to see it one day soon(ish). It would certainly help with workflow when producing 2D games that have more complicated shapes that need more precise collisions. I wrote a similar tool in AS3/Flash a couple years ago, but it is also incomplete and is quite different environment than that of Unity.

    I'm also looking forward to the tilemap stuff. :D
     
  48. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Not exactly...
    Megafiers works with the polygons of the mesh ! If your mesh has one or two triangles only, you can't do a lot of things with Megafiers here.

    6R
     
  49. SanjuanRJ

    SanjuanRJ

    Joined:
    Sep 11, 2011
    Posts:
    11
    Hi people!
    I have a question about physics, using ex2d.

    When I put a mesh collider, the form of the mesh doesn't assume the form that I want.

    For example, how can I set a hill collider?

    Thx
     
  50. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Thanks 6R! I hope this information can help Wonkywoogames.

    Hi Sanjuan,

    Current version of ex2D only generate Mesh Collider and Box Collider in Rectangle. So if you want to do a pixel level collision, you have to create your own mesh collider.

    I have create an issue in doing this: https://github.com/jwu/ex2D_Runtime/issues/2