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

SM2 - 2D made easy and efficient!

Discussion in 'iOS and tvOS' started by Brady, Nov 4, 2009.

  1. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I'm having really strange sizing issues. All I'm trying to do is have some simple static sprites and I can't get the game to render them properly. I have tried all the different options, pixel perfect, no pixel perfect, auto resize. It seems to always resize my sprites smaller and move their positions differently than I had them set up in the scene when I run it. Is there something really basic I am missing here? Thanks.
     
  2. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady, as anyone figured out how to handle pausing sprite animations without enabling the time.deltaTime in your SM2 code? I am currently doing FindGameObjectsWithTag then checking timescale = 0 and if so pause all animations with that tag. But of course there seems to be overhead in doing checks like this, so I am wondering if anyone has a better way... Thanks.
     
  3. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @helios, are you using the latest version of SM2? You can check the updates page here: www.anbsoft.com/updates


    @jrricky, at the moment, there isn't a centralized way to do that, like you would do with Time.timeScale. However, I suppose it would be pretty easy to simply add a public scale coefficient in SpriteAnimationPump by which the time elapsed gets multiplied. So if you set it to 0.5, for example, then the time delta that gets sent to each sprite would be half of what it would normally be. I'll probably do that officially, but in the meantime, you could just multiply the value assigned to "elapsed" in the AnimationPump() by a public static float called "timeScale". That should do the trick. Let me know if it doesn't work for you.
     
  4. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    Hey Brady, yes I'm using the latest update through that page. All I'm trying to do is have my sprites proportional to each other. I'm not using an orthographic camera, so I don't need it to be pixel perfect, but whenever I create new sprites, they all are scaled differently. So say I have a person sprite and a table sprite. They are proportional in their source, but when I create a Packed Sprite, their dimensions are way off. Even after running, the returning to the scene. I've tried the auto-resize feature, I'm not sure why I'm having so much trouble just getting sprites scaled the same.
     
  5. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Auto-resize is just to keep the geometry proportionate for successive animation frames which are different aspect ratios and dimensions. IT doesn't have anything to do with proportions relative to other objects.

    What I would recommend if you're not using pixel-perfect is to use the "Size Sprites" wizard (under Tools->A&B Sfotware->Size Sprites). You can select as many sprites as you like in the scene before you use this wizard and it can apply the sizing to all of them in a single batch. The way it works is you tell it the camera you are using, and then tell it the "target" resolution you're designing for at which you would like the sprites to be pixel-perfect (though it doesn't use the actual pixel-perfect feature at runtime, so the sprites will be proportionate at other resolutions). If you don't want them to be pixel perfect at any particular resolution, then just pick a resolution and see what the size comes out to be. Once you get the result you like, you can use this for all your sprites and they will all be sized according to the same standard.
     
  6. xanthoran

    xanthoran

    Joined:
    Nov 30, 2011
    Posts:
    4
    Hello! I posted this on the SM2 forums, but I thought I might try here also.

    I'm trying to make an isometric game with lots of sprites (some animated, some not). Because of the iOS texture size limit, many of my animated characters must be super sprites to fit them all.

    My main issue is the age-old z-sorting problem that isometric games have, where some sprites should be 'behind' others based on the location of the footprint (not the sprite itself). I've successfully calculated the z-order index, and I can even implement exactly what I want if I use simple packed sprites and a single sprite manager, using 'setDrawLayer()'. However, all of my characters and buildings and whatnot will never fit on a single texture for a single sprite manager.

    My question is how to manually force depth sorting for multiple super sprites that are not associated with a sprite manager. I understand that currently, SM2 will automatically do this based on the distance from the sprite to the camera (which is almost what I need), but I need it to base this on the distance from the footprint to the camera (which i have already computed).

    Does anyone know where I might be able to modify SM2 to do this?

    Thanks,
    Peter
     
  7. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    xanthoran,

    Watch this postmortem video from Unite11 from the guys who made Smuggle Truck for iOS.
    http://video.unity3d.com/video/3708116/unite-11-postmortem-smuggle
    They had the same problem and they provide a tool that I believe is free in the Asset Store. Or it may be on their website, I can't remember. It allows you to set the RenderQueue on any material. This implicitly tells the renderer what order to render things from back to front.

    Basically, you will need to manually create the materials with shaders that have the correct RenderQueue values to force the renderer to render in the order you want or use the tools those guys provide.

    You can learn all of the nasty details of shader renderqueue stuff here:
    http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html

    http://unity3d.com/support/documentation/Components/SL-CullAndDepth.html

    Hope this helps.

    Allan
     
  8. xanthoran

    xanthoran

    Joined:
    Nov 30, 2011
    Posts:
    4
    Thanks for the advice, I'll definitly check out the video. I think I was able to set it to what I want though, by simply altering the renderQueue in a script myself:

    renderer.material.renderQueue = renderNum;

    Thanks!

    -p
     
  9. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Render queues can work in some situations so long as you're sorting per-material or managed group. But sort per-sprite between managed groups/materials is another issue. In such a situation, as mentioned in my reply to your other thread on the anbsoft.com forum, I'd just recommend using unmanaged sprites and just adjust Z position.
     
  10. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady,

    Im testing to see if I could use SM2 as a level tiler, but I have hit a bump, where there are lines in between each 'tile' when I connect them as you can see in this pic. Is there anyway to fix this?

    Posted on forum too.

    EDIT: Err, solved? I messed with the atlas filter mode set to Point then texture format to RGB 16 Bit and its cleared up...though my atlas sizes are gonna be big. Any other ideas to help keep size of atlas down would be of help but I found a temp solution.
     

    Attached Files:

    Last edited: Dec 5, 2011
  11. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    EDIT2: Is whatever size shown in the preview mode really what the size of the atlas will be? Currently says 2.0 MB with the RGBA 16 bit texture format, but when checking from finder, the size is 119 KB?
     
  12. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Gotta say after all this time having it and should have said it sooner. This is nice, just did a 2d project for windows phone 7 and when I got back to unity and use SM2, it worked out perfect.


    Thanks Guys.
     
  13. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @jrricky
    Yes, that's the correct size. The file size is probably a PNG or JPG or something, which is not the form it will be in when deployed. Unity is showing you the deployed size.

    @tmanallen
    Thanks for the kind words, and best success in your projects!
     
  14. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady,

    I am using the Sprite Vertex colored shader and I seem to be getting some clipping in my sprites when viewed from different angles. Any ideas how to fix?
     
  15. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Also, do sprites with alpha not batch and always cost 2 drawcalls?
     
  16. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    The clipping may be due to how Unity does distance-based sorting of meshes. It sorts based on the *center point* of the mesh *to the camera*.

    Alpha sprites will batch just fine. But see the troubleshooting section of SM2 for reasons why you might have more drawcalls than expected, and possible remedies.
     
  17. ptdnet

    ptdnet

    Joined:
    Apr 20, 2011
    Posts:
    100
    Often, when I generate an atlas, SM2 puts blocks of garbage on the "unused" areas of an atlas. Usually it's noise, sometimes it's oddly sized versions of the used area, or (somehow) screenshots of my dev environment. What is that?

    I'd post a screenshot, but now it's behaving. When I see it again I'll post it up!

    I'd say usually this isn't a problem, except for when I use compressed images it obviously will not compress very well because the texture is full of garbage.

    EDIT: Got one... this is an atlas with 2 sprites on it. Sprites on the left, but what's on the right?
     
    Last edited: Dec 7, 2011
  18. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Actually, SM2 is just using Unity's PackTextures here. I saw this once before with another user, and the best we could finally figure was that there was something going wrong with his video card or video driver. If not something like that, then if you can 100% verify that only those two images are assigned to any sprites anywhere (including prefabs), then it would have to be a bug in Unity's PackTextures. In which case, I would recommend filing a bug report with Unity.
     
  19. ptdnet

    ptdnet

    Joined:
    Apr 20, 2011
    Posts:
    100
    That came from a project that only contained two sprites, one for each image. You should see the fun ones where it's filled with white noise. It's almost like when the texture is being allocated in memory it's not being blanked first.
     
  20. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    So I've gone through the troubleshooting, and the only solution I can come to based on my game being 3D and using SM2 for particle effects is the Sprite Cut Out Shader :-/ which uses alpha testing which is bad for performance on iPhone. The other solutions only work if the game is orthographic 2d. I wish there was another way.
     
  21. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady, I posted this on the forum:


    Why am I seeing spaces between sprites when there are no spaces at all; I used vertex snapping, but when the camera moves the spaces show/hide, its very jarring... What is this, and how can I fix?
     
  22. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
  23. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Tried that, but it doesnt work...
     
  24. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hmm, a temp solution I came up with was to make the background color the same as the main tile brownish color, but I doubt this is going to work for all situations. As soon as a step over one problem, there is always another to stop me in tracks smh :-/ There has got to be a reason this happens...help is still appreciated in figuring this out.
     
  25. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @jrricky
    See my reply on the official SM2 forum.
     
  26. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Hey Brady I see you guys have updated the SM2 to 1.85 I can't find my activation key is there a way to retrieve it?

    Scratch I found so I just edited this one.
     
  27. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hmm...so it seems SM2/EZGUI is not playing nice with the Unity beta, sprites arent being shown properly, is there a fix on the way Brady?
     
  28. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Actually, all the beta issues should be resolved (except for one particular deployment mode which I'm not at liberty to discuss here).
     
  29. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    So there is a new update for unity beta 3.5?
     
  30. KokonutStudio

    KokonutStudio

    Joined:
    Dec 30, 2011
    Posts:
    10
    We used the SM2 and the 2D Toolkit, and i have to say that for us it's more efficient the 2D Toolkit, the performance, it's simple, fast and a great community in their forum for any problem :D
     
  31. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Stuff like this is popping up in the Console using Unity Beta 3.5:
     
  32. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @jrricky
    No, the problems with 3.5 were on Unity's side, and should have been resolved by the current beta. However, there are still issues with Flash export which are yet to be resolved. The warning you mentioned is just a deprecation warning that doesn't cause any functionality problems, but it has been addressed in the internal development version that will be released soon.


    @KokonutStudio
    Thanks for the great feedback!
     
  33. Disaster

    Disaster

    Joined:
    Oct 31, 2009
    Posts:
    43
    Brady, I was wondering if you had any plans to package up EZ Animator on it's own at any stage? I purchased SM2 a long time ago and I really want to give EZ Animator a try but I don't really have any need for EZ GUI and unfortunately I'm not wealthy enough to buy it just for the animator.

    I've tried Ani.Mate and iTween but I'd much rather use something that is specifically designed to work with SM, kind of defeats the point on saving on all those draw calls otherwise :)
     
  34. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thanks for the question. At the moment, I don't have any plans to break it out into a separate package. Since for performance reasons it needs to know ahead of time about the various specialized classes upon which it operates, it would need to be stripped down to work only with SM2 since SM2 lacks some of the other classes that it supports, so you would get compiler errors (and C# and Unity currently lack any way to do project-scope preprocessors that would otherwise resolve this). If it were altered to be more generic, then performance would suffer due to a need to use runtime reflection, etc.
     
  35. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi Brady

    I'm using SM2 for 2D animations. In my set up i have 2 buttons: one starts the animation, the other stops the animation.
    This works fine (using PlayAnim("anim"), and StopAnim()), however, when I press button one again to play the animation again (2nd time), the animation doesn't play.

    I do have other events occurring when the buttons are pressed, and they are working fine, so I know it's not the code to press the button etc, and i've basically broken it down to an issue with SM2. (edit: or my use of SM2)

    Does anyone use SM2 who might be able to shed some light on this?
     
  36. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi - noone can help with this? I've tried various hacks with no luck. Even tried a simple single push button to Start/Stop/Start and still no luck with the animation playing the second time with PlayAnim.
     
  37. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It sounds like it might be some kind of logic error. Try using DoAnim() just to see (DoAnim uses some internal logic to ignore repeated requests to play an animation if the requested animation is already playing).
     
  38. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    Hi Brady,

    Since moving to 3.5, our team has noticed massive memory spikes when building atlases. Building a small (1024x1024 atlas) gives me a 350MB increase in memory use which is never returned. After building a few atlases, we're having to shut down Unity and restart, which is frustrating. We weren't monitoring memory use before upgrading to 3.5 so cannot say for certain that it wasn't happening, but it has magically become an issue since we upgraded to 3.5 so we're thinking it's more likely than not related to 3.5. Are you aware of any issues or solutions? Should we be reporting this to Unity?
     
  39. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That definitely sounds like something to be reported to Unity. I'll be looking into this as well, and I think I may have a strategy to help. But even so, it sounds like something Unity needs to be aware of.
     
  40. Hungariano

    Hungariano

    Joined:
    Mar 24, 2009
    Posts:
    60
    Hi Brady.
    I have run into a small issue. I dont know if I am missing something but I have made a bunch of PackedSprite objects.
    I check hideAtStart in the editor.
    But when I later try to unhide them by calling mySprite.Hide(false) they do not get displayed.

    If I dont mark hideAtStart in the editor but hide them with code in my Start() function, mySprite.Hide(false) works as intended.

    Could it be something with hideAtStart?? The PackedSprite objects are inside a prefab if it makes any difference.

    Thanks in advance
    /Peter
     
  41. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi Brady
    I feel as though the answer to my problem should be simple, and I'm missing something...

    I want to set the Alpha of a PackedSprite to 50% on an instance of an object. I can't set this at the material side, as the atlas is used across many objects in the scene.

    So, i thought i'd set the colour of the packed sprite on the individual object instead.

    So far i have:
    Code (csharp):
    1.  
    2. var newColour : Color;
    3. newColour.a = 0.50f;
    4. thisSprite.SetColor(newColour);
    5.  
    6.  
    However, whilst the alpha side works, the COLOUR is changed from the object's default white to Black, and hence doesn't make the sprite look correct under alpha (i.e. you see a black alpha'd square rather than the detail of the image inside the square, if that makes sense).

    What am I doing wrong?

    Thanks
     
  42. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    accidental second post - how do i remove this?
     
    Last edited: Mar 14, 2012
  43. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @Hungariano
    I can't think of what would cause that off the top of my head. All Hide() does is disables the mesh renderer (or if the sprite is managed, it sets its vertices to 0,0,0). Are you using the latest version of SM2?


    @mangoblue
    This is because by default your color variable is probably 0,0,0,0, and you're only changing the alpha component. Try something like this instead:

    var newColor : Color = thisSprite.color;
    newColor.a = 0.5f;
    thisSprite.SetColor(newColor);

    or even easier, you should be able to just do:

    thisSprite.Color.a = 0.5f;

    Just be sure to use the upper-case 'C' here.
     
  44. DavidC02

    DavidC02

    Joined:
    Jul 19, 2011
    Posts:
    152
    How can I have an animation for something like 'stop', 'walk', 'run'. I have an static variable that shows me when my character is moving, I want that while true, my character starts walking (one animation), then runs (loop), until the static variable reads false, then stop walking (play this just once), stop (static frame).

    With this I get as far as "running", but then for "slowing down", or walking away, I don't know what to do.
    http://codepad.org/r6OgVsGm

    Thanks.
     
  45. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady, don't remember if I asked before, but why does SM2/EG look like this in 3.5?
     
  46. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @davidc02
    I think that instead of using a counter (which won't show you what direction you're going, i.e. whether you're slowing down or speeding up), you should use an enum. Or I suppose you could use a counter and then combine it with a signed value that indicates which direction things are going. But fundamentally it's just an issue of finding a logic pattern that works for what you're doing, and then call DoAnim() to play the appropriate animation.


    @jrricky
    You need to get the latest version. 3.5 changed some of the way controls get laid out.
     
  47. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Thanks I did! :)
     
  48. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I know this will sound like a terrible question but how do I swap images from with in the same atlas? So say I have objectX, using materialX. MaterialX is an atlas with a dozen sprites. How do I swap image 3 to image 2?
     
  49. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    This is demonstrated in the sample project that comes with SM2. Just have each "image" as a single-frame animation, and then just "play" that "animation", which will switch it to that image. Alternatively, you could put all the images into a single animation and set the framerate to 0, and then call PlayAnim() and pass in the animation and then the frame number.
     
  50. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Ok,
    I am looking to change the image on event, so onTriggerEnter... Change image.