Looks like this:
Imagine that the chest is a skill icon and has the number of seconds left on the cooldown on it.
The code plus example of use (weapon script):
PHP Code:
//#CLIENTSIDE
function onCreated()
{
this.skillIconImg = findimg(200);
with (this.skillIconImg) {
this.image = "chest.png";
this.x = int(screenwidth / 2 - 16);
this.y = int(screenheight / 2 - 16);
this.layer = 4;
}
this.cooldownImg = findimg(201);
with (this.cooldownImg) {
this.red = 1;
this.green = 1;
this.blue = 1;
this.alpha = 0.75;
this.mode = 2;
this.layer = 5;
}
this.trigger("onTimeout", null);
}
function onTimeout()
{
this.cooldownProgress -= 0.01;
if (this.cooldownProgress < 0) this.cooldownProgress += 1;
this.cooldownImg.polygon = this.getCooldownPolygon(this.cooldownProgress);
for (temp.i = 0; temp.i < this.cooldownImg.polygon.size(); temp.i += 2) {
this.cooldownImg.polygon[temp.i + 0] *= 32;
this.cooldownImg.polygon[temp.i + 0] += this.skillIconImg.x;
this.cooldownImg.polygon[temp.i + 1] *= 32;
this.cooldownImg.polygon[temp.i + 1] += this.skillIconImg.y;
}
setTimer(0.05);
}
//temp.progress goes from 0.0 to 1.0, where 0.0 is no cooldown and 1.0 is full cooldown.
//Returns an array compatible with TShowImg.polygon with coordinates ranging from (0, 0) to (1, 1).
function getCooldownPolygon(temp.progress)
{
temp.angleInDegrees = temp.progress * 360;
if (temp.angleInDegrees <= 0) return null;
if (temp.angleInDegrees >= 360) return {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};
temp.polygon = {
0.5, 0.5,
0.5, 0.0
};
temp.a = degtorad(90 + temp.angleInDegrees);
temp.dx = +cos(temp.a);
temp.dy = -sin(temp.a);
if (temp.angleInDegrees > 0) {
if (temp.angleInDegrees < 45) {
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
temp.polygon.add(0);
}
else {
temp.polygon.add(0.0);
temp.polygon.add(0.0);
}
}
if (temp.angleInDegrees >= 45) {
if (temp.angleInDegrees < 135) {
temp.polygon.add(0.0);
temp.polygon.add(0.5 - (temp.dy/temp.dx) * 0.5);
}
else {
temp.polygon.add(0.0);
temp.polygon.add(1.0);
}
}
if (temp.angleInDegrees >= 135) {
if (temp.angleInDegrees < 225) {
temp.polygon.add(0.5 + (temp.dx/temp.dy) * 0.5);
temp.polygon.add(1.0);
}
else {
temp.polygon.add(1.0);
temp.polygon.add(1.0);
}
}
if (temp.angleInDegrees >= 225) {
if (temp.angleInDegrees < 315) {
temp.polygon.add(1.0);
temp.polygon.add(0.5 + (temp.dy/temp.dx) * 0.5);
}
else {
temp.polygon.add(1.0);
temp.polygon.add(0.0);
}
}
if (temp.angleInDegrees >= 315) {
if (temp.angleInDegrees < 360) {
temp.polygon.add(0.5 - (temp.dx/temp.dy) * 0.5);
temp.polygon.add(0.0);
}
else {
temp.polygon.add(0.5);
temp.polygon.add(0.0);
}
}
return temp.polygon;
}
The important code with all the math in it is the
getCooldownPolygon function.
Assembly required. "Batteries not included."