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

    deadfire52

    Joined:
    Jun 15, 2011
    Posts:
    101
    Thanks alot Brady, I was afraid of upgrading because I didn't want to mess something up. Working great now!
     
  2. deadfire52

    deadfire52

    Joined:
    Jun 15, 2011
    Posts:
    101
    Just started to make a new sprite, same thing happened but it seems that a computer restart fixes the problem and resizes the sprite goes back to its normal size.
     
  3. deadfire52

    deadfire52

    Joined:
    Jun 15, 2011
    Posts:
    101
    Hey, how do I get a box collider to set itself to the size of a trimmed sprite that has a Texture_Offset?

    I've got this but it only works with the Middle_Center offset.

    Code (csharp):
    1.  
    2. function Update(){
    3.     boxCollider.size = Vector3(MainPS.width, MainPS.height, 2.5);
    4. }
    5.  
    I figure I have to set the boxCollider.center to the center of the sprite but that doesn't work either

    Code (csharp):
    1.  
    2. boxCollider.center = Vector3(MainPS.width/2, MainPS.height/2, 0);
    3.  
     
  4. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Hey Brady, just curious, is there any FREE iOS demo (on Appstore) showcasing how fast your SM2 can do?? I am very interested.
     
  5. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @deadfire55
    Actually, if you just add the box collider component to the sprite, it should automatically be both positioned and sized to fit. Also, to get the center of a sprite, use its .GetCenterPoint() method. That gives you the center in local coordinates.


    @I am da Bawss
    I don't have any one particular app in mind, except perhaps Bouncing Jack which I don't recall if it has a free demo or not, but you'll find several examples in the A&B Soft showcase forum here, many of which have free demo versions:
    http://forum.anbsoft.com/viewforum.php?f=17

    Some of those are EZ GUI-only, but you'll also find a lot of examples which make extensive use of SM2. Thanks, and please let me know if you have any other questions.
     
  6. deadfire52

    deadfire52

    Joined:
    Jun 15, 2011
    Posts:
    101
    Just what I needed!

    Here it is for anyone else:

    boxCollider.size = Vector3(MainPS.width, MainPS.height, 2.5);
    boxCollider.center = (MainPS.GetCenterPoint());
     
  7. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Also, if you just do:

    mySprite.gameObject.AddComponent<BoxCollider>();

    To a sprite that doesn't already have one, it will automatically fit the collider to the sprite.
     
  8. LimeSplice

    LimeSplice

    Joined:
    Jul 15, 2011
    Posts:
    111
    Hi Brady
    I'm wondering whether its best to use an ortho or perpective camera with SM2? I want to show good depth between sprites (landscape elements - movement, to characters), and ortho of course looks totally flat?

    Please excuse if the above sounds noobish - I am one after all ;)
    Thanks
     
  9. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It really depends on what you are wanting for your game. As far as apparent "depth" between 2D sprites, that can be completely accomplished by moving things at different rates (parallax) and making things different scales based on the perceived depth desired. Ortho only looks "flat" if you are look at objects which are supposed to have depth themselves, i.e. 3D models. If you're just look at all sprites anyway, the sprites are already flat.
     
  10. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    Hi, I noticed that when I had to move my project around all the references to the source textures of all my sprites' animations are gone, meaning I got a whole load of those empty grey boxes with NONE on it instead of my source frames in the timeline editor... Now, this wouldn't be a problem if I didn't have to edit the sprites anymore, but alas; I do...
    Seeing that my game is basically 99% of SpriteManager sprites, manually reassigning would be quite the horrendous task.
    Is there any way to fix this besides me manually reassigning every frame again?
     
  11. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That's because Unity tracks assets by GUID, not path. So if you move assets out of your project folder and then back in, Unity may assign new GUIDs to them since for all it knows, they are new assets. This causes your previous references to be lost, since it looks them up by GUID. So make sure not to move your assets out of the project folder and back in. If you need to relocate a project to another computer, etc, I recommend exporting a package, which preserves all the GUIDs and references.
     
  12. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    Thanks for the info! Much appreciated. But is there a way to re-assign the frame's GUID after the original references are lost without manually removing/adding sprite frames?
    Like, could I for instance go over all the sprites in the project, their animations, said animations frames; fetch the GUID, see if I can retrieve some sort of filepath from that, fix the path and assign the good filepath's GUID to the spriteframe?
    Not sure if that's possible and my apologies if this was a retarded question, I've got very little experience with GUID and all that stuff. :)
     
  13. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    No, that won't work. Think of the GUID as sort of a "serial number" that uniquely identifies an asset in Unity's asset database. If you move an asset out and then back in, Unity will assign it a new GUID. So there's no way to get at the old GUID's info that I'm aware of. I don't think there are any Unity editor APIs that will give you that info for an asset that is no longer associated with that GUID. I suppose you could try calling AssetDatabase.GUIDToAssetPath() with an "old" GUID, but I really don't think that will work since it has to do a look-up of the GUID and find the corresponding path, and I'm pretty sure that gets cleared out when the asset is removed/deleted.
     
  14. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    Hmm, okay. Guess I'll have to find another way then. I take it you store no other information of the source texture in a sprite frame then just the GUID and some coordinates?
    Again, thanks for the info!
     
  15. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes. Now under certain circumstances, the path *might* be stored. You'll find that possibly in the .framePaths array of a PackedSprite's .animations array (which is an array of TextureAnim objects). So you could iterate over them, accessing it like so:

    ...
    mySprite.animations[animIndex].framePaths[frameIndex]...

    But there's no guarantee that info will be there. If it is, however, you could make sure the images are restored to their previous paths, and then re-grab the GUIDs from the images (the new GUIDs) and store those in the .frameGUIDs array (the elements correspond to the paths array).
     
  16. Maph

    Maph

    Joined:
    Sep 19, 2009
    Posts:
    55
    framePaths array has empty values, the frameGUIDs values are not; but AssetDatabase.GUIDToPath results in an empty string when using one of the "old" GUIDs as you expected.
    In other words, I'll have to reassign them all manually. I'll just write an editor script that assigns animations/frames through an xml file for some kind of batch import/update.
    Thanks for the help anyway. :)
     
  17. 2Dsprite.com

    2Dsprite.com

    Joined:
    Jun 9, 2011
    Posts:
    74
    Is there a function for SM2 that allows you to do something at the END of the animation? (Once it has completed)?

    I've heard SM2 can make it do stuff like destroy the object or loop the animation in the editor, but I need to run events after an animation has completed playing.

    So far I'm disappointed in other sprite packages and figure this one might be better. Also, is the price staying the same ($150) despite competition? If so, why? Is it more advanced than the other 2D extensions by a large amount?
     
  18. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, SM2 has a method called .SetAnimCompleteDelegate() that lets you assign a method to be called when any animation reaches the end. The use of this feature is demonstrated in the sample scene that comes with the package.

    Thanks!

    As for the other packages, I can't say for sure as I haven't used them to any great extent, but I can say SM2 is in very wide use in actual production work.
     
  19. malyna

    malyna

    Joined:
    Jul 9, 2010
    Posts:
    105
    Hello Brady,

    Are you working on new features in SM2 ? or maybe on SM3 ?
     
  20. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    SM2 has been getting new features all the time, since the first release. No definite plans for an "SM3" at the moment though. Thanks!
     
  21. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady, one thing about SM2 that seems to be increasingly bothersome is that I can't delete frames before the last frame. I would have to start from the last frame and delete till I get to the frame I want removed. Is this something that is noticeable to anyone else?

    EDIT: it works now, twas just probably something to do with the gameobject...
     
    Last edited: Aug 30, 2011
  22. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Actually, it will delete whatever frame you have selected. Just click on the desired frame and hit the delete key.
     
  23. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Hey everyone,

    New to SM2 and am having an initial setup issue. I've got my object and have setup a sprite atlas + animation on it. When i setup the animation i set it to "trim" the images automatically and when i did that it moves the animation around when played. if i don't use the trim option the animation plays nicely, but is obviously much much larger of a file. ARe there any settings i need to set in the Packed Sprite option to tell it that its been trimmed?
    Thanks!
     
  24. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, you can let it be trimmed while not moving it if you set the anchor setting to something like MIDDLE_CENTER. Otherwise, TEXTURE_OFFSET will position the sprite according to where it was on the original canvass.
     
  25. smithlim

    smithlim

    Joined:
    Nov 18, 2009
    Posts:
    21
    Hello~
    I am new to Unity3d. ^^
    I would like to show the sprite animation on the GUI.
    I think If I get the texture of current frame, I can show the sprite object on the GUI.
    for example)
    suppose there is a function GetCurTextureOfCurFrame() : this function returns Texture2D of current animation texture.

    OnGUI()
    {
    Texture2D curAniFrame = spriteObject.GetCurFrame().GetCurTextureOfCurFrame();
    UnityEngine.GUI.DrawTexture(Position, curAniFrame , ScaleMode, AlphaBlend, ImageAspect);
    }

    question 1) Is there a function like GetCurTextureOfCurFrame()
    question 2) If not, could you give me any idea?

    Thanks.
     
  26. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    There isn't a method exactly like that because one of the big advantages of SM2 is that your images are atlased, and so you don't want them both in an atlas, AND loaded as separate individual textures. That would just double your memory requirements, and increase your build size. But if what you are wanting is to be able to set a sprite to show a specific frame, then yes, you can do this by either calling .SetCurFrame(frameNum) on a sprite that is already playing an animation, or you can start the animation on a particular frame using the version of PlayAnim() that accepts a second argument that is the frame number. If you just want to change to a particular frame and have it stop there, you can set the animation's framerate to 0 and just use the PlayAnim() method I just mentioned and it will stop on that frame. There is also the "posed" technique mentioned in the SM2 docs and demonstrated in the sample package that comes with SM2 (see the code for the "posed" sprite). The "posed" technique basically just involves playing the animation at a certain start frame and then pausing the animation.
     
  27. smithlim

    smithlim

    Joined:
    Nov 18, 2009
    Posts:
    21
    thank you for your idea ^^
     
  28. spinon

    spinon

    Joined:
    Oct 3, 2011
    Posts:
    1
    Hello,
    We just purchased and installed SM2 and I we are having a couple issues that I can't seem to find solutions to anywhere. In case it makes a difference, we are working on a Mac with OS 10.6.8 running Unity iPhone 1.7.

    The first issue is that the Sprite Timeline is not a window inside of Unity. It is a separate pop up box. It is also throwing four errors:
    "Unable to require resources at 'Editor Default Resources/ Builtin Skins/Lucida Grande.tff"
    UnityEditor.EditorWindow.Show(Boolean) at /Users/build/builds/unity-iphone/iphone/Editor/Mono/Generated/Unity.cs:671)
    SpriteTimelineEditor:ShowEditor() (at Assets/Editor/AnBSoft/Editors/SpriteTimelineEditor.cs:77)"

    The other two errors are for different Lucida type fonts (bold, small and big).

    The second issue is that when we try to create a new atlas, the console will give feedback saying "0 atlases created". The interesting part is that the atlas generator will create a new folder based on the folder name in the Atlas Folder input box but will not create the atlas.

    Any ideas?
     
  29. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm not sure it even supports unity 1.7 ios, it is a couple of years out of date.

    Strongly recommend you upgrade to 3.4 as ios is a heck of a lot faster and more compatible and more stable than that ancient version, plus integrated into the same editor as desktop, so just one editor for everything.

    It will cost $400, for the basic version, but even basic nowadays is several times better than 1.7 plus compatible with everything on asset store. What I am trying to say is you can't expect any support for 1.7.
     
    Last edited: Oct 3, 2011
  30. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @spinon
    The error messages you describe are mentioned in the SM2 documentation. They are a result of a bug in Unity 1.7 which was never fixed (well, it was fixed in Unity 3.0 and later, but 1.7 still has it and obviously Unity isn't updating Unity iPhone 1.7 anymore). They are innocuous and do not affect SM2 in any way.

    Regarding the message about 0 atlases being generated, check that you have the proper "Scan Project Folder Only" option selected. That is, if you are working with sprites that only exist in the current scene, make sure this option is unchecked. If you are dealing with sprites which are linked to prefabs, then make sure this option is checked. Otherwise, if working with scene-only sprites and the option is checked, it will search for prefabs only and will fail to find them since none exist. Again, this is a limitation of Unity iPhone 1.7. Unity 3.0 and later don't have this problem.
     
  31. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    is it possible to use SM2 to animate the uv coords, or better ye just move them across a few square(256x256) frames, from an atlas generated by SM2, on a 3D-mesh that is not a plane created by SM2? SM2 has great texture packing capabilities, and I'd like to use the sheets created by SM2, to "play" through the "frames" in that sheet, on a 3D mesh in my game's scene.

    So say for example I drag in 16x 256x256 frames(2d png's) for a looping fire-texture, inside the SM2 animationTimelineEditor, then want to play that animation (those frames) on a Mesh, say a 3d-sphere-mesh with UV's already laid out. Has anyone found a means of doing this with SM2 or EZGui(I have both).? I appreciate any insight/help that you can offer.
     
    Last edited: Oct 4, 2011
  32. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @zhx
    Not really, SM2 stores discrete UV sets for sprites, but it isn't really designed to do the same for an arbitrary number of vertices in that way. Plus, depending on how many vertices you have, it could be performance prohibitive to re-assign a ton of UV coordinates to each vertex every frame. Instead, I think you would probably be better off manually creating a regular grid atlas, and then using the 3D object's material's "Offsets" values to offset where the UVs point. That would be a lot faster.
     
  33. DamonK

    DamonK

    Joined:
    Sep 23, 2011
    Posts:
    16
    Hey Brady,

    I am having some difficulty with SuperSprite, since I enlarged an objects image I have 6 different animations on 6 different sprite atlas. Each animation is in a packedsprite which is the child of the super sprite. (is this setup correct?).
    I then spawn lots of the objects. Each plays then pauses a random animation. It works to an extent, except some of the sprites do not appear. If I pause the game and look into the objects supersprite I can see the packed sprite made active has no width or height, even if I give it a width and height the image still does not render.
    Have you encountered this before?

    Cheers, Damon.
     
  34. drgsus2

    drgsus2

    Joined:
    Mar 8, 2011
    Posts:
    54
    Hi Brady,

    is it possible to get the current animation's name or number from a sprite? So if an animation is playing in the PackedSprite "Hero", can I have a separate event, which gets triggered, when this certain animation is playing on that Sprite?

    And on that same note:
    Is it possible to then get the current frame of this animation? So for example: An event gets triggered when "Hero's" "Attack" animation reaches the 3rd frame.

    Thanks :)
     
  35. i-tech

    i-tech

    Joined:
    Jan 2, 2011
    Posts:
    195
    Hi,

    We bought SM a few months ago and it worked great. Now it suddenly does not work anymore. I might have updated unity or something like that. When i import the manager into the project it reports a bunch of errors. The example scene doesn't work too. I tried to build an atlas and it said 0 atlases were build. How can i fix this. Do i need to update SM and how to.

    Kind regards,

    Jernej Beg

    i-tech ltd.
     
  36. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @damonk1
    It sounds like you just need to give the sprite in question some dimensions as it is set to 0x0. You will need to do this at edit-time through the inspector, however, since doing it through the inspector at runtime will not have an effect. The quickest and easiest way to get it sized as desired is to select it and then use the "Size Sprites" wizard, which lets you size it to be pixel-perfect for a certain target resolution.


    @drGsus
    Yes, you can use .GetCurAnim() on a sprite to get a reference to the current animation, if any. You can then call .GetCurPosition() on that animation reference to get the 0-based index of the current frame being played for that animation.


    @i-tech
    It sounds like you might need a later version. You can always get the latest version here:
    www.anbsoft.com/updates
     
  37. photon

    photon

    Joined:
    Mar 2, 2010
    Posts:
    7
    Hi Brady,
    does SM2 support usage of TexturePacker.com made atlases?
    Would be cool, since I could optimize space usage through several options like rotation etc.
    thanx
     
  38. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Not at the moment, not built-in. I'm still considering it as I've had several questions about this, but at the moment my time has been devoted to adding other features and maintaining the library through some of the latest Unity upgrades. But it's a possibility in the future perhaps.
     
  39. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    +1 for texturePacker support!!!.

    Its PVR compression is(in my limited tests) much far better than unity's PVR compression, for specific cases. We use EZGui for its superior handling of low-draw-call unity interfaces, and use TexturePacker for its superior ability to retain detail in PVR-iOS compression. We certainly hope to be able to use to two together at some point, for optimal development.

    For anyone not using TexturePacker(very cheap for its abilities) for their interface compression, I'd strongly suggest you give it a try. For a PVR compressed interface, it can yield EXTREMELY evident differences in compression artifacts! Oh, and and large background images, again, BIG BIG diferences in a PVR compressed image by Unity and one by TexturePacker, give it a try if you havent. http://www.texturepacker.com/ . We dont work for them, we're just sold on the results we've gotten from our battery of tests with their PVR/iOS compression, its stellar in its versatility, compared to Unity's built in PVR compression(no offense intended).
     
  40. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady, I am trying to trigger a sprite animation play during a character animation but it doesn't seem to be working properly...the sprite animation plays after the character animation? Here is the script I am using:

    Code (csharp):
    1. //Play attack sprite
    2. if (att1.normalizedTime > 0){
    3.     meleeParticle.Hide(false);
    4.     meleeParticle.PlayAnim ("Double Slash");
    5.        
    6. }
    Any ideas? Its pretty annoying when its supposed to be simple and it doesnt work...
     
  41. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    This is because normalizedTime is > 0 during the entire length of the animation, so PlayAnim() is going to be called, presumably, every frame. Since, as stated in the docs, PlayAnim() starts the animation playing from the beginning, it is constantly starting over every frame, so it doesn't appear to play. It doesn't actually get a chance to run to completion until your character animation finishes.

    Instead, you should either use DoAnim(), which only starts an animation playing if it isn't playing already, but it would be better to change your logic so that you only call your sprite animation code at the point you want it started, since you're incurring overhead just by calling Hide() and DoAnim() repeatedly without need.
     
  42. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Any Any ideas? Should I do like < 2 frames too then? Or just do normalizedTime = 1 so it only checks that one frame?
     
  43. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Actually, normalizedTime runs from 0 to 1 (which is why it is called "normalized"). So checking to see if it equals 1 would make it not run until it was finished. I don't know of a way to check for something like a "frame" for a character animation. The nearest to that would be .time, which I believe is the time, in seconds.

    I'm not sure where you're putting this code, or under what conditions it gets run, so all I can suggest is to structure your code so that you don't wind up calling methods every frame needlessly. For example, the code which triggers the character animation could also trigger the sprite animation. Or you could use a flag to track when the sprite animation needs to be run, and when the flag is set, you don't run it anymore until it is unset again, or something along those lines.
     
  44. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    sorry I actually meant something like:

    Code (csharp):
    1. if (normalizedTime = 0.1){
    2.    PlayAnim();
    3. }
    I was posting from my phone and wasnt thinking...
     
  45. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Checking equality probably won't be reliable since you won't know in advance what the exact float value at the time the check is done. It could easily skip by your test value. So you would need to do something like:

    if(normalizedTime < 0.1)
    ...

    That would reduce inefficiency, but would still result in redundant calls for 10% of the character animation. Also, you would need to change it to DoAnim(), since PlayAnim() would result in it being 10% behind. But you also wouldn't want to try and make the threshold too low (like 0.001) since again, depending on your framerate, it could skip right past it without ever evaluating to true.

    Doing:

    if (normalizedTime > 0)
    sprite.DoAnim()

    would still work, but I still think the most efficient thing would be to restructure the code entirely so that DoAnim() or PlayAnim() just get called once at the point that the character animation begins.
     
  46. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Solved!

    I did this:

    Code (csharp):
    1. //Play attack sprite
    2. if (att1.normalizedTime >= meleeTimeMin  att1.normalizedTime <= 0.3){
    3.     meleeParticle.Hide(false);
    4.     meleeParticle.PlayAnim ("Double Slash");
    5.        
    6. }
     
    Last edited: Nov 2, 2011
  47. Min Atori

    Min Atori

    Joined:
    Aug 19, 2011
    Posts:
    46
    I'm trying to make a cut scene using Unity's built in animation editor and sprites from SM2. Is there a way to play the sprite manager animations through Unity's built in animation editor?
     
  48. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    No, not really. You might try adding an animation event that calls PlayAnim() on the sprite in question, but I don't think it's going to work in edit mode.
     
  49. Min Atori

    Min Atori

    Joined:
    Aug 19, 2011
    Posts:
    46
    So then SM2 has no way to allow for cut scenes with the animations created with SM2?

    That's kind of a wash.
     
    Last edited: Nov 12, 2011
  50. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Oh wait, I thought you meant in-editor. At runtime, yes, you can just add an event as I said and call PlayAnim() or DoAnim(). It just won't play the sprite animation in-editor.