2D Toolkit Forum
2D Toolkit => Support => Topic started by: Intrawebs on January 10, 2013, 12:32:54 am
-
I'm using your TK 2d Camera, I also have two sprite collections that both have a 2x as their current platform and a 4x as an additional platform. The atlas's all get created just fine. For the camera I have it setup pretty much like you did and I work at the 640 width x 960 height with my 2x sprites all designed/anchored/positioned just great at that resolution in the editor. My 4x sprites are all double the size of the 2x sprites and are designed to be full retina on ipad4 (2048 height x 1156).
I then fire up my iPad 2 (1024 height x 768 width). In the scene before my gameplay I do the following
tk2dSystem.CurrentPlatform = "4x"
The gameplay screen has everything automagically positioned, scaled etc on ipad2. It looks as if my 4x atlas is used and scaled down 50% (what I want).
What I dont under stand is the camera overrides. Are they needed and when would I use them? Am I doing anything wrong?
Also, do you have any links in these forums about how people tackled android ratios/resolutions while also using the TK2dCamera? I purchased multiplatform toolkit asset but so far I haven't needed it.
-
Camera overrides let you rescale the screen for different resolutions and aspect ratios. If you set up a wildcard override, and with the default values, it will scale whatever output you have to fit the screen. Eg. 1024x768 -> 960x640. There are options on how you want to scale, so you can tell it to try to fit width, height and so on.
You aren't doing anything wrong. Have you tried your app on iPhone or other android devices? You'll probably find it already does a lot of what you need - when it doesn't, you'll just need to tweak the overrides to suit.
-
Thanks for helping with my sanity check! Haven't tried the phone yet, need to grab some old ipods around the house and try them (4th and 2nd gens), looks great when forcing the editor to those lower resolutions.
What has been your experience or others when needing to futz with overrides? As in when do you commonly need to if at all?
-
I just turn on the default override. That pretty much covers most needs.
-
I'm developing for a resolution of 1920x1080, I'm a bit confused at how to set up the tk2d camera.
In the Camera options I've set the size beneath orthographic to 1920, is this right?
Other settings include native res: 1920x1080, overide of 1920x1080 stretch to fit,
Camera resolution: force editor resolution, 1920x1080.
Also should I scale the artwork for levels at the 1920x2080 resolution or go lower? The sprite collection seems to have trouble creating the larger textures. Do I need to pre-slice them in photoshop once I get them from the artist?
-
In camera options - orthographic size doesn't matter.
The tk2dCamera setup you have is correct.
Make sure you have Use tk2dCamera ticked on your sprite collections and you should get pixel perfect at 1920x1080.
For easiest workflow, you should develop the game at the lowest resolution you intend to support, and then use platform specific collections for higher resolutions.
What do you intend on slicing? Have you tried the dicing feature?
-
Cool thanks.
I guess the lowest would possibly be 720p but I'm thinking a lot of artwork would have to be rescaled / remade for other devices so I was going to start with a higher quality experience for 1080p.
Yeah I tried the auto-slicing in the collection editor and it works ok (besides a few small parts it seems to crop by themselves). I guess in my mind I imagined being able to scale a 1920x1080 sized painted graphic and import it as a high resolution background. It just seems I can't import graphics at these high resolutions with the sprite manager?
I'll take another look tomorrow. Thank you for answering my questions. :)
-
If your source images are really large, you'll probably run into atlas limits (4096x4096) very quickly. If these are solely for backgrounds, you could just import them as normal 2D UI textures, and use tk2dSprite.CreateFromTexture. As long as you use the same parameters for these as you do your other sprites, they will appear at the correct size.
As with most options, its probably worth spending a short while experimenting to see what works best for you.
-
Thanks unikron, I'll try that tomorrow. :)
But yeah, I'm thinking for performance issues it's probably better to splice the graphics up before importing them. I'll have to experiment further. Thank you so much for your prompt responses!
-
I develop at 640x960 (so I can see what Im doing) per my original post I still use the same assets. The problem I have is when I switch to 320x480. I have an override on the camera set to scale of .5 just like in your demo #11. I do this so that my 2x atlas can be used for both 640 and 320 widths (if there is a better approach to this let me know). The problem is, the anchors dont adjust their position automatically because of the scaling override I think, they do adjust when there is no override scaling.
The graphics do scale and look just fine and in the place they are suppose to be, but Im using some anchors as reference points to do some tweening of objects. What do you advise for the most seamless workflow. I know you say develop at the lowest resolution I intend to support but I think I would still have this problem in situations where I need to scale up.
A simple alternative is to do screenWidth/2 and screenHeight/2 to get middle center vs. using anchors as reference positions.
-
Is it the camera anchors which aren't updating properly? I'm not 100% clear on what you mean. If you can post screenshots that would be most excellent. Or email them to support@unikronsoftware.com if you prefer.
-
Its the camera anchor transform position. I set one up as middle center while at 640x960. When I run the game and change the resolution to 320x480 the anchor (and all others) stay in the same place. The anchors move to their respective positions at different resolutions when there is no override for that resolution.
-
Yes that is expected. When you add an override, it rescale the camera, so the actual resolution in your game remains the same. Your game still thinks its drawing into the native resolution, however you have set that up.
-
How do you advise I solve this problem then. I need to get the center of the screen with scaling so that I can position objects in their same position but exactly 1 screen to the left or right of the visible screen.
I tried...
var centerScreen = tk2dCamera.inst.ScaledResolution / 2;
Center = new Vector3(centerScreen.x, centerScreen.y, 0);
//this is one virtual screen space to the left...not visible
var xPos = Center.x - (centerScreen.x * 2);
screenLeftPos = new Vector3(xPos, Center.y, Center.z);
//this is one virtual screen space to the right...not visible
xPos = Center.x + (centerScreen.x * 2);
screenRightPos = new Vector3(xPos, Center.y, Center.z);
But, the ScaledResolution =400x400 for some reason when an override is set to scale at .5 (with a resolution of 320x480) from the native resolution on the camera of 640 width and 960 height, so I dont understand how it got 400x400.
http://imgur.com/ImjFhlf (http://imgur.com/ImjFhlf)
-
tk2dCameraAnchor uses tk2dCamera.ScreenExtents. Check how it positions the anchor in there. You can use the same code to position something at any of the corners, also one "full" screen away too - rect.xMax - rect.xMin = the width of the visible extents.
-
Your suggestion still doesnt help when scaling.
Im confused as hell now and have spent a lot of time on this. I want to get this right before I go any further on my project. I think it would be great if you had a demo scene that handles the following.
My goal is to have containers centered top, centered bottom and centered middle. The game is played in portrait. My sprite collections will have 2x and 4x sources....or 1,2 and 4x if it makes sense. I want everything to auto scale per resolution and want to design at 640x960. I have a background tiled sprite that is massive, so letter boxing on the sides is not an issue as this tiled sprite is shown. My 4x sources are all 2 times the size as the 2x source...per your doc this will have the best results.
How should i setup the camera when doing this, I do not want to put in explicit width and height overrides for every possible size as this will be on Android.
-
To set up the camera for this scene, set up the tk2dCamera as follows:
1. Native resolution = 640, 960
2. Overrides, delete everything, and click "Add override" to add a wildcard override. Leave this as it is. Don't add any more overrides.
Your game will now scale to fit the screen, the tiled background will reveal more as the aspect changes.
If you want your game to be "pixel perfect", and only ever scale by whole numbers, then switch AutoScale to "Pixel Perfect Fit".
Note, I haven't mentioned anything about 1x, 2x or 4x collections - it really doesn't matter. They are totally independent to the camera. All sprites from platform specific sprite collections should be the same physical size, so for almost everything, you can ignore that feature even exists.
Your question before wasn't related to this at all, or have I misunderstood it? Didn't you want to move something completely offscreen?
-
As I was typing the below you posted, so I will reply to your post. Correct, my issue was needing to move some stuff around, but the root problem was actually my latest question which was related to my original post of not grasping all this. Once I get this root issue fixed then moving stuff around should work fine per what you already suggested on that. Per your recent post, that seems to work great. But, I dont see the option for "Pixel Perfect Fit" in the camera override, I just downloaded the current version from the asset store as well to double check it wasn't a version issue. I do see a "stretch to fit".
Below is what I was going to do before you posted your response. Looks like I dont need to set scale and do what you suggested and then separately pick which asset 2x vs. 4x to load on my own, not a problem. Thanks for all your help on this!
******************************
I think I now know how to approach this. I will at game load time, the same time I set 4x vs. 2x also create and have only 1 resolution override.
This override will be...
width = screen.width
height = screen.height
auto scale = none
scale = screen.height / NativeRes.height (see psuedo code below)
fit mode = center
While testing the above logic by manually setting these on the camera this works, everything gets positioned properly. What I'll be doing is essentially creating 1 wildcard at runtime that is actually meant for the active resolution. Of course I need to also make sure that when Im setting the scale to also set a matching 4x vs. 2x, which would have impact on the scale.
Some pseudo/hack code here on handling the decision making for 4x vs. 2x and its impact on scale to make sure the best possible scale and source is rendered.
scale = 1
tk2dSystem.CurrentPlatform = "2x"
tempScale = screen.height / 2k2dCamera.NativeRes.height
if tempScale >= 1.5
tk2dSystem.CurrentPlatform = "4x"
tempScale = screen.height / (2k2dCamera.NativeRes.height * 2)
scale = tempScale ///// here we are scaling down the 4x vs. scaling up the 2x.....need to play with the results to see what looks optimal and when (scale up/down 4x/2x)
else if templScale > 1 AND tempscale < 1.5
scale = tempScale /////scale up the 2x...but no more than 1.5 times its original
else if tempScale < 1
scale = tempScale ////scale down the 2x
//I could then also check if the scale < .5 and show a 1x vs. the native what I used to design of 2x...I doubt I will ever have a height of < 480
-
Pixel perfect fit is from 1.90 - apologies, I've got that mixed up. It is probably safe to upgrade if you want. Barring any major issues, this current version will go out as is.
-
Thanks, this all works great now. Pixel Perfect Fit works as well. :) You may want to sticky the part about getting multiresolution support with the override you suggested.
-
One more question on this, should I still be doing anchor middle center on my sprites in my sprite collection (2x, 4x) with the new override setup you suggested? Or do you think I should anchor my sprites differently?
-
No real rule there, whatever works for you will be fine.