2D Toolkit Forum

2D Toolkit => Support => Topic started by: Bona on May 10, 2012, 11:56:49 am

Title: Importing a Font into a Sprite Collection -- IndexOutOfRangeException
Post by: Bona on May 10, 2012, 11:56:49 am
Hi Unikron, thank you for providing these nice tools  ;D

I'm still learning the workflow and got stuck in "Importing a Font into a Sprite Collection"

My version is  1.7 final+patch 2 with Unity 3.5.1f2, after step 6 of the above walkthrough, I got these errors :

IndexOutOfRangeException: Array index is out of range.
tk2dSpriteCollectionBuilder.ProcessTexture (.tk2dSpriteCollection settings, Boolean additive, Boolean stretchPad, UnityEngine.Texture2D srcTex, Int32 sx, Int32 sy, Int32 tw, Int32 th, .SpriteLut& spriteLut, Int32 padAmount) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:309)
tk2dSpriteCollectionBuilder.Rebuild (.tk2dSpriteCollection gen) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:781)
tk2dSpriteCollectionEditorPopup.DrawToolbar () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:410)
tk2dSpriteCollectionEditorPopup.OnGUI () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:670)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

Have tried using the same .fnt for tk2d TextMesh without any problem, the font is from GlyphDesigner using Cocos2d Text format, also tried other formats and different char sizes and still couldn't pass that error.

Attached pls find 2 files for your testing use. Please help.

edit: attachments removed
Title: Re: Importing a Font into a Sprite Collection -- IndexOutOfRangeException
Post by: unikronsoftware on May 10, 2012, 02:06:51 pm
This is a bug in the current version. It only happens when you create a sprite collection with no sprites (and just a font). An easy fix for now is to drag in a really small sprite into the collection, and then add the font.

It'll be fixed in the next release.

Edit: Drop me a PM/email if you'd like a copy and I'll send it your way. It may be a few days to a week before it gets packaged up and released.
Title: Re: Importing a Font into a Sprite Collection -- IndexOutOfRangeException
Post by: Bona on May 11, 2012, 09:41:14 am
Thank you Unikron, that fixed it, SpriteCollection_Data folder of those fonts generated without problem.

Other than TextMesh, can I use those character sprites as "Tk 2d Sprite", too?

When I use the sprite collection the dropdown shows only the small sprite that I added to fix the bug, couldn't access to font sprites in the same collection from inspector. Don't know if it's designed to work this way, it would be nice if the font sprites can be used individually, too.

I'll wait for the next update, please take your time, your tools are very nice and I'm enjoy using it. ;)
Title: Re: Importing a Font into a Sprite Collection -- IndexOutOfRangeException
Post by: unikronsoftware on May 11, 2012, 11:02:16 am
The font sprites aren't displayed in the sprite list, intentionally, as they don't exist as sprites. The reason is in a lot of cases you want to mix sprites & fonts in the same collection, and say you have 512 glyphs, that will seriously clutter up the selection dialog. I'll think of a way to make it optional at some point.
Title: Re: Importing a Font into a Sprite Collection -- IndexOutOfRangeException
Post by: Bona on May 11, 2012, 11:16:57 am
Thank you for clarifying, back to explore the script ref now  ;D