- Home /
Countdown timer with textures ?
Hello guys.
Does anybody know a simple way to create a timer with textures?
I created the textures for the numbers 0 to 9 and I was wondering how to make them work as a timer?
For example the zombieville money counter is using textures, how are they working?
Any help would be appreciated.
Answer by Peter G · Feb 22, 2011 at 11:30 PM
I don't know for sure how Zombieville is creating its textures, my guess is that it is a font, but if you need to, you could probably do something like:
var digitSprites : Texture2D[]; //Fill with 10 values 0-9;
function CalculateScore (score : int) : Texture2D[] { var scoreImages : Texture2D[] = new Texture2D[3]; //This would create a value to the 100's.
var onesColumn = score % 10;
scores[0] = digitSprites[onesColumn];
var tensColumn = (score % 100) - onesColumn;
tensColumn /= 10;
scores[1] = digitSprites[tensColumn];
var hundredsColumn = score % 1000;
hundredsColumn -= (tensColumn * 10 + onesColumn);
scores[2] = digitSprites[hundredsColumn];
return digitSprites;
//We fill the array in this order so that when we iterate through with a foreach loop the hundreds will be the first value returned.
//You could made a more generic version of this that could keep score up to any number of digits.
}
Then it would just be up to you to format the images into the correct spot.
Your answer
Follow this Question
Related Questions
Changing leaf colors in C# 1 Answer
How to create Timer animations? 1 Answer
How to make a random occurrences using a timer? 3 Answers
using player time as highscore 1 Answer
Resume timer after application exit 1 Answer