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. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Hi, geno!
    I checked your suggestion, but every texture uses 'bilinear' filter. I caught that if my camera is frozen its ok, but my camera should follow the player object. So that kind of 'artefacts' I see only when my camera is moving.
     
  2. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Sorry, I'm not sure if you really understood what I wrote. You should change it to 'point' filtering. The flickering is caused by using 'bilinear' filtering.
     
  3. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Thanks for trick. Using this I have more likely picture (i mean 'point' filtering). And I solved my issue - just reimport all textures and rebuild all atlases.

    Thanks a lot and have a nice stuff
     
  4. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Does anybody know if there's an official IRC Channel for ex2d already?
     
  5. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Thank You!

    Another question, maybe a little trickier. I want to make sure I'm approaching this problem in the easiest, simplest way. My game is going to have two identical folders with all my textures, one high resolution, and one low resolution. All the files have the same names, except the low res ones have _low at the end ("texturename_low.png"). The low resolution pngs are exactly half size (this is for 3g iPhone/Touch support, a must for us).

    At runtime, I want to use either the low res textures or the high res textures depending on the device I'm running on. What's the best approach to doing this swap?

    *Do I have to create all my assets via script as described in the docs? Or even create two entire sets of atlases, sprites, and animations?

    *Or, is it possible to create my Sprites, Animations, etc and somehow "swap" out the underlying exAtlas updating the sizes accordingly? Cocos2d (the platform I'm porting this game from) has this sort of automated process, but I'm aware they've had years to build that kind of feature.

    Thanks in advance for any advice!
     
  6. profanicus

    profanicus

    Joined:
    Nov 23, 2009
    Posts:
    295
    That really depends on the game; personally I find doing top down from XY quite bad.

    Apart from not making intuitive sense when viewing the scene, you cannot use Vector3.forward to move objects in their direction of facing. You have to change physics gravity direction. LookAt doesn't work because it's based on Z axis. All kinds of extra problems that don't exist when making it in XZ.

    To fix these requires rotation transforms piled on top of more counter transforms to move the sprites back into view. I am trying to avoid empty GOs that do nothing except rotate child objects (I have lots of objects), which is why I am a little disappointed that a great feature like choosing axis of quad creation was removed.
     
  7. johnny_karas

    johnny_karas

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

    Basically the evaluate version is too old. You can PM me or send me an E-Mail to ask a latest evaluate version (I'm recently very busy to upgrade the public evaluate version).

    So in the new version, you only need to do Anim.animations[0].speed = the_speed_you_want to change animation speed.
     
  8. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Well, I have no time to set up this but sounds great. I will propose this to nantas, see if we have resource in maintaining it.
     
  9. johnny_karas

    johnny_karas

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

    Actually this problem still exists. Though point filter solve it but some people thin bilinear is better in visual. And recently a discuss of the issue have been setup in my github page: https://github.com/jwu/ex2D_Runtime/issues/26. I think I will try the solution jeedee suggested later in my development.
     
  10. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    I would suggest to use existing resources like freenode.net. So, if you're fine with that, I have just started a channel on freenode called #ex2d. :) Would be really cool if everyone who's here around joins the channel so we can discuss ex2d and unity stuff / problems / ideas / etc.
     
  11. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi 39thstreet,

    The multi-resolution support is not been done in ex2D so far, so if you wish to making a game in multiple resolution, you should first focus on one platform and use the script generate your resource in the 2nd platform. But no matter how, you still need to create another scene for you HD version.
     
  12. johnny_karas

    johnny_karas

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

    It is very cool, I'd like to join it but since I'm very busy, I may only online to check the questions each morning, so basically I'm not too active in the channel but I think Nantas can. Anyway, I will ask nantas' advice first since he is in the charge of supporting and marketing.
     
  13. johnny_karas

    johnny_karas

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

    The forward can change to up and the gravity can change to Z as you already mentioned. I think this really depends on person, the reason to remove XZ, YZ support is it will introduce a very complicate rendering pipeline that is really hard to maintain in our future plan, such as Skeleton animation editor and Layer Manager.

    I made some Space Ship shooting game before in ex2D, in my experience, those annoying problem can be conquered. Plus In my previous works, I developed a 2D engine that only have x, y coordination. I use it made prototypes and they only have up, right vector, but still can create games without trouble. XZ, YZ platform is really not that important once the team have the same knowledge and have an agreement in encoding the game.

    Hope you can understand and I'll seek the reason deeply to find out if XZ, YZ is really necessary in the future. Keep in touch, this topic won't be closed easily, we both need more example to prove it.

    Regards,
    Wu
     
    Last edited: Mar 23, 2012
  14. 39thstreet

    39thstreet

    Joined:
    Jan 30, 2012
    Posts:
    104
    Ah, that's what I was afraid of. This is a universal iOS app, so it's not really a 2nd platform. Guess I'll be doing a lot of things twice :(

    It's a real bummer, because I don't think any of the 2d platforms on Unity support multiple resolutions, and it's a key feature.
     
  15. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Hello!

    I have a doubt regarding the texture size.

    We have a pair of big images which cannot be compressed, and which would occupy something around 2048x2048 pxs in a texture map.
    Hence, as they cannot be compressed (any methods we tried made it look really bad..), we would have 16MBs only in a texture maps for those images.

    Is there any other way, using ex2d or not, to load those textures into a sprite?
    I mean, each individual .png has less than 600KBs. I don't have almost any experience regarding image compressions methods, hence I do not know how to proceed. Our current project will be targeted at iOS and Android, we cannot use 16MBs just for these images.

    And, lastly. Can I use any alternative method of compression which does not degrade image quality? I mean, the 2048x2048 .png texture map generated on the computer before compiling anything has less than 2MBs, and when I build my project using RGBA32, it turns to 16MBs.


    Thanks very much, and sorry for the ignorance on this topic :p
    Fernando.


    EDIT: found a nice thread on this topic: http://stackoverflow.com/questions/1686525/pvrtc-compression-increasing-the-file-sizes-of-png

    Hence, is there any way of storing textures as .pngs and decompressing them at runtime?
    Sometimes this trade-off between performance and storage may be worth..
     
    Last edited: Mar 23, 2012
  16. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Hi, I want to use the exScreenPosition Script to position my GUI elements which are to be rendered in a second camera. I moved the GUI elements -3000 units on the x-axis. Now if I try to use the exScreenPosition Script it doesn't seem to work like I thought. There is no possibility to specify my offset of -3000 for x. Is there another way on how to do this? I just want to draw my game world/objects and GUI with two separate cameras. I'm grateful for any help on this.
     
  17. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Hi.
    I have had the same problem. I solved this by using exViewPortPosition. And dont forget to choose correct camera in your exSprite inspector.
     
  18. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Cool, that solved my problem, too. Many thanks! :)
     
  19. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Yes I know. But since it makes the structure too complex, I put it in a very low priority until the main method goes stable enough. I'm currently design the ex2D v1.3 ( will be v2.0 ) which introduce a new structure to keep remember the multi-resolution results. But still not mature to use in the project.
     
  20. johnny_karas

    johnny_karas

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

    I'm not familiar with the Runtime texture compress technique so I can't comment on it. In my knowledge and working experience, if you wish to use a texture have high quality you have to compromise the size. And the only technique I know in compress texture in a OK quality is DTX and PVR algorithm. So I doubt that is the only way I can go for.
     
  21. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Hi Jwu,

    I'm trying to achieve sprite culling with exSoftClip although I'm unsure if this is the right way to do it.

    Here's an example of my code:

    Code (csharp):
    1.  
    2.         if(clipper  playfield) {
    3.             Transform t = playfield.transform;
    4.             clipper.transform.position = Camera.main.transform.position;
    5.             playfield.transform.parent = clipper.transform;
    6.             clipper.UpdateClipInfo();
    7.             clipper.UpdateClipList();
    8.             playfield.transform.parent = t;
    9.         }
    10.  
    Short explaination of what the code tries to achieve:
    Basically, every object that can be seen by my camera is a child of "playfield" in my hierarchy. Now I want everything clipped that's outside of the camera's view. The clipper has the exact same size as the camera and its position will always be updated to the camera's position.

    Now here comes the tricky part: Since I'm moving the clipper and camera as one unit it's a bad idea to make the playfield a child of the clipper, because this would also move my playfield with the camera.

    I also noticed that calling either one of the update methods of exSoftClip seems to only fill but does not clear the list of objects to be clipped.
     
  22. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Well, just after posting my question I found out what was missing. A simple call to the Commit() method and it's working almost perfectly. Yay! :p
    There seems to be a problem with rotated sprites though. As a fix I use a slightly increased size for my clipping rect.
    Is there a chance that this problem will be fixed some time soon?

    EDIT: maybe my solution is helpful to others so here's the fixed code snippet ...
    Code (csharp):
    1.  
    2.         if(clipper  playfield) {
    3.             clipper.transform.position = Camera.main.transform.position;
    4.             clipper.transform.rotation = Camera.main.transform.rotation;
    5.             playfield.transform.parent = clipper.transform;
    6.             clipper.UpdateClipList();
    7.             playfield.transform.parent = null;
    8.             clipper.Commit();
    9.         }
    10.  
     
    Last edited: Mar 26, 2012
  23. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hello,

    I would like toask you for some tips about using Ex2D (I am evaluating Unity and some 2D Toolkits for it) to realize what we could call an ol' school 2D beat'em up with sprites that can move horizontally, jump along the Y axis, and walk up and down with the Y axis movement here affecting the z-index so to speak. One would need to change the drawing order of sprites according to the distance from the camera in order to have characters walking in front of some objects and behind them according to their position on screen.

    The problem, as I am seeing with Cocos2D too and the re-ordering in their scene graph, is that such re-ordering is easy for children of the same batch node/texture atlas, but there are considerable more problems if you mix and match different atlases and multiple childrens of the same batchnode and keep z-ordering correct according to the formula you are using.

    How to deal with this in Ex2D? Is it possible to fetch all animations from the same texture atlas but to have each sprite be independent (separate draw call per sprite even though they use the same atlas)?
    How would you approach this kind of scenario with your toolkit?

    Thank you for your help!

    My Best Regards,

    Panajev
     
  24. fgielow

    fgielow

    Joined:
    Jan 3, 2012
    Posts:
    122
    Hey!
    Thanks for the answer.

    I discovered why .pngs are so much smaller before the build procedure. It is basically because .png is a format that is optimized for being small in disk space, while it cannot be read at random pixel coordinates. When that .png texture is 'built' into the final release, it is converted to other structures which can be read at random coordinates. This greatly improves in-game decompression performance, but increases the size needed for storing the texture in disk. I am replying because I thought that info would be useful to others too.



    Regards,
    Fernando.
     
  25. yotes

    yotes

    Joined:
    Mar 18, 2012
    Posts:
    15
    Hi man, wow i've been looking some stuffs of this tool, and looks great. I'm thinking in buy it, but currently i'm using another tool, that is more simple, but it has a feature that I love, the filled sprite (http://www.wyrmtale.com/orthello/sprites). Does this tool has something like this? Thanks, and keep the good work!
     
  26. johnny_karas

    johnny_karas

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

    Glad you figure out the way. For rotated in clip, basically current clipping system is lack in support this. Because the soft-clip calculate the clip rectangle in CPU, it is difficult to let it support rotating sprites. Plus I found sometimes there will have blinking when using clip.

    However I'm going to introduce shader for clipping. So when sprites under the list of clip object, a clipping shader will be applied and all clip will be calculate and render by GPU. I'm going to finish this in the 2nd milestone of our new game MoneyWtiches. Which may be the first game use the new ex2D GUI system. After we publish the game, I will release the new ex2D GUI framework with it and that would be July in this year. But I think I will release GPU clipping code early in May.

    So please wait for our game and the new clipping system :)
     
  27. johnny_karas

    johnny_karas

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

    The ex2D batch is based on Unity rendering system. So basically it is Unity doing the batches. The tips for making less drawcall in ex2D by batching can be found here: http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:advance:less_drawcall. In short, only the sprite with the same material can be batch together and ex2D can't support customize batches also unable to re-batch things in the runtime, they all be done by Unity3D dynamically.

    So if you have all animation in one atlas and use them in the same scene, they would be batched together. The way you separate them is make them in different material (just duplicate them), and each one use one of the material.

    My question is, why you want to do that? Increase the draw call will affect the performance in Mobile device and even PC.

    BTW: for depth control, ex2D provide a Layer Manager system which can help user organize the scene depth and change layer dynamically without affect others.
     
  28. johnny_karas

    johnny_karas

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

    I'm not sure I fully understand filled sprite do based on the documentation, anything wrong please let me know. My understanding is it is a tilling pattern in a big mesh and keep the UV changes. I think this can be done by changing the tilling and uv in Unity material. :)

    Regards,
    Wu
     
  29. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Sounds great! I'm really looking forward to the GUI framework and your new clipping system. :)
     
  30. mr-zafod

    mr-zafod

    Joined:
    Mar 22, 2012
    Posts:
    13
    Good day!
    If Im not wrong you mean that I can construct a 'tiled mesh' using ex2D? Can you provide more if you dont mind.
     
  31. Neil_Rowlands

    Neil_Rowlands

    Joined:
    Mar 27, 2012
    Posts:
    1
    I have a question about the _ex2D_AtlasDB and _ex2D_SpriteAnimationDB files that Ex2D adds to the Unity project.

    I am working on a project where sometimes all or some of the sprites in a scene will turn magenta.
    Rebuilding the above files then fixes things.
    The problem (so far) has shown up when loading a scene that someone else has been working on.

    Currently we have these files under version control, and are wondering about removing them from that and just keeping local copies. Do you have any recommendations?
     
  32. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    What about loading the atlases at runtime using resource.load into a dictionary that uses a common name, and then using SetSprite on a instanced standard prefab to create your sprites?

    So your code might be something like: (simplified)

    if( BigRes ) Atlases.Add( "Sprites", Resources.Load("MyBigAtlas") );
    if( SmallRes ) Atlases.Add( "Sprites", Resources.Load("MySmallAtlas") );

    and then walk each sprite atlas to build a dictionary of sprite names, then just create a sprite by referencing by sprite name.

    The only real downside is that you would have both sets of textures in your project, but it seems that is what you want.

    Perhaps there's a downside to this approach that I'm not seeing?
     
  33. johnny_karas

    johnny_karas

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

    You misunderstanding, the tile-map/tiled mesh editor is still under developing, the only thing can do tile right now is use a separate texture and do tilling and uv setting for the material use Unity's building material system.
     
  34. johnny_karas

    johnny_karas

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

    We do meet some problem when multiple member change atlas in ex2D and use version control manage them. I suggest you still use version control for atlas DB ans animation DB, but if you got error, rebuild them locally.

    To kill the bug, I'm trying to introduce a new structure in ex2D v1.3 (will be v2.0). So before that, there is not a perfect way for this. Hope you can understand.
     
  35. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Thanks for the answer, I guess I made some confusion when explaining myself earlier on.
    My question was not about how to batch items and how to reduce draw calls, I do understand how a texture atlas helps in this case (both to reduce draw calls and to avoid redundant state changes).

    Cocos2D uses a scenegraph and renders all objects at a default z (say z=0) using an internal z-index for each node to decide the final drawing order.
    To take advantage of batching on Cocos2D you use a special node called batchnode and accept some limitations (such as using the same blending equation for all batchnode's children... well all limitations that come with not being able to switch render state between primitives as you render them in one go). You init the batchnode with the texture atlas you have prepared (thanks to SpriteHelper or TexturePacker), you add the batchnode to the scene, and then create children of this batchnode which are the actual sprites you see on screen.
    The batchnode is added to the scenegraph with its own "global" z-index and the batchnode children are added to the batchnode's node and receive a z-index which is relative to their parent and used only to sort them amongst each other. Cocos2D does allow you to change z-order of items at runtime: you would want to do that to be able to change their z-index based on the Y position they stand on for the Pseudo 3D effect to work.

    As you can already see, there is a problem when we mix children of two different batchnodes in an environment that is pseudo-3D like FinalFight



    In this case (f you were to minimize the draw calls count) you would have, maybe oversimplifying things, three batchnodes (one for Guy, one for Cody, and one for the enemy Slash). One batchnode would have two children (Slash) and the other two batchnodes (Guy and Cody) would have one child each.
    The two children of the Slash batchnode would have their own z-order but that would only help in understanding which of the two children is in front of the other not to resolve the drawing order between them and Guy's sprite for example.
    The drawing order between the two Slash sprites and the Guy's sprite would be resolved by looking at their respective batchnode's z-index. The net result of this would be that no matter how you try to re-order the sprites based on height, they would still retain their original drawing order that is the one determined by their own batchnode (which makes sense given that elements in the graph you are actually re-ordering) and I would not be able to be in front or behind another sprite just because of the current Y position.

    One quick workaround would be to take a CPU tax (not that big of a problem if your base HW is at least an iPhone 3GS or better, for this kind of games at least) and simply avoid batching and use a draw call per sprite (unless we have a tons of sprites on screen the number of draw calls will still be limited). We would still benefit from using texture atlases when animating the characters and custom engines could still sort by texture and avoid unnecessary state changes.

    But that's Cocos2D, and my current understanding of that framework, here we are talking about your product ex2D and how it interacts with Unity.

    How would you suggest dealing with this scenario (multiple sprites, z-index changes based on Y, etc...)?

    Thanks for your help!
     
  36. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Using different materials would break the batching system, but would also add an unnecessary state change (unless Unity is able to detect that the texture state change is redundant)...
     
  37. geno

    geno

    Joined:
    Mar 11, 2012
    Posts:
    18
    Hi everyone,

    I want to share my code with you guys about how to use exViewportPosition for resolution independent GUIs where sprites can still be animated (say: translated). For example, if you have a GUI bar with several sprites like lives, time, health, etc. on it and you want to let it slide-in from the top screen edge you normally want to group all elements as childs in the top bar gameobject and only move the top bar. This is all fine unless you also want to use exViewportPosition to handle different screen resolutions, because it nails your sprites down at the very point the script "thinks" they should be for the currently used resolution. I think I found a pretty comfortable way to make it work anyway by just adding another script which forces an update to the x/y position of the sprite and after that disables the exViewportPosition component which results in a freely movable sprite at the correct position for every resolution. :)

    There are two booleans for X and Y to be able to decide if you want to skip either X or Y on the forced update. The script does only work with GameObjects that have a exSprite or exSpriteFont component added to it.

    Feedback and suggestions appreciated, have fun! :cool:

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class gExViewportPosition : MonoBehaviour {
    7.    
    8.     public bool applyX = true;
    9.     public bool applyY = true;
    10.    
    11.     public void Awake() {
    12.         exSprite spr = GetComponent<exSprite>();
    13.         exSpriteFont sprfnt = GetComponent<exSpriteFont>();
    14.         Vector3 vOld = Vector3.zero;
    15.         Vector3 vNew = Vector3.zero;
    16.  
    17.         if(spr != null) {
    18.             exViewportPosition vp = spr.GetComponent<exViewportPosition>();
    19.             vp.enabled = false;
    20.             vOld = spr.transform.position;
    21.             vNew = spr.ViewportToWorldPoint(spr.renderCamera, vp.x, vp.y);
    22.             spr.transform.position = new Vector3(
    23.                 applyX ? vNew.x : vOld.x,
    24.                 applyY ? vNew.y : vOld.y,
    25.                 vOld.z);
    26.         }
    27.         else if (sprfnt != null) {
    28.             exViewportPosition vp = sprfnt.GetComponent<exViewportPosition>();
    29.             vp.enabled = false;
    30.             vOld = sprfnt.transform.position;
    31.             vNew = sprfnt.ViewportToWorldPoint(sprfnt.renderCamera, vp.x, vp.y);
    32.             sprfnt.transform.position = new Vector3(
    33.                 applyX ? vNew.x : vOld.x,
    34.                 applyY ? vNew.y : vOld.y,
    35.                 vOld.z);
    36.         }
    37.         else
    38.         {
    39.             Debug.LogError("Unsupported ex2D object!");
    40.             return;
    41.         }
    42.     }
    43.    
    44. }
    45.  
    46.  
     
  38. bryantdrewjones

    bryantdrewjones

    Joined:
    Aug 29, 2011
    Posts:
    147
    Every time I save a scene file containing exSprites, Unity prints out the following warning message:

    Any idea why that is? Everything appears to be functioning just fine, but this warning worries me :)
     
  39. johnny_karas

    johnny_karas

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

    Thank you for your long explain. After reading your post, I'm very proud that the ex2D's Layer Manager system is superior of the system behind Cocos2D. The layer manage system can help you organize the z order in the scene.

    There are three type of layer in the layer system -- normal, abstract and dynamic.

    Generally the normal is for static object, those objects when you put them in the scene you wish you don't want to change their depth. So the normal layer is for background and not delete/added objects. When you change the order or delete item or added item in normal layer, you will change the whole layer structure which cause the depth changes for all objects.

    The dynamic layer actually is what you want for those dynamically spawn/delete objects. When you set a layer to dynamic, you will see a value to fill. That is the depth block you wish to arrange for the layer. For example if you set the number to 200, it means you have 200 depth for all object in this layer. In this time, when you insert 2 objects in it, the object one will be dynLayer.z + 200/2, object two will be dynLayer.z + 200. Since the block is always 200, it won't affect the layer in front/behind it.

    The abstract layer is a layer that when object insert to it, they will have the same z that equals to the abstract layer's z.

    So basically you can put the enemy and player in the dynamic layer and others like background in normal layer. In layer block you can see what kind of material can be batched and the z order is controllable and programmable so there is not too much limitation. The rest of the things can be done by Unity3D.

    Hope these information help you!
     
  40. johnny_karas

    johnny_karas

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

    I notice the problem since 3.5. I have to check the scripts one by one to find out where leaks the resources. So I put this task in my ex2D v1.3 development backlog. Thanks for your report.
     
  41. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hello and thanks for all your help.

    I have a couple of questions to ask you (which might mix a bit with what I sent by e-mail earlier on).

    How are objects added to the abstract layer sorted? I suppose you use a painter's algorithm of some sort to sort the sprites (no pun intended)... is it based on the sprite's Y coordinate? Is it based on the order in which sprites have been added to the layer?

    As I was writing earlier on, sprites in a pseudo 3D environment have to change drawing order based on a few conditions, one of them could be to simply "link" the sprites' Y coordinate to the drawing order. You would need to pay attention not to do that when the sprite is jumping, as it is one of the cases in which a change in Y coordinate should not imply a change in fake Z/drawing order.

    How would I handle that with the dynamic layer?

    Say I have 4 sprites moving independently up an down the screen, say that they are walking, how would I change the draw order for these sprites? Editing the sprite's z or is there a z order variable (some system expose an integer zOrder variable not linked to the vertexZ directly?)

    Thanks for your answers!
     
  42. ShawnMcCoo1

    ShawnMcCoo1

    Joined:
    Dec 26, 2011
    Posts:
    39
    When my app first starts up and instantiates my sprite prefab it shows the atlas containing the animation before it actually starts rendering the animation correctly. I'm on 3.5 with the latest version of ex2D.
     
  43. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    I'm using the latest evaluation copy and get the following errors when I add a new PNG to sprite atlas:

    $scr1.png

    PS: the same thing under Win7

    I tried to repeat it and always is the same - I can't create an atlas
     
  44. ShawnMcCoo1

    ShawnMcCoo1

    Joined:
    Dec 26, 2011
    Posts:
    39

    I get this as well as:

    'Assets/.ex2D_AtlasDB.asset' is not a valid asset file name.
    UnityEditor.Asset

    and

    UnityException: Creating asset at path Assets/.ex2D_AtlasDB.asset failed.

    When trying to import assets using the newest Unity.
     
  45. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124

    Let me try to explain what we would do given the need to build a 2D game with depth sorting need.

    First let's say we define character sorting order with a "depth" value and ignore y axis movement for the moment. For the final game I suggest handle actor's depth value and y-coordinate separately to make things simpler. We would make the layer structure like this:

    MainCamera
    = HUDLayer
    = CollidersLayer (abstract)
    = FXLayer
    = PawnsLayer (dynamic)
    = ShadowsLayer (abstract)
    = BackgroundLayer (dynamic)

    And lets say a pawn (player or npc) in the game has a prefab structure like this:

    PawnPrefab (no exLayer here)
    = Collider (Unity collider, usually I use CapsuleCollider) (exLayer)
    = Weapon (or misc)
    = MainSprite
    = Shadow (exLayer)

    After you instantiate the prefab or initialize it in any way you want, you need to assign each part to their corresponding layer parent:

    Collider.layer.parent = CollidersLayer;
    Shadow.layer.parent = ShadowsLayer;

    We don't want to attach layer to the main pawn sprite because the depth is changing all the time and we want to manage it by script. But you can take advantage of knowing the z-coordinate range at runtime thanks to dynamic property of Pawns layer:

    Pawns z-coordinate range = ( PawnsLayer.transform.position.z, PawnsLayer.transform.position.z + PawnsLayer.range )

    range is a property of exLayer, it represent the value you defined in LayerMng editor for a dynamic layer. Sorry our script reference is not up to date at the moment, we will get it updated as soon as we got time.

    With the range calculated, you can write your own depth management script to sort the z-coordinate of Pawn.MainSprite within the range.

    I'm not sure here, jwu will answer this better. But I think you should not use Abstract layer if you DO want a specific sort method.



    And for colliders, since we put them into an abstract layer, all the colliders will share the same z-coordinate, then you can manage if they should collide with each other with Unity's layer-based collision detection.

    ex2D doesn't have its own collision system, we find Unity's physics system good enough at the moment. We will probably add a custom collider shape editor in the future but there's no fixed date.

    That's pretty much what we would do for an action game with dynamic depth sorting. We think it's a good solution since the structure is very clear, no hidden magic numbers, no reworking if you want to add a new layer deep into production. All you need is a little depth sorting management script which is not a big deal IMO.

    I hope this helps, if you need more details or anything please let us know.
     
    Last edited: Mar 30, 2012
  46. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    @soulburner, @ShawnMcCool

    Since Unity3.5 we have to change the naming for ex2D Atlas database and SpriteAnimation database. And the evaluation version is not up-to-date with Unity3.5. We are sorry about that, but we are in a critical stage of our upcoming game so lack of time is a big problem here.

    We would like to provide help. If you want to evaluate ex2D just drop us a mail and we will send a copy of ex2D to you. The copy does not contain license so you can try the full feature of ex2D first, and pay later if you like it.
     
  47. ShawnMcCoo1

    ShawnMcCoo1

    Joined:
    Dec 26, 2011
    Posts:
    39
    I actually bought ex2D a few months back. I'm quite pleased with it. But, I'm looking forward to updates that resolve this issue.
     
  48. nantas

    nantas

    Joined:
    Feb 11, 2010
    Posts:
    124
    Hi Shawn,

    We use mailing list to deliver updates to users purchased on our website. We sent updates to email address you provided during the purchase process. If you can't find the mail or want to use another email address please drop us a mail. I will send you the latest build.

    I think the error you met is due to the not-up-to-date version of ex2D. You can confirm this by checking the ex2D version in Windows->ex2D->misc->About. You should see ex2D v1.2.4 (120227) if your version is the latest official release.

    And if you subscribe to our beta distribution mailing list, you can get ex2D v1.2.5 (120309) at the moment.

    Subscribe link: http://eepurl.com/hapI-/
     
  49. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    That would be great! I've sent you a private message
     
  50. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hello and thank you very much for your answer, I think I know now what code to bring over and what I should focus on, sprites-wise :).

    I would like to ask you a question about camera and parallax/scrolling layers. Does ex2D bring some custom components that are designed to support those two elements?

    P.S.: a more practical problem. I have been trying to get my backgrounds in a Unity3D scene with ex2D and line it up with the camera.
    The backgrounds are multiple 2000x640 (three of them inserted into a texture atlas) and I have tried setting the anchor of the background on the bottom-left, its origin at X,Y (0,0) and the camera at (480,320), size 320, and resolution of 960x480 (Retina display). Is this a bad set-up?
    I am asking you this question because the background image does not line up perfectly (horizontally) with the camera (the background starts like 20 pixels away from the left side of the camera view, so I can see the default blue background on the left side instead of the background lining up against the left side of the camera). Is it because the texture is non POT? I got a bit too accustomed of using NPOT textures on iOS (on 2D games did not feel the need for mip-maps or GL_REPEAT).