Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SpriteManager - draw lots of sprites in a single draw call!

Discussion in 'iOS and tvOS' started by Brady, Jan 15, 2009.

  1. teatime

    teatime

    Joined:
    Jun 16, 2008
    Posts:
    129
    Is there a built-in way to "snap" the drawn positions of sprites to a certain level of granularity to get a true retro/pixel-art look at any resolution, or is this something i would have to hack in?
     
  2. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    No, SM doesn't do anything to the transform, etc. So anything like that would need to be done through your own scripts.
     
  3. un4given

    un4given

    Joined:
    May 21, 2011
    Posts:
    1
    Has anybody had trouble adding extra animations?

    I can add it via the PackedSprite + timeline editor, but when I run create atlases nothing happens. The atlas stays the same, even though the animation is 'added' in the PackedSprite UI.

    Is this a known bug or have I missed a step?
     
  4. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    It sounds like something has been missed. If the sprite in question is in a prefab, make sure you check the "Scan Project Folder" option when building the atlas. If the sprite exists only in the scene, make sure it is not deactivated as Unity's FindObjectsOfType() (which is what the atlas builder has to use to find the sprites in the scene) doesn't support deactivated GameObjects.
     
  5. Mårten

    Mårten

    Joined:
    May 16, 2011
    Posts:
    18
    Hello everyone,
    I put together a blog post for first time users of SpriteManager. It's really very easy-to-use, but there were some stuff you had to understand when starting out which I thought I could touch upon. I hope it helps someone :)

    Also I put together some documentation classes for SpriteManager which you can use in UnityDevelop if that's your IDE of choice

    Check it out here: http://www.piecesinteractive.se/blog/spritemanager-beginners-guide-unitydevelop
     
  6. nebula2012

    nebula2012

    Joined:
    May 20, 2011
    Posts:
    9
    thanks for sharing.
     
  7. hooligan

    hooligan

    Joined:
    Nov 26, 2010
    Posts:
    40
    Hey all have a quick question,

    Im using SpriteManager one to do some GUI stuff for my game. Im using a linked sprite manager and updating the sprite myself. The problem I seem to be having is.

    I have a game object which contains 3d text and this gameobject has a sprite attached to it. I move the GameObject and then update the sprite and there seems to be a delay like the sprite has to catch up to the text. It is much more noticeable when i deploy it on the iPhone.

    I've tried a few things such as updating the sprite in LateUpdate etc but cant seem to get it right.
     
  8. kariwm

    kariwm

    Joined:
    Jun 10, 2011
    Posts:
    3
    Hi There,

    I'm currently working on a game and this is the first time so far I've truly been stuck (hence the first post : D). The problem I seem to be facing is the bounding box for Sprite Manager isn't resizing. I've used auto-update in and out of code. I have four objects which are part of a sprite manager -- these objects start parented to the manager, and are then parented and assigned positions above the four characters I have in the scene, (using transform.parent). These are the positions of the players in a 'race (from 1st to 4th position) and it works fine.

    The problem comes when they move. Each Sprite (which has the Sprite Manager set, and their Render Camera set to the perspective game camera) works fine, but the bounds box doesn't update, so when they go outside the box, they 'dissapear'. Am I missing something here? Why isn't the bounding box for the SkinnedMeshRender increasing in size?
     
  9. kariwm

    kariwm

    Joined:
    Jun 10, 2011
    Posts:
    3
    Incidentally, it seems to only be a problem with Sprite Manager **in particular** as using normal Sprites "fixes" the problem. However, I assume there's some performance losses in doing that!
     
  10. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    @hooligan
    I would have suggested LateUpdate, but if that isn't working, I can't think of any way to make it update any later than that. That should otherwise work since it should be able to apply the transformation to the geometry before it is rendered.


    @kariwm
    I don't have it here in front of me at the moment, but I think I remember exposing a setting on the manager object called something like "auto update bounds". There is a setting to that effect somewhere which should case the bounds to be recalculated each frame.
     
  11. Vandash

    Vandash

    Joined:
    May 12, 2011
    Posts:
    11
    Hi Brady, a performance question about SM1 :

    I currently use 4 sprite manager, have about 650 sprites in my game, and moving some of them around every now and then.

    On iPhone, the rendering itself takes 4ms per frame, but the Mesh.CreateVBO takes about 20ms. Is that normal ? Is that caused by me moving around the sprites ?
     
  12. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Depending on the device, yes, that sounds possible with a really high number of sprites since this means the mesh data has to be recreated and the entire vertex array for each mesh has to be re-copied. If sprites are only moving every now and then, try not using a linked sprite manager, and instead, use the "regular" SpriteManager component and then just explicitly tell it to update when something moves.
     
  13. Vandash

    Vandash

    Joined:
    May 12, 2011
    Posts:
    11
    Thanks for the answer :) I'm already using the regular sprite manager, not the linked one. I guess I will have to reduce the sprite position update a little bit ;)
     
  14. aarora2

    aarora2

    Joined:
    Aug 2, 2011
    Posts:
    11
    Hello to all. i m just the beginner of the sprite manager. I have made some basic animation by watching the videos. But i did't know much about this package.. Can anybody tell me how i can move forward?

    a) please tell me which type of camera should i use- Orthographic or perspective.
    b) What should be the size of the Sprite sheets?
    c) What will be the size of field view of camera?
    d) Which plane should i use?

    and many more things which u know so that i can improve the graphics quality and performance[/B][/B](all basics of Sprite Manager so that that will be perfect)
     
  15. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    a) That depends on your game design. Typically, however, for most 2D games, it is easiest and best to use an orthographic projection.

    b) That depends entirely upon what you want to put in them. They just need to be large enough to hold whatever it is you need them to hold. There isn't really a set size they ought to be.

    c) Again, this depends on your game design. However, if you use an orthographic camera, there is no field of view, there is only the orthographic size, which in most cases I would recommend setting to exactly 1/2 the height of your target resolution. So for 480x320 (iPhone landscape), you would set the orthographic size to 160. This results in there being a 1:1 correlation between 1 unit of world space and 1 screen pixel. So that makes it really easy to size your sprites, etc.

    d) I recommend the XY plane. It's sort of the standard, and you'll be working in the familiar coordinate space where X means left/right and Y means up/down. It doesn't really matter which plane you use, but this is the most familiar and in my opinion, easiest to work with.
     
  16. aarora2

    aarora2

    Joined:
    Aug 2, 2011
    Posts:
    11
    Hello to all,
    I am using the sprite Manager package.
    I m using the orothographic camera with size 160.

    I want to play basic animation of water- I have taken a plane of scaling x=2.7 and y=2.3. I have taken Images of water of size 1024*768 and number of frames=25 but there is very low quality.
    So please suggest me what should be the size of Images and what should be the numbers of frames i will taken so that the quality will be good???
     
  17. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    That's a really hard thing to suggest. It depends entirely upon what your ephemeral threshold for "quality" happens to be, as well as some less ephemeral things, such as the target resolution, the size of the water on-screen, the game type, and several other things.

    I would, however, suggest you first try disabling mip maps on your texture(s) as well as disable compression. This will at least make sure you aren't losing quality in those areas first so you can eliminate those factors. You can always turn those back on later as you get closer to what you want.
     
  18. Mårten

    Mårten

    Joined:
    May 16, 2011
    Posts:
    18
    I just stumbled upon this in SM1, and maybe it's just me not understanding how things work, but:
    It seems that if you use MoveToBack() and the like you won't be able to use the SortDrawingOrder() function. It will output an invalid cast error. This is because the MoveToBack() etc. functions seems to add integers in the spriteDrawOrder ArrayList of SpriteManager, which makes the SpriteDrawLayerComparer not work.

    Setting drawLayer on a Sprite works as it should however, so there is a way to avoid the problem.

    However, I've had situations using MoveToBack() and the like where the result just seems inconsistent and I'm guessing this is because of this.
     
    Last edited: Sep 1, 2011
  19. Xroft666

    Xroft666

    Joined:
    Dec 24, 2010
    Posts:
    24
    Hello everybody!
    I actually dont know if my issue is discussed already, I am sorry if it is.
    I wonder how to sort sprites per-frame (in SM1) while SortDrawingOrder() function costs much (like-a... 250 ms on iPad for ~100 sprites).
    I have big amount of static sprites, and moving sprites too. And I need to sort moving objects between theirselves and static sprites.

    Thanks for this audience :)
     
  20. goodhustle

    goodhustle

    Joined:
    Jun 4, 2009
    Posts:
    310
    Not sure if this has been addressed in the many pages prior to this, but it seems like there's a bug in the winding order calculations within SpriteManager.SortDrawingOrder. The order of mesh vertices within the CW part of the if statement doesn't follow the comment, and is identical to the CCW ordering. I changed this so it follows the comment, and confirmed that it does now flip the normals on the mesh. Brady, I know you've moved on to SM2, but would you like me to update the wiki with a fix for this?
     
  21. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Sure, if you're sure it's a bug in the original. Thanks!
     
  22. bumble864

    bumble864

    Joined:
    Jan 27, 2011
    Posts:
    128
    Just like the last few, sorry to post this if someone has already asked but I can't search a forum and go directly to a post with the keywords I'm looking for.

    Firstly, this is fantastic. I've been able to get in to this fantastic add-on and dissect it almost all the way down to understanding, which i AWESOME...

    Now for my question, How can I parent all the newly created sprites to a singular game object so I can move them all simultaneously?

    Thanks,russ
     
  23. spentak

    spentak

    Joined:
    Feb 11, 2010
    Posts:
    246
    I'm porting an iOS app onto Unity. In my app I have a scrollview that I dynamically add UIImageViews to. My images are named such as hats1,hats2,hats3 -- shirts1, shirts2,shirts3, etc etc.

    I am wondering on how I can accomplish this using Sprite Manager 2. I know I could create a prefab for every single image and then instantiate the prefabs, but that will take FOREVER (because I have many images). What I would rather do is have a single prefab where I pass in the name of the actual texture (hats1) and then sets the sprite width and height based upon the texture size, then rebuilds the atlas using the texture name I passed in (gets it from the assets folder), then I instantiate it.

    How can I do this? Is there anything I can do to make my life easier here than having to build 200 prefabs (one for each sprite)?
     
  24. GTHaxor

    GTHaxor

    Joined:
    Dec 12, 2011
    Posts:
    60
    EDIT: Looks like I forgot to change "Alloc Block Size" after I remade the SpriteManager GO. Solved!

    ORIGINAL:
    Here's what I have so far:

    Code (csharp):
    1.  
    2. public var SM:SpriteManager;
    3.  
    4. function Awake()
    5. {
    6.     var SMGO : GameObject = GameObject.Find("_SpriteManager");
    7.     SM = SMGO.GetComponent("SpriteManager");
    8. }
    9.  
    10. function AddSprites()
    11. {
    12.     var s:Sprite = SM.AddSprite(tInstance[11].gameObject, 32, 64, 0, 128, 64, 128, true);
    13. }
    14.  
    When I run my game, I receive the error:

    Code (csharp):
    1. ArgumentException: Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
    2. System.Array.CopyTo (System.Array array, Int32 index)
    3. SpriteManager.EnlargeArrays (Int32 count) (at Assets/Plugins/SpriteManager.cs:318)
    4. SpriteManager.Awake () (at Assets/Plugins/SpriteManager.cs:276)
    5.  
    The error points to the following line in SpriteManager.cs:
    Code (csharp):
    1.  
    2. tempSprites.CopyTo(sprites, 0);
    3.  
    Any ideas why this error pops up?
     
    Last edited: Dec 13, 2011
  25. GTHaxor

    GTHaxor

    Joined:
    Dec 12, 2011
    Posts:
    60
    Another issue. I have spawned a grid of tiles on screen, each using SM to display a sprite. There is one player controller which is spawned as well, again using SM to display its sprite. Whenever I move the player controller through keyboard inputs, the game object is moved but the sprite remains stationary. Why doesn't it move with the game object?

    I saw that the demo had soccer balls that moved and the sprites followed their game objects. What am I doing wrong?

    EDIT: Figured out the use of the function Transform() but being a curious person, I'm interested in the difference between my situation and the demo scene. Why do the soccer balls update automatically while my game object does not?
     
    Last edited: Dec 13, 2011
  26. dan2fuzzywu

    dan2fuzzywu

    Joined:
    Jun 16, 2010
    Posts:
    5
    Hi Brady,

    I just purchased EZGUI from the asset store yesterday, and I've run into a compiler error that's related to SpriteManager which I don't recall purchasing. I get the following error which is preventing me from being able to work on any other scenes:

    Assets/Plugins/Sprite Scripts/Support/ISpriteMesh.cs(19,29): error CS0106: The modifier `abstract' is not valid for this item

    What should I do?

    Regards,
    Daniel
     
  27. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    @dan2fuzzywu
    Did you perhaps import the simple demo package as well? If so, it should be noted that until the next update on the Asset Store, that particular demo package contained some obsolete scripts which will overwrite the newer ones when imported. If you only import the main EZ GUI package or any of the other demo packages, you shouldn't have any problems.
     
  28. dan2fuzzywu

    dan2fuzzywu

    Joined:
    Jun 16, 2010
    Posts:
    5
    I think the simple demo was part of the EZGUI asset purchase from the Unity asset store. When will the next update be available? My version from Unity asset store is 1.07 but I see on your website is 1.075.

    Otherwise, how do I remove the obsolete scripts?


     
  29. dan2fuzzywu

    dan2fuzzywu

    Joined:
    Jun 16, 2010
    Posts:
    5
    I deleted everything and reinstalled EZGUI. I imported the mushroom demo and everything appears to be working fine. I will avoid the simple demo. Thanks!

     
  30. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Yes, an update should be coming soon to the Asset Store.
     
  31. jjobby

    jjobby

    Joined:
    Nov 28, 2009
    Posts:
    160
    Does someone use SM1 in flash export? I've encountered the problem that SM1 doesn't play the animation in flash player. It works perfectly fine in editor but doesn't work in flash build version. I can still control and play the game. Do you have any suggestion or any idea what possibly be the problem? I really need help here. :-|

    I also have another question about SM1 (sorry, if it has already been asked before). If I have many sprite manager and each one has its own texture atlas, how can I control the draw order between each sprite manager? :confused:
     
  32. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    Regarding SM1 compatibility with flash export, I honestly can't say at the moment as I'm presently focused on SM2 and EZ GUI support for flash export.

    Regarding controlling draw order between managed sets, it is unfortunately not possible to interleave sprites from two different managed sets unless you're using a Z-testing shader. The reason is because each set is a single mesh, and Unity renders it in a single pass.

    If you're just wanting to control which entire set gets drawn in front, then you just need to make sure the center of the bounding volume which contains the managed set you wish to appear in front is nearer to the camera (assuming you're using blended shaders), since Unity renders the meshes back-to-front in order of distance from the camera.
     
  33. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi Brady

    I'm currently controlling a movement animation whenever the player presses a joystick left (backward) or right (forward in a side scroll).

    This is how I'm doing it:

    Code (csharp):
    1.  
    2.  
    3. if ( moveTouchPad.position.x > 0.7  moveTouchPad.position.x !=0){
    4.         movement = Vector3.right * forwardSpeed * moveTouchPad.position.x;
    5.         playerBase.UnpauseAnim();
    6.    
    7.     } else if (moveTouchPad.position.x < 0.7  moveTouchPad.position.x !=0) {
    8.         movement = Vector3.right * backwardSpeed * moveTouchPad.position.x;
    9.         //playerBase.PlayAnimInReverse("DriveFwd");
    10.         playerBase.UnpauseAnim();
    11.        
    12.     } else if (moveTouchPad.position.x == 0) {
    13.         playerBase.PauseAnim();
    14.     }
    15.  
    My question is, how do I get the animation to play backwards? As you can see above, I had an attempt using PlayAnimInReverse, but this did nothing, I guess because i have the anim in the pause state. I use pause so that the movement (stopping/starting) looks natural, rather than having the animation play from the beginning every time the player moves.

    Wondered if you could shed some light on this for me?

    Cheers!

    Edit: Forgot to mention that i have this at top of script:

    Code (csharp):
    1.  
    2. function Start()
    3. {
    4.     playerBase.DoAnim("DriveFwd");
    5.     playerBase.PauseAnim();
    6.  
    7. }
    8.  
     
  34. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi Brady
    I also have another, different question for SM2. I have a pre made sprite sheet (8 columns, 7 rows) that i'd like to animate. Can i do this with SM2 (I don't have the individual pngs that make up the sheet). Had a play using the Sprite.cs script and couldn't get that to work.

    Thanks again


    EDIT: Since posting I've resolved this issue, thanks. My inspector settings weren't correct for the atlas. Ta.
     
    Last edited: Jan 18, 2012
  35. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Maybe someone else is able to help with this issue (or reversing the animation that's in pause above)?? Thanks
     
  36. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    You'll find an answer to this on the thread you posted on the official forum over at forum.anbsoft.com. Thanks!
     
  37. Deleted User

    Deleted User

    Guest

    I'm using SM1, and having some trouble with colored sprites. I have a bunch of sprites for a tiled background, monsters, etc. After some time, it seems like random sprites get colored random colors. I think it might have something to do with multiple calls to SortDrawingOrder, and somehow the color array is getting out of sync with the verts it's supposed to be coloring.

    Anyone else ran into anything like this?
     
  38. Intrawebs

    Intrawebs

    Joined:
    Mar 24, 2011
    Posts:
    45
    Sorry if this has been asked, but how do I use the same atlas in multiple scenes. Whenever I rebuild the atlas it removes all the sprites that were on there from a different scene and replaces them with just the ones on the scene that was open when I built the atlas, even if if there is enough room for the new sprites.
     
  39. Suminsky

    Suminsky

    Joined:
    Aug 11, 2011
    Posts:
    50
    Did you find a solution? Im experiencing the exactly same problem..I just created a project with one animated sprite, just to test the spritemanager class working, and then created a flash build since is what we are required to target.
     
    Last edited: Mar 20, 2012
  40. Suminsky

    Suminsky

    Joined:
    Aug 11, 2011
    Posts:
    50
    So, I just tested with an old project I had in witch I do the UV animation myself, it also DOESNT work in the flash build, sorry to post on this topic witch isnt the main subject but I find it very appropriate(i think im going to open one in the scripts forum also)..:

    No uv animation on flash builds? My unity version is the 3.5.0f5, my flash version is the last(just updated it), I tested in both chrome and IE...
     
  41. CoCoNutti

    CoCoNutti

    Joined:
    Nov 30, 2009
    Posts:
    513
    Hi Brady

    I've come across an unusual (i.e. first time it's ever happened) problem that I don't know how to resolve.

    For months, and the last few weeks in particular, I've been rebuilding atlases on a daily basis (just to update the art, not add more sprites to the atlases).

    I've always had the atlases set to 2048x2048.

    Then out of nowhere tonight, I went to build and i'm now receiving warnings for ALL of my atlases that not everything can fit on every atlas and the sprites will be resized!!! I have no idea why or how this happened. Furthermore, one of the sprites is totally off on the atlas - it keeps displaying some other random area of the atlas instead.

    Hope you can help, this is really throwing everything out of whack.
    Thanks.

    *Edit NB: I'm still using Unity 3.4 because i don't want to have to deal with 3.5 bugs/issues atm -- just get the project done then do it!
     
    Last edited: Mar 28, 2012
  42. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,681
    I am wondering if there is a more exact science to setting the SpriteManager2 Lower Left Pixel Dimensions.
     
  43. Dipso

    Dipso

    Joined:
    Jun 29, 2012
    Posts:
    82
    Hi

    I used Sprite Manager 1 (specifically version 0.633) in an iOS game, Pure Fun Soccer.

    Attached are two scripts with the changes I made to the code: Sprite.cs and SpriteManager.cs

    The changes include:
    - Setting top and bottom vertex colours for a sprite.
    - Method to clean up a sprite manager. This is mainly used when creating and destroying sprite managers in a single scene.

    Do a search for my name "Diorgo" in the code to find the changes.

    Brady, thanks a lot for making Sprite Manager 1 available :)

    View attachment $spritemanager_diorgo.zip
     
  44. ejtech

    ejtech

    Joined:
    Jun 29, 2012
    Posts:
    1
    Sorry if this has been asked before. But just to clarify, can SpriteManager and its associated scripts be used for commercial games. In other words, could I use SpriteManager in a game I am going to sell.

    Additionally, great work.

    Thanks,

    Ejtech
     
  45. wolverine

    wolverine

    Joined:
    Jul 23, 2012
    Posts:
    1
    Hai,

    First of all, Thank you. You have done a wonderful job here, and it surely is helping me very much.

    But now I need your help.

    I have created a game and is using your SpriteManager to play the explosions in it.
    It was working fine until I made its second version, Including a zoom feature.

    Now I am using two cameras instead of one, and the explosions are not playing correctly. It is being called at the correct position (even when the game is zoomed) but is either delayed, or isn't playing at all.

    1. I'm using the LinkedSpriteManager.cs
    2. Auto Update Bounds is checked.

    I can't figure out what's wrong, and i dont know how it happens, or how to reproduce this. Sometimes, everything works perfectly, but some other time, these issues are seen.

    I could really use your help here.
    Please look into this.

    Regards,
    - A.
     
  46. Matz

    Matz

    Joined:
    Jul 3, 2012
    Posts:
    12
    Thanks
     
    Last edited: Aug 1, 2012
  47. gam3r

    gam3r

    Joined:
    Jan 21, 2013
    Posts:
    5
    Thank you very much for writing efficient wrappers to make sprite management easier. This will really save me a lot of time.
     
  48. Aberrations

    Aberrations

    Joined:
    Jan 31, 2013
    Posts:
    2
    Hey Brady, thanks for releasing this to the community it's really good stuff.

    Is there a GitHub repo for spritemanager 1? I've made a few additions and I know some other people that would be interested in adding to it as well.

    If not would you mind if I hosted it on a GitHub repo? Of course i would include the licence headers as well.
     
  49. par-002

    par-002

    Joined:
    Jul 4, 2012
    Posts:
    52
    Hey Abberations... did you ever get a reply for this question? I have some added code as well but would hate to duplicate stuff thats already been done.

    Thanks!

    PAR
     
  50. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,469
    There is not a GitHub repository for it at the moment. If you'd like to create one, that'd be cool.