Hello Guest

Author Topic: tk2dCamera and background sprite szie problem  (Read 6317 times)

ProjectOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
tk2dCamera and background sprite szie problem
« on: December 15, 2012, 05:10:55 pm »
  :-[
Hi,
This is my first attempt at 2DToolkit but I did go through the brief documentation... so I decided to use the tk2dCamera with the goal of simplifying deployment to different iOS screen resolutions.

This is what I did/got so far, I must be doing something wrong.

1) Imported 2DToolkit on a brand new project
2) Deleted demo folder as I forgot to untick it before importing
3) Created a tk2dCamera with the following settings
- In the tk2dCamera Inspector
--- Camera panel: I didn't change default settings which have Orthographic and Size 480 (unless it changed to 480 after I set the Resolution override
--- tc 2d Camera (Script) section of the same panel:
------------- Resoluiton overrides is TICKED 
------------- Native Resolution I set to : Width 960 and Height 640 (I want to work a 2x iPhone 5 resolution with my main background sprite being 960x640
------------- Overrides set to: Widlcard Override, Width-1 and Height-1   Also: AutoScale:Fit Visible and FitMode:Center. This is because what I understtod from the documentation is  that using these Widlcard Override settings tk2dToolkit will automatically try to fit the 960x480 screen size on to other screen resolutions

Camera Resolution seciton of same panel:
--- Force Editor Resolution is TICKED
--- Preset iPhone 5 which gives of course a 1136x640 wide setting (then I went to the Unity GAME window and iPhone 5 Wide (16:9) 1136x640 (this should match the settings and show things properly)

Then I created a new Sprite Collection and added just one image which is my background image for the game. In the Sprite Collection Settings I have
- Use tk2dCamera TICKED (DO I NEED TO SET ADD PLATFORM SUPPORT AT THIS STAGE?)

I created a Sprite in the Hierarchy which defaulted to my only sprite collection and background sprite
- Position and Scale both set to 0,0,0 by default
- Scale to 1,1,1 by default

PROBLEM:
in the Scene view whcn I select the tk2dCamera I can see my backround image centered in the Scene screen and it also appear centered in the CAMER PREVIEW although here the background image does not cover the whole Camera Preview, there is plenty of empty blu camera border. Problem, the tk2dCamera Preview only shows my Background Image in the left bottom quarter of the screen... Same in the actual Game window

Of course I have done something wrong int he settings

The BackgroundSpriteCollection prefab created by the Sprite Collection (same folder with atlas0, atlas0 material) shows these settings among others
- Sprite Definitions -> Size 1
- Textures.... -> Inv Ortho Size 1
- Textures.... -> Half Target Height 320

What was I supposed to do differently so that I can use  960x480 background and overall game scene size with all scene elements to show correctly centered in the game screen?

Sorry for the long post, but I guess without mentioning the settings above you won't be able to see what I ddi wrong :)

Thanks!



« Last Edit: December 15, 2012, 06:10:27 pm by ProjectOne »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera and background sprite szie problem
« Reply #1 on: December 16, 2012, 12:02:34 am »
You've got quite far with this.

1. Do you need to add platform support at this stage? No, that and resolution scaling is independent to each other.

2. The tk2dCamera origin is from the bottom left. Due to a bug in the Unity camera class, the built in camera preview shows it incorrectly which is why there is a second tk2dCamera preview. Also the built in camera class doesn't know (or indeed care) about resolutions as they don't matter in 3D - they obviously do in 2D. The game window & tk2dCamera preview are always correct.

To get your sprite centered and working properly...

1. Firstly, I think your sprite size may be incorrect (iPhone4 res is 960x640, not 960x480). Or perhaps that is a typo in your post.

2. What you want to do first is set up the scene so it looks correct on 960x640. Set Force Editor Resolution to this value and make sure your scene looks correct. Position the sprites whatever way you want to. Use anchors, or simply move to position correctly. Don't forget if you use the BottomLeft anchor, it will anchor to the BottomLeft at any resolution, so the only appropriate one here is MiddleCenter.

3. Now that it looks correct at that resolution, all you need to do is add a default override, and then change your resolution to 1136x640 (in force editor resolution, and the game viewport resolution). The scene should appear centered.

That should be it. Let me know if you run into any further problems.

ProjectOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dCamera and background sprite szie problem
« Reply #2 on: December 16, 2012, 10:51:51 am »
ok thanks will try again following your instructions
Thanks!

ProjectOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dCamera and background sprite szie problem
« Reply #3 on: December 16, 2012, 12:30:27 pm »
OK, got it to centre eventually, thanks.

Is this normal?:
I added a player sprite, rough test transparent png, just a test sprite that is not animated, size is 220x152.
Created the Sprite Collection, added this test sprite, commit... then added Sprite to Hierarchy..

It shows up but invisible to camera because is super tiny.
I have the same background in photoshop and in photoshop this test sprite is proportioned to the background. To have the same proportion of the sprite in-game I have to scale the sprite by 200 on X and Y.

Is the need of scaling up expected due to pixel perfect tk2dCamera.... or you think it should have been fine and I may be doing something wrong?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera and background sprite szie problem
« Reply #4 on: December 16, 2012, 02:52:02 pm »
That's just because Use tk2dCamera isn't ticked on the sprite collection.

You can use the whole system in 2 modes, with or without the tk2dCamera. With the tk2dCamera, 1 pixel = 1 world unit, so it is really large.

The default doesn't use it, it uses the normal ortho camera mode with a fixed ortho size, the sprites created using this mode will be really small when seen in a tk2dCamera. Clicking on "1:1" should fix it.

If you're intending on using with a tk2dCamera, I suggest simply ticking the UseTk2dCamera tickbox to keep things simple.

ProjectOne

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: tk2dCamera and background sprite szie problem
« Reply #5 on: December 16, 2012, 07:02:37 pm »
oh! Silly me... did tick the Use tk2dCamera for the background but forgot to tick it for the other sprite.
Ops!
Thanks