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

    spanjoar

    Joined:
    Dec 11, 2010
    Posts:
    30
    First of all: I am a noob, so please go easy on me. Here's my question:

    I have 3 animations, Idle, Run Left, Run Right; I can get each one working fine. My problem is though, I'm not sure how to switch between them. I have them on 3 separate atlasas attached to a game object. What I want is, I press the left key, left animation plays, right key, right animation, no keys, idle. Any advice how I can do this? Please keep in mind that I'm pretty new to coding.
     
  2. i-tech

    i-tech

    Joined:
    Jan 2, 2011
    Posts:
    195
    hi there. Does anyone recommend a certain sprite size. Like in the example of this post(the cow).Would it be good to have a 80x80 sprites and so on..
     
  3. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hmm, I wish there was a particle creator to go along with the Brady. :/
     
  4. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    First, I apologize for the late reply. Once again, it seems something was messed up with my subscription to this thread as I only just now received a notification.

    @spanjoar
    I would probably suggest having a look at the side scroller prefab that is part of Unity's standard assets packages. It has some logic in there that detects these different states, and you might even want to use the prefab itself to control your character. But you'll probably want to us DoAnim() for most of it, as opposed to PlayAnim(), so that you don't wind up re-starting the animation for every frame that your code decides that the "Run Right" animation should be playing, for example.

    @i-tech
    That depends entirely upon your specific game design, target hardware/resolution, artistic design, etc. There's not really any way to make a recommendation across the board. But I would just say, keep in mind all the different animations you'll need, and then see what will fit on a single atlas. If you will need more than one atlas to hold all your content, be aware of any memory limitations on your target platform.

    @jrricky
    Speaking of which, I recently was informed about TimelineFX, which is so awesome, I'm now helping to promote as a companion tool to SM2 (if ordering it, please order it through the link on the SM2 page so I can get credit for the referral):
    http://www.anbsoft.com/middleware/sm2/

    This is a really nice compliment to SM2 if you want to do really cool-looking particle-like effects, but for really cheap (low-fillrate and CPU cost). I've played with some of the explosion effects as sprite sequences and they look great. And it's much more efficient for mobile platforms than spawning lots of particles which eat fillrate and CPU.
     
    Last edited: Mar 18, 2011
  5. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Oh wow, thanks Brady!! For $50 thats just what the doctor ordered!! :D
     
  6. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    BTW, TimelineFX is so awesome (some of the best procedurally generated explosions I've seen) that I've decided to promote it as a great companion to SM2. You'll find a link to it at the bottom of the SM2 page (www.anbsoft.com/middleware/sm2). If you heard about it from me and decide to order TimelineFX, please use the link on the SM2 page to order so that I receive proper credit for the referral. :)
     
  7. malyna

    malyna

    Joined:
    Jul 9, 2010
    Posts:
    105
    TimelineFX looks pretty awesome, but why the editor takes 25 % of CPU usage ? Or it is only me ? Phenom II 955.
     
  8. YueFeng

    YueFeng

    Joined:
    Feb 14, 2010
    Posts:
    24
    Hi Brady,I used Unity3D 3.3.0 and old version of sm2 ,but have some problem, can sm2 1.84 Support 3.3.0 ? thank you!
     
  9. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @malyna
    I don't know, I didn't write it, I just think it's a great compliment to SM2 so am helping to promote it on the SM2 page. But I have noticed the editor seems to eat up a LOT of CPU. But that's okay since it's just a way to render out sprite sequences.


    @YueFeng
    Yes, the latest version of SM2 supports all versions of Unity 3. Thanks!
     
  10. Hilm

    Hilm

    Joined:
    Nov 2, 2007
    Posts:
    338
    Hey,
    So I'm having a strange problem - basically I have a left and right button to scroll thru a few items.
    I then have a select button... For some reason however the left/ right buttons appear to be calling the select function - even tho neither of them are set to invoke the select buttons method. (And they still run the left/ right function there actually setup to call)...

    Whats weirder is that this only happens when the select button is in the scene...

    I have checked the collision mesh of the select button, and it's not overlapping the arrow buttons so theres no way both could accidentally be pressed...

    I'm a little stumped... Any ideas what the issue could be?
     
  11. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Is this an SM2 question or an EZ GUI question?

    If EZ GUI, my hunch is that you're using one of the pointer types that includes the "RAY" type. Read the EZ GUI docs for what the "RAY" pointer is used for (i.e. mainly for FPS games). Using any of the "RAY" pointer types in an incorrect context will wind up with an extra "touch" being fired through the center of the camera.
     
  12. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
    Hey Brady...Sprite animations arent affected by Time.timeScale?
     
  13. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Not by default. This is so pause menus that use animated elements can still work. But you can easily change that by uncommenting the #define at the top of SpriteAnimationPump.cs that says "USE_DELTA_TIME".
     
  14. ssmchan

    ssmchan

    Joined:
    Nov 6, 2010
    Posts:
    72
    Dear Brady,

    I have bought your SM2 and really enjoy your effort!! thanks!

    I would like to have your recommendation that what is the right setting which can make 2D graphic look more clear on iPhone? I have see the result in Mac is good but when I build in iPhone the graphic seem downgraded? any idea?

    Thanks in advance.

    Regards,
    Simon
     
  15. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It could be compression. But for a complete list of all the recommendations regarding clarity, see the "Texture Sharpness" topic on the first page of the SM2 docs, as well as the "Images are blurry" topic in the Troubleshooting section of the SM2 docs. If you follow all of those recommendations, you should be able to get as clear a result as possible in Unity.
     
  16. ssmchan

    ssmchan

    Joined:
    Nov 6, 2010
    Posts:
    72
    Dear Brady,

    Thanks and we will try it again.. :)

    Regards,
    Simon
     
  17. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Having a little trouble with the supersprite, I have three animations run, jump and idle, but since jump wouldn't work correctly with the packedsprie I was trying to use the supersprite but it seems that the sprite doesn't display or call the animations what so ever, I went to the main site and followed the tut on the supersprite several times to see what I was missing, but to no avail. Has anyone done the supersprite that has had the same trouble and could tell me how to fix this? Now I have the same sprite that I am using for the windows phone 7 version that I am doing and the sprite sheet works fine and I know this is a great program also but just needing some help with it.
     
  18. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    If the jump animation issue is the same one you have mentioned in PMs before, then using a SuperSprite won't help because a SuperSprite is just essentially a proxy for a PackedSprite. I thought we pretty well established that the reason the jump animation wasn't playing was because somewhere in your code, you were calling another animation right after it, thus overriding the jump animation immediately?
     
  19. Daiboken

    Daiboken

    Joined:
    Mar 8, 2011
    Posts:
    28
    Hello Brady! we recently purchased your software and it's pretty amazing! we only have 1 complain about it, when the first sprite animation ocurrs, a SpriteAnimationPump object is created dinamically and it makes a global frame slow during a little period of time. We want to know if is possible to have that object (SpriteAnimationPump) created from the begginning or if is possible to reduce the overhead produced by SpriteAnimationPump creation.

    Thank you very much!
     
  20. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    I thought thwas the issue also so I tried supersprite to see if that would just enable and disable a gameobject so that the sprite jump would be called all by itself but the that didn't work as it didn't call either gameobject like it showed in the video. As a matter of fact the sprite never displayed at all so that is why I am asking the question, so there is no real solution for my issue? I am calling the jump animation just the same way that I would call any animation, there is no animation in my code overriding it, it is not being called for some reason or another.
     
  21. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @Daiboken
    Sure, you could create an empty GameObject in the scene, and just attach the SpriteAnimationPump component to it. That should work.


    @tmanallen
    It's too hard to say what else might be happening as under normal circumstances, it "just works", so there has to be some other extraordinary circumstance involved. If you could e-mail me privately with a sample package that demonstrates your problem, I'd be happy to take a look at it and see what might be going on.
     
  22. Daiboken

    Daiboken

    Joined:
    Mar 8, 2011
    Posts:
    28
    Hey Brady, i made what you say and it still creating me a SpriteAnimationPump dynamically. I tryed creating a empty GameObject and attaching SpriteAnimationPump script to it and it happens nothing. Or renaming the gameobject to SpriteAnimationPump and attaching the script to it and it remains creating a new SpriteAnimationPump object.
    Any soultions? Thx a lot!
     
  23. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Ahh, try adding this line to Awake() in SpriteAnimationPump.cs:

    instance = this;

    I'll get that into the next release, but that should do the trick.
     
  24. Daiboken

    Daiboken

    Joined:
    Mar 8, 2011
    Posts:
    28
    That worked!
    Thank you very much :)
     
  25. chunjay

    chunjay

    Joined:
    May 1, 2011
    Posts:
    2
    i'm using the packedsprite script for my scenes in unity. it's an ipad project, so each scene has a 2048x2048 sheet. so far, two scenes. what's great is that the smaller sprites stay where they belong. unfortunately, when i build atlas with the 1024x768 background (on each scene), one cancels out the other. i go back into the other scene to rebuild the atlas, and the background from the previous scene gets deleted. a vicious cycle. they both are assigned different materials to go onto different sprite sheets, so i can't see the problem here.

    can't seem to find a solution so any help would be appreciated. thanks, and i love sm2 no matter what.
     
  26. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That sounds like that one or both of two things is happening:

    1) There is an object in the open scene that uses the material of the object in the un-opened scene, and so it is over-writing the contents of that material's atlas.

    2) There is a prefab in the project folder that uses a material of objects in un-opened scenes, and those objects in the un-opened scenes aren't linked to prefabs themselves, and so they get "left out" of the atlas build.

    This is why it is strongly recommended to make sure each type of sprite in your game is linked to a prefab, because since Unity doesn't provide access to objects in non-open scenes, this is how information gets synchronized between scenes.

    If you've already done this and it is still happening, go to your scene instances of your prefabs with which you're having trouble, and make sure they are re-connected to their source prefab by selecting them and clicking the "Revert" button in the inspector. This will make sure none of their values have been overridden.
     
  27. chunjay

    chunjay

    Joined:
    May 1, 2011
    Posts:
    2
    beautiful. it was definitely the prefab issue. worked like a charm. thanks mate.
     
  28. blacksmithgames

    blacksmithgames

    Joined:
    Aug 30, 2009
    Posts:
    24
    Hi,

    does it support different resolutions for iPad resolution (1024x768), retina resolution (960x640) and normal resolution (480x320)?
     
    Last edited: May 11, 2011
  29. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    Hi,
    How to drag and drop (with the mouse) a sprite made with sprite manager 2 ??? In the XY plane ???
    Thanks for help...

    6R
     
  30. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    @blacksmithgames
    There isn't as yet a built-in way to specify different textures for each resolution, but there are definitely strategies to accomplish this. Mainly by assigning the material's atlas texture at start based on the detected device.


    @p6r
    If you mean how to make a sprite draggable in the scene at runtime based on user input, that functionality isn't part of SM2. You would need to write your own code to accomplish that. However, EZ GUI does have that functionality built-in in the latest beta, and this can be combined with SM2.
     
  31. p6r

    p6r

    Joined:
    Nov 6, 2010
    Posts:
    1,158
    @ Brady :
    It's THE problem : How to code a sprite draggable in a scene at runtime !?! In javascript ??? I can't do that...
    Could someone help me ???

    6R
     
  32. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    To just make it draggable, I think you'll need to add a collider to the sprite object, then when you detect it is being clicked/touched (either by raycast, or by OnMouseDown()). Then, you'll need to monitor pointer movement and move the sprite according to the input delta each frame. So you'll need somewhere to store the position of the pointer in the previous frame, and then check it against the current frame, and figure out how far it moved, and then increment the sprite's position by that much. To convert the screen coordinates to world coordinates, use Camera.ScreenToWorldPoint().

    That should help.
     
  33. Skulltemp

    Skulltemp

    Joined:
    May 2, 2011
    Posts:
    78
    Does SM2 have a way to combine multiple layered textures or sprite sheets into one final one?

    Like discussed HERE
     
  34. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'm not 100% sure which part of this you're referring to. First, you definitely can "dye" neutral-colored sprites to a certain color using SM2. As to combining "multiple layered textures or sprite sheets into one final one", I'm not entirely sure what you mean. SM2 does pack textures together into a single atlas, but it requires you pass it individual sprite images. You cannot pass it entire atlases/sprite sheets at a time.

    Or if you mean if you have multiple atlases each with a different "layer" of clothing, etc, on it, if these could be combined into a single final atlas at runtime, there are two things about this:
    1) If the positions of all the sprites that correspond to one another are the same in each atlas, that could, in theory, be done. However, SM2's packing method is likely to not result in this kind of positioning, so you would need to use your own pre-made atlas in this case.

    2) If #1 is taken care of, then you could theoretically do this at runtime by using Texture2D.GetPixels() and .SetPixels(). You would just use GetPixels() to get the contents of the source layer and destination layer, and then loop through these, multiplying adding each pixel of the source layer to the destination layer, but first multiplying it by the source alpha. Then once you have a processed buffer of pixels, write these back to the destination layer or to a new Texture2D with SetPixels().

    I don't think, however, this would be terribly fast, especially if you have to do it multiple times to add in multiple layers. Unfortunately, as far as I'm aware, Unity doesn't provide a faster method for doing alpha-based "blitting" from texture to texture. Unless perhaps you used some kind of render texture technique, which I suppose could work.
     
  35. Skulltemp

    Skulltemp

    Joined:
    May 2, 2011
    Posts:
    78
    Sorry for not being more clear. I will post an example of the images I use.
    The masking as already been done, so a chest piece which has a hand overlapping it in an animation, has no pixels where the hand overlaps.





    For animations, there are, say 16 frames to a walk animation. The model has 16 animated frames, the shirt has 16 frames, the boots 16 frames, the hat 16, etc. etc.
    All of these are exactly positioned and masked to where, when combined, they form the figure to the exact pixel. All of that is already done.






    I thought Managed Sprites might work, but was unclear of what that exactly does.

    Hmm, if I have to create my own texture atlas, then that won't work very well. It will inevitably REQUIRE there to be NO trimming, so I wouldn't be able to save as much space. I've seen what SM2 can do with trimming and making its own sprite sheets, so I really think that is one of the biggest reasons to even get SM2.
     
  36. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    You can definitely do that with SM2 without any additional work and using its built-in atlas generation. It would just require multiple sprites for each "part" and "layer", and since they would come from multiple atlases, it would still be a handful of draw calls for the character. So depending on your game, that may not be a significant impact at all.

    Otherwise, yes, you would need to use atlases with your elements in pre-positioned places that align, and then merge them together as needed to create a composite atlas with the "outfit" you desire.

    Given that such a composite could be slow to build at runtime, it would probably be worth just using SM2 out-of-the-box and accepting the handful of draw calls for your character.
     
  37. Skulltemp

    Skulltemp

    Joined:
    May 2, 2011
    Posts:
    78
    Awesome, thanks!

    I guess I should have originally just asked "How much do draw calls affect performance?" lol, bc honestly it's purely a 2D game, and there are only ever [that] many images on screen at one time. For a PC, I'm not worried about draw calls- correct? Since PC's are so powerful, dealing with a few hundred isn't a big deal? What my question is, then, would be how many "draw calls" a mobile game can handle?

    I'm trying to think of the average/maximum draw calls (atlases) that would need to be drawn all at once.
    Each character would have a Base + 11ish item layers + 1( pre-rendered) particle atlas, let's just round up and say 15 per character.
    Mobiles are pretty small screen size, so even if it was a heavily dense area, let's say 10 characters. Environment, let's just say heavily itemed area, 20. That's 170, so lets round up to 200.

    200 draw calls about the max under the worst conditions, is that a lot? For PC? For Mobile?

    I'm mainly asking bc I have no idea how much "performance" a single draw call would be.
     
  38. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That's do-able for PC, but 200 would be crippling on mobile. Older iOS devices start to slow down at round 25-30 draw calls. Newer ones can do a fair bit better and are more limited by fillrate (so make sure you're not re-drawing over the same areas of the screen too many times). But 200 would still be way too many even for the newer devices, in my opinion.

    For mobile, you're going to want to figure out a way to consolidate that via batching.
     
  39. Skulltemp

    Skulltemp

    Joined:
    May 2, 2011
    Posts:
    78
    Thanks! :)

    I actually don't even know if the game will even be on mobile. There are currently no plans on porting it to mobile-- however, there are plans to support a mobile version which is tailored more towards casual character building during downtime, such as Crafting, organizing bank items, chatting, etc. These could be limited to the specific screens (or their own unique mobile interface) so no problem there! :)

    Afterall, we live in a generation where we could craft a full suit of armor while waiting at the doctors office, attending class, or waiting in line at the DMV-- and when we get home, able to equip and go out and play with that armor :D
     
  40. BloodWraith86

    BloodWraith86

    Joined:
    May 16, 2011
    Posts:
    136
    I have a question. Is there a way to use both the Transparent Vertex Colored shader AND use basic 3D lighting?

    That way I can have a distant light act as normal where the 2D Sprites can have lighting, like dark in a dungeon with torch lights hitting them with radial lighting?

    I read that the Vertex Colored shader is like an Unlit shader.
     
  41. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Yes, it is like an unlit shader. You could use a regular diffuse shader or other lit shader type, but most of those I'm aware of that come with Unity aren't vertex-colored. So you'd need to find one or write your own (or create one with one of the visual shader tools available out there) to add vertex coloring to a regular diffuse shader.
     
  42. BloodWraith86

    BloodWraith86

    Joined:
    May 16, 2011
    Posts:
    136
    Is there a way to edit your vertex color shader to make it add the regular diffuse shader?

    I notice a lot of shader files are really short and simple looking.

    I'm not really knowledgeable about shaders. I'm trying to find the .shader file for the regular diffuse, but I can't find it, nor can I just click "edit" like most shaders I download.
     
  43. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I think the built-in shader source is all available via Unity's Resources section on their site. I'm not a Shaderlab expert myself either, but I think if you add:
    Code (csharp):
    1. Bind "Color", color
    ...between the braces of your "BindChannels" bloc, it should do vertex coloring.
     
  44. BloodWraith86

    BloodWraith86

    Joined:
    May 16, 2011
    Posts:
    136
    thx! i looked on unity's site already but i'll look again thx
     
  45. probbins

    probbins

    Joined:
    Oct 19, 2010
    Posts:
    216
    Hey Brady,

    I am using SM2 for my project - it has been fantastic so far!

    I have a lot of units on screen at once (tower defence) and when I burn them with the flame thrower each burn sprite adds its own draw call on each unit.

    Anyway to have each animated burning sprite effect on all units just cost a single draw call? Is there any other ways of doing this optimally as I am now receiving performance issues which I believe is directly related to draw calls!

    Regards,
    Pip
     
  46. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    It could be draw calls, or it could be fillrate. Make sure to try the "Mobile" specific blended shaders that come with Unity, or try the "Fast" version of the vertex colored shader that comes with the latest SM2 beta package. These are much faster blended shaders for mobile.

    Regarding draw calls, it could be the "interleaving" issue described in the SM2 troubleshooting. Be sure to have a look under the "More draw calls than expected" section in the troubleshooting.
     
  47. probbins

    probbins

    Joined:
    Oct 19, 2010
    Posts:
    216
    Thanks Brady,

    I did save some draw calls with the interleaving issues.

    I am using mobile additive shaders for most sprites or unlit texture/transparent
     
  48. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,820
  49. b3y0nd3r

    b3y0nd3r

    Joined:
    Oct 5, 2010
    Posts:
    27
    hello there,

    I have a question Brady, sorry if already is asked, but can be SM2 the right tool for making an 2D Rpg in Unity 3?

    Thanks in advance ;)
     
  50. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'm reluctant to say it's the "right tool" for any particular game, but what I can say is that it makes working with 2D sprite-based graphics much, much easier. So if your game design involves that sort of graphical approach, then yes, it's great for that. :) Thanks!