Hello Guest

Author Topic: Help needed with cross platform spritecollections  (Read 6894 times)

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Help needed with cross platform spritecollections
« on: August 03, 2014, 10:26:55 am »
I'm struggling to get the cross platform (1x, 2x and 4x) spritecollections working.

I have included a project (https://bitbucket.org/mygamingproject/displaycheck or download at https://bitbucket.org/mygamingproject/displaycheck/get/54ea635e3900.zip) to hopefully show the issues I am having.

I'm targeting mobile and ios5.1 so I see my three derivatives being

1x = iphone 4 (960 x 640)
4x = iPad Air (2048 x 1536)
2x = everthing else

To demonstrate the issue i am having i have used some open game art by evo (http://opengameart.org/content/2d-adventure-sprite).

The alien in this art will be the height

1x = 90px
2x = 180px
4x = 360px

Meaning the alien should consume somewhere between 15 - 23% of the height of the screen assuming in landscape.

I have a singleton that sit within a scene called "setup" that sets an object then persists throughout my scene as well as determining the ratios. This seems to be called correctly.

The issue I think i am having is the correct setup of the camera to sprite. If I setup my sprite to accommodate the alien, I click on the 1:1 button to ensure its pixel perfect and the scale drops to 0.05. The only way is remedy this is to zoom the camera scale or alter the scale of the sprite but this then doesn't work correctly with the resolutions.

The camera is prettyy standard setup as well

Native and Preview Resolution at 960 x 640 (my lowest and 1x supported resolution)
Pixels per Meter set to 20
Origin set to 1

Overrides set to

Matchby: Wildcard
Auto Scale: Fit to Height
Fit Mode: Center

I don't understand if the alien is 360px and height is 1536px the scale at 1:1 can be 0.05.  Particularly when the camera and the imported assets have been imported at the same units.

Any help would be appreciated as currently I can't ignore this issue as the texturememory falls over on lesser devices if I just go with one.
« Last Edit: August 03, 2014, 10:34:11 am by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #1 on: August 03, 2014, 12:17:27 pm »
Hmm, looks like theres a bug with the sprite collection scaling - don't think anyones been using the 1:1 button since we introduced the tk2dCamera... This can be fixed in tk2dSpriteCollectionData -
         float spriteSize = (Collection.invOrthoSize * Collection.halfTargetHeight);
to -
         float spriteSize = (collection.inst.invOrthoSize * collection.inst.halfTargetHeight);

This should return 1 in all cases where the pixel per meter settings match, regardless of scale. You shouldn't need to use that button, the sprite should be pixel perfect at 960x640, and in 4x it will be a bit bigger because you've got fit visible selected in the override. If you select closest multiple of two, the sprite should be pixel perfect without you doing anything to the sprite.

You really wanna avoid changing the sprite size as that will imply changing your code and making all the visual setup rather useless.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #2 on: August 03, 2014, 12:31:36 pm »
Oh ok that makes sense as really couldnt see what I was doing wrong.

I had Fit to height so if you say I do Closest multiple of two that would work better.

I've changed the code in tk2dBaseSprite not tk2dSpriteCollectionData as it wasn't present in that.

The only bit I'm not quite sure of from your response is what you mean by:

Quote
You really wanna avoid changing the sprite size as that will imply changing your code and making all the visual setup rather useless.

Is this in context to the multiple sizes of the sprite across 1x to 4x?  As if so this is essential to having the smaller spritesheets and therefore manageable texturememory.
« Last Edit: August 03, 2014, 12:39:26 pm by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #3 on: August 03, 2014, 05:53:27 pm »
Yes that is in context to the 1x - 4x platform collections. But the key thing with them is the physical size doesn't change, it remains constant. The amount of detail is what changes. That means you dont have to reposition everything when you change resolutions. That coupled with the tk2dCamera scaling options will let you run the same game on different displays, displayigng the suitable amount of detail on each display.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #4 on: August 03, 2014, 06:11:39 pm »
So how do you prepare the image file(s) to be smaller and subsequent spritecollection to ensure the overall texture size is reduced for older devices? I thought this was done through scaling the asset?!?

If I have understood you then the concept is a little foreign to me as I have come from an environment of Texturepacker (codeandweb) where the size and scale of the spritesheet is what alters not the detail thereby reducing the dimension of the spritesheet to go in to memory.
   
« Last Edit: August 03, 2014, 06:13:53 pm by mygamingproject »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #5 on: August 03, 2014, 06:15:56 pm »
You dont do anything, as long as your platform collections are there - and you set the appropriate version of the asset to you as you were already doing in that sample, it should just work. You can see what happens when switching platforms by doing so in 2D Toolkit > Preferences, you should be able to see the quality increase and decrease.

Get this working with the camera first, behaving like you want it to. This feature is completely separate, and all it does is increase quality. The atlas size changes, but the physical sprite size remains constant.

mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #6 on: August 03, 2014, 06:35:54 pm »
You can tell its a Sunday as I'm really not getting this.

The setting and switching of the assets I get now from the sample i provided.

The bit I'm not though is atlas size changes but the physical size of the sprite remains constant. One principal must be that you don't exceed 2048x2048 otherwise exceeding this with retina sizes means you can't switch easily.

Also you say "as long as your platform collections are there" but is it not the case if you are working to 2048x2048 then you don't need platform specific collections and the constants are dealt with the camera as stated. Otherwise reduction of atlas size can only be achieve through scaling.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #7 on: August 04, 2014, 11:59:49 am »
Imagine the same sprite being displayed in 2 displays
1024x768 - the sprite fills the screen and is 1024x768 in size.
2048x1536 - with the same sprite as above and fit visible in the tk2dCamera, the same sprite will fill the screen. It only has 1024x768 pixels worth of data, so is upscaled.
2048x1536 - with a 2x sprite collection, the source sprite is now 2048x1536. It is the same physical size as the 1024x768 sprite, so the result is now pixel perfect.

And just to illustrate the final combination, which you wouldn't use -
1024x768 - with a 2x sprite collection, the 2048x1536 sprite fills the screen, as its the same size as the 1024x768 sprite.

Make sense?


mygamingproject

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #8 on: August 04, 2014, 12:56:31 pm »
I see.

My mindset is working the other way. I want to think about the most powerful device and resolution and downscale but this is where the issue reside as your default position is a larger size that older devices can't accommodate.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Help needed with cross platform spritecollections
« Reply #9 on: August 04, 2014, 01:32:25 pm »
Same thing applies the other way. If you start with 2048x1536 sprites, then develop with that, set the platform to 4x, and work your way down from there. The lower resolution sprites will be the same physical size as the large one - the only thing that needs to be right is the ratio between the platform collection sizes.