Author Topic: Best practice for very large grid of tiled sprites  (Read 5223 times)

FWCorey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Best practice for very large grid of tiled sprites
« on: January 31, 2013, 07:58:17 AM »
What would be the best method to use (on mobile) to instantiate an array of 1024 x 256 sprites using NGUI?
I find after anything bigger than a chunk of 24x24 tiles of 2 triangle panels. I have to wait for 2 vsyncs to let the draw calls batch or it falls behind and the scene freezes after it's finished loading so it can catch up. Sometimes as long as a minute or more. :o I'm hoping there is a faster way to do this with NGUI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best practice for very large grid of tiled sprites
« Reply #1 on: February 01, 2013, 01:09:23 AM »
Wait what? You're instantiating 24*24=576 tiles, 1024x256*4=1 Mb each? That's 576 megabytes of memory right there.

FWCorey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Best practice for very large grid of tiled sprites
« Reply #2 on: February 02, 2013, 03:07:29 PM »
Nope. There are 1024 x 256 sprites. Each of which is a 16x16 texture. I've got it to do that in the editor in 3 seconds if the hierarchy window is closed (It was causing the massive delay). To speed things up I was thinking of doing a quadtree and dynamically displaying the sprites as the scene scrolled but if NGUI is fast enough I'd rather just spawn at load and leave them there.
Oh and there are less than 200 (16pixel x 16pixel) textures in the atlas. Currently it's batching down to about 25 drawcalls (Since it never has all of the different sprite types onscreen at once). It's running at about 40 fps on a Galaxy Tab 10.1 for example, and I'd like to speed it up.
« Last Edit: February 02, 2013, 03:16:08 PM by FWCorey »

redhawk

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Best practice for very large grid of tiled sprites
« Reply #3 on: February 02, 2013, 05:41:30 PM »
Why not just set up some mesh colliders with the mesh render off (so you can't see it) and then do some sort of on-click-raycast type event that then opens up your NGUI?  I'm guessing you are trying to do a tower defense type set up.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best practice for very large grid of tiled sprites
« Reply #4 on: February 02, 2013, 06:03:51 PM »
Best way to speed it up is to use Premultiply Alpha shaders I added to NGUI in 2.3.0, and to use Unity 4.1 as it has some new features NGUI takes advantage of. Everything else will likely be minor.

FWCorey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Best practice for very large grid of tiled sprites
« Reply #5 on: February 02, 2013, 06:44:15 PM »
Actually redhawk it's a 2.5d destruction game. The sprites aren't meant to be clickable and have box colliders on them for physics. I shudder to think what that many mesh colliders would do to framerate.  :o
Tried changing the shaders and it had zero effect Aren. Thanks for the suggestion though.
I guess I'll have to do the quadtree system after all and make it a sparse one, only updating data to changed elements.
Should be able to reduce drawcalls to below 10 but I was hoping NGUI would save some time in Blender.