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.


Messages - Benny

Pages: [1]
1
Support / Bug? Multiple materials for sprite collection is not working.
« on: November 21, 2013, 01:41:19 pm »
After I updated to 2.6.0, multiple materials for a single sprite collection is not working. When hitting 'commit' to generate sprites data, all material indices of sprites will be reset to 0.

So I traced down to source code of tk2d, and found something weird.

File: tk2dSpriteCollectionBuilder.cs
Line: 1910

Code: [Select]
// make sure its not overrun, can happen when refs are cleared
thisTexParam.materialId = Mathf.Min( thisTexParam.materialId, gen.atlasMaterials.Length - 1);
coll.spriteDefinitions[i].material = gen.altMaterials[thisTexParam.materialId];
coll.spriteDefinitions[i].materialId = thisTexParam.materialId;

First line uses altlasMaterial to clamp material id, I suppose this is what is causing the bug. I changed it to altMaterials, and it seems back to work.

Am I correct?

2
That's really a quick reply, cheers!  ;)

3
I need to build a static sprite batcher from code. This was working before 2.0.

The new sprite batcher in 2.0 supports more kinds of sprites using different sprite collections. This is super cool, however, my code stopped working.

So how to create a sprite batcher from code?

Here is my code, it does create the batcher, but the batched sprites' positions and scales are all wrong, any clue?

Code: [Select]
            tk2dStaticSpriteBatcher batcher = new GameObject("spritebatcher").AddComponent<tk2dStaticSpriteBatcher>();
            batcher.spriteCollection = spriteCollection; // I bet this is useless under 2.0

            tk2dBatchedSprite[] batchedSpriteList = new tk2dBatchedSprite[count];
            Vector3 position = batcher.transform.position;
            for (int i = 0; i < count; ++i)
            {
                tk2dBatchedSprite batchedSprite = new tk2dBatchedSprite();
                batchedSprite.spriteCollection = spriteCollection; // i added this line for 2.0
                batchedSprite.name = "batched sprite";
                batchedSprite.spriteId = spriteCollection.GetSpriteIdByName(spriteName);
                batchedSprite.localScale = Vector3.one * 10;
                batchedSprite.position = position;
                position += new Vector3(10, 0, 0);
                batchedSpriteList[i] = batchedSprite;
            }

            batcher.batchedSprites = batchedSpriteList;
            batcher.Build();

Pages: [1]