Hello Guest

Author Topic: The fifth way of looking up platform assets ;-)  (Read 3206 times)

habitoti

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
    • Rombos Homepage
The fifth way of looking up platform assets ;-)
« on: March 04, 2014, 07:52:11 am »
Hi,

I would like to suggest a fifth way of looking up graphics assets for platform support. I am actually using it, so maybe it's useful for others (and if you take it into standard coding, I wouldn't have to carry it over on each update ;-).

I have hundreds of assets organized in atlasses. I don't like to put them flat into a single folder, so I have quite a big and deep subfolder structure. For platform support, I don't want to clutter that with additional lowres files, but rather have other folders with the complete same hierarchy next the to it, carrying the lower resolutions still organized in the same deep hierarchy. So my structure for the native platform looks something like this:

Code: [Select]
Assets/Graphics/4x/fld1/fld2/asset1.png
Assets/Graphics/4x/fld1/fld2/asset2.png
Assets/Graphics/4x/fld3/asset4.png
...
   

For 2x I simply use PhotoResizer from Mac Appstore that can generate hundreds of arbitrarily scaled versions in seconds, retaining the complete hierarchy. So I create this for scaled down assets:

Code: [Select]
Assets/Graphics/2x/fld1/fld2/asset1.png
Assets/Graphics/2x/fld1/fld2/asset2.png
Assets/Graphics/2x/fld3/asset4.png
...
   

Then my fifth way of looking up simply selects the proper full hierarchy for the given platform (and it will not harm any previously existing lookup principles, since they would be found first for proper setups):

Code: [Select]
// Fifth path: assume that source graphics are in a structure that has a root of /nx/ (n: 1,2,4)
// this will be replaced by desired platform. This way you can structure all artwork in arbitrary
// folder structures below that root
if (platformTexture.Length == 0) {
// locate current platform
string altDirectory = directory.Replace("/4x/", "/" + platformName + "/");
altDirectory = altDirectory.Replace("/2x/", "/" + platformName + "/");
altDirectory = altDirectory.Replace("/1x/", "/" + platformName + "/");
if (System.IO.Directory.Exists(altDirectory)) {
platformTexture = FindFileInPath(altDirectory, filename, ext, extensions);
}
}

So if you think this would be useful for others, just pick that piece of code and add it to the existing 4 ways of looking up platform assets. It works in either "direction", no matter what your source platform is.

Regards, habitoti
Checkout our homepage or visit the Rombos blog.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: The fifth way of looking up platform assets ;-)
« Reply #1 on: March 04, 2014, 11:50:54 am »
I am considering adding more "hooks" into the system, eg. being able to register your own platform sprite finder. Not sure if its a good idea to keep adding more options to that...