Hello Guest

Author Topic: Problem with platform specific sprites and scale  (Read 7322 times)

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Problem with platform specific sprites and scale
« on: November 06, 2012, 07:03:13 pm »
I just installed the latest version of 2D Toolkit (1.80 + patch 1) and started making my scene. The game will have three sets of spritesheets: 1x, 2x and 4x. I setup the 1x spritesheet and made sure that 2x and 4x sprites were in place. After pressing commit all three atlases were created so everything should be ok.

When I create a sprite (say 100x100 in position 0,0), it's correctly positioned in 1x resolution (which is 320x480). But when I increase the Game view size to 640x960, the sprite is not changed or scaled. The gameobject should be scaled to 200x200 and the sprite should be changed to 2x version, right?

I have the "tk2dSystem.CurrentPlatform = "2x";" if else statement in Start function and it correctly prints SD, HD and UD depending on the screen width and height.

Any advices? Does the camera need to be changed?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #1 on: November 06, 2012, 07:10:12 pm »
Yes, the idea is the sprites stay exactly the same size so you don't have to reposition anything.
The camera change is only in one place as opposed to all instances of everything.

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #2 on: November 06, 2012, 08:10:35 pm »
Yes, the idea is the sprites stay exactly the same size so you don't have to reposition anything.
The camera change is only in one place as opposed to all instances of everything.

Ok, so what do I need to change in the camera settings then?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #3 on: November 06, 2012, 09:53:12 pm »
Do you use tk2dCamera or just a plain ortho camera?

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #4 on: November 07, 2012, 06:47:30 am »
Do you use tk2dCamera or just a plain ortho camera?

I'm using tk2dCamera. Should I use the camera resolutions overrides for this one?

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #5 on: November 07, 2012, 07:15:48 am »
Now that I'm looking at the sprites, shouldn't the sprite atlas material change after calling "tk2dSystem.CurrentPlatform = "2x"; ?
I mean, I have everything setup with 1x. When I hit "Play", shouldn't the atlas change to the 2x automatically?
Now it's not changing.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #6 on: November 07, 2012, 08:20:27 am »
It only changes when reloaded, ie if you load a scene after setting current platform. Not in current scene. In editor, use the preferences page to switch. In game set this before starting the first scene.

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #7 on: November 07, 2012, 08:55:15 am »
It only changes when reloaded, ie if you load a scene after setting current platform. Not in current scene. In editor, use the preferences page to switch. In game set this before starting the first scene.

For some reason it doesn't work even if I set the variable in previous scene.
I have two scenes: "Menu" and "1player".

In "Menu" scene if do this after hitting "Play" button:

Code: [Select]
tk2dSystem.CurrentPlatform = "4x";
Debug.Log("tk2dSystem.CurrentPlatform: " + tk2dSystem.CurrentPlatform);
Application.LoadLevel("1player");

Then in "1player" scene I do this:

Code: [Select]
void Awake(){
Debug.Log("platform AWAKE: " + tk2dSystem.CurrentPlatform);
}

void Start(){
Debug.Log("platform START: " + tk2dSystem.CurrentPlatform);
}

EVERY debug says "1x", even the first one right after I have set it up to 4x.

JyriKilpelainen

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #8 on: November 07, 2012, 09:22:27 am »
Aha! If I replace the first code with this:

Code: [Select]
Debug.Log("tk2dSystem.CurrentPlatform: " + tk2dSystem.CurrentPlatform);
tk2dSystem.CurrentPlatform = "4x";
Debug.Log("tk2dSystem.CurrentPlatform: " + tk2dSystem.CurrentPlatform);
Application.LoadLevel("1player");

it works! So I need to ask first the CurrentPlatform variable's value and then override it. I can't just go and say tk2dSystem.CurrentPlatform = "2x"; straight away without getting the variable's value first.
Is this some kind of bug?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #9 on: November 08, 2012, 10:06:17 am »
Maybe. I'll look into it.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Problem with platform specific sprites and scale
« Reply #10 on: November 08, 2012, 04:19:53 pm »
I think I know what the issue was here. Fixed for the next release.