Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - KronusGT

Pages: [1]
1
Support / [Solved] tk2dSprite.CreateFromTexture w/generated texture help.
« on: September 27, 2013, 11:36:59 pm »
I'm having trouble getting this to work properly. I'm new to Unity/2D Toolkit and moving my project over from FlatRedBall, where I did everything in code. In that, I had created a method which outputted a solid Texture2D to be used for a sprite. I created this so I could easily throw together overlays and fades of any color. Here is the method:

Code: [Select]
public Texture2D GetSolidTexture(Color C)
{
Texture2D _SolidTexture = new Texture2D(64, 64, TextureFormat.RGBA32, false, false);

Color[] _C = new Color[_SolidTexture.width * _SolidTexture.height];

for (int i = 0; i < _C.Length; i++)
{ _C[i] = C; }

_SolidTexture.SetPixels(_C);

return _SolidTexture;
}

I had it at 2x2 so it would take up as little space as possible, but I changed it to 64x64 so it would be visible for testing.

Here is me trying to create the sprite, a black overlay that I'll be fading out:

Code: [Select]
GameObject _BlackOverlay = tk2dSprite.CreateFromTexture(GetSolidTexture(new Color(0f, 0f, 0f, 1f)), tk2dSpriteCollectionSize.Explicit(576f, 64f), new Rect(0f, 0f, 64f, 64f), new Vector2(0f, 0f));
tk2dSprite _BlackOverlaySprite = _BlackOverlay.GetComponent<tk2dSprite>();
_BlackOverlaySprite.SortingOrder = 5;
_BlackOverlaySprite.scale.Set(32f, 18f, 1f);
_BlackOverlaySprite.transform.Translate(-1024f, 576f, 0f);

I'm not using tk2dCamera. The base size seems to be fine (still getting used to this ortho+height thing...), but scale.Set fails to change it. The texture color is also incorrect, instead of solid black it is transparent white. Can anyone figure out what I'm doing wrong?

Pages: [1]