2D Toolkit Forum
2D Toolkit => Support => Topic started by: hizral84 on September 20, 2013, 03:05:51 am
-
Hello there,
This just purchase 2D Toolkit and this is my first time using it. I would like make a number counter using the 2D toolkit. Usually I used a sprite atlas that I made my self for the number zero to nine and just assign the coordinates manually. Below here is the script that I alwayt used for the number sprites:
using UnityEngine;
using System.Collections;
public class TestManager : MonoBehaviour {
public int testScore; //If the testScore is increasing it will move the coordinates to the next sprites.
public GameObject score;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (score != null)
{
//TextSprite (score, 10, 0, 10, "fScore", testScore);
}
}
void TextSprite (GameObject spriteObject, int columSize, int colFrameStart, int totalFrame, string type, int index)
{
int fScore;
fScore = index % 10;
if (type == "fScore")
{
index = fScore;
}
index = index % columSize;
Vector2 offSet;
offSet = new Vector2 (1.0f / columSize * index, 0);
spriteObject.renderer.material.mainTextureOffset = offSet;
}
}
so now when I create a power of two from the 2D toolkit option and used my script it does not work why is that?
Thank you.
-
Thats because tk2d packs the sprite much more efficiently than is possible using textureOffset. Also, as you probably already know, tetxureOffset will mean you need a unique material for everything, which will break batching.
If you're just wanting to create a number counter, why don't you just use the textmesh instead - it will simply let you write numbers yourself, like scoreTextMesh.text = "00031"; and be done with it.
http://unikronsoftware.com/2dtoolkit/doc/2.20/ - check the font mini tutorial