Hello Guest

Author Topic: Check atlas space to add sprite?  (Read 4165 times)

jk9211

  • Newbie
  • *
  • Posts: 4
    • View Profile
Check atlas space to add sprite?
« on: March 25, 2016, 06:52:30 am »
Is there any way to check whether there is space in atlas to add a texture?

I'm trying to push textures and build sprite collections by script and I would like to split collections if it gets too big for my liking as I'm making a 2D game and there will be a lot of textures.
Last time i checked, all of multiple atlas in a collection are loaded into memory and that is not what anyone wants.

Is there a way to know this before trying to add to a collection? Thanks in advance  ;D

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Check atlas space to add sprite?
« Reply #1 on: March 27, 2016, 02:55:06 pm »
No there isn't, but you have the code if you want to poke around. You can run the atlasing to see if it'll fit before actually running the rebuild. I can point out what to look at if you want to try implementing this.

jk9211

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Check atlas space to add sprite?
« Reply #2 on: March 28, 2016, 01:30:59 am »
Can you point me in the right direction?
I'm kind of stuck. Thanks XD

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Check atlas space to add sprite?
« Reply #3 on: April 05, 2016, 12:42:34 am »
The easiest way to figure this out is to step through the code.
In tk2dSpriteCollectionBuilder.cs, look for this line
Code: [Select]
tk2dEditor.Atlas.Builder atlasBuilder = new tk2dEditor.Atlas.Builder(atlasWidth, atlasHeight, gen.allowMultipleAtlases?64:1, allowFindingOptimalSize, forceSquareAtlas, allowRotation);
tk2d does a whole load of things to the sprites before putting them in the atlas, but all you'll need to care about is getting the padding correct for your sprite. .Build() will return != 0 if failed.