2D Toolkit Forum
2D Toolkit => Support => Topic started by: asea19 on February 14, 2013, 08:50:22 pm
-
Hi, do GetBounds() and GetUntrimmedBounds() return the width and height of a sprite before or after the camera scales things? Or neither? I am using the tk2d camera and I have native resolution set to 1136x640 with a resolution override with wdith and height set to -1, Auto Scale set to Fit Visible and Fit Mode set to Center.
After inspecting the output of these functions on a sprite that is 352 x 107 pixels. here is what is returned: 'Center: (624.8, 189.9, 0.0), Extents: (624.8, 189.9, 0.0)' . I am a bit confused! I see the proportion is about 1.75 of the actual sprite's dimensions. Is there any significance to this number? I just need to get the pixel dimensions of the sprite after scaling has occurred so I can position them relatively within the viewport. Any suggestions? Thanks!
-
With the tk2dCamera, there is no camera scale applied - it is the camera that is tweaked to get stuff to fit / moved around and so on.
Can you please check that the scale on your sprite (scale in the sprite inspector) is 1? sprite.GetBounds will scale by the applied scale.
-
With the tk2dCamera, there is no camera scale applied - it is the camera that is tweaked to get stuff to fit / moved around and so on.
Interesting. When I add a resolution override on the tk2d Camera inspector, it looks like it is scaling all of the sprites. That is why I assumed this. Still a bit confused as to what you mean.
So, regarding the scale in the sprite inspector. You are right. It is not 1,1,1. It is actually .15. I assume this has to do with how I am loading the sprites. I am loading them at runtime and used this thread as a guide on how to do that: http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1058.msg5282.html#msg5282 (http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1058.msg5282.html#msg5282)
Could you glance at this and see what I might be doing wrong? Thanks again.
var gameObj:GameObject;
var tk_spr:tk2dSprite;
var tempTexture:Texture2D;
tempTexture = Resources.Load( "Textures/MENUS/"+spr_str, Texture2D );
var tSize:Rect = new Rect(0, 0, tempTexture.width, tempTexture.height);
var tAnch:Vector2 = new Vector2(0, tempTexture.height);
gameObj = tk2dSprite.CreateFromTexture( tempTexture, tk2dRuntime.SpriteCollectionSize.Explicit( tempTexture.width, tempTexture.height ), tSize, tAnch );
gameObj.name = spr_str.ToString();
gameObj.layer = LayerMask.NameToLayer("MENU");
tk_spr = gameObj.GetComponent(tk2dSprite);
tk_spr.collection.transform.parent = gameObj.transform;
tk_spr.pixelPerfect = true;
BTW, I printed out tempTexture.width and tempTexture.height and they are the accurate pixel dimensions of the incoming texture.
-
it should be tk2dRuntime.SpriteCollectionSize.ForTk2dCamera()
That will create it with the correct size for later.
You don't need to set pixel perfect.
-
Thanks! That fixed it.