Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Green to Red coloring

Robo
Guest
Quote
2020-09-17 13:10:29

Need some javascript to seamlessly change a health bar or other meter color from green at 100% and ending in red at 0% ?

here you go:

just setup before first drawing variable "cond" = 100
with a 2d overlay as "overlay"


// starting from 100%
var cond = ccbGetCopperCubeVariable("cond");
if (cond > 0) {
cond = cond - 1;
ccbSetCopperCubeVariable("cond", cond);

if (cond >= 50) {
var G = 255;
var R = (100 - cond) * 5.1;
R = Math.round(R);
} else if (cond >= 0) {
var R = 255;
var G = cond * 5.1;
G = Math.round(G);
}

var node = ccbGetSceneNodeFromName("overlay");
ccbSetSceneNodeProperty(node, "Background Color", R,G,0);
}


count2rfeit
Registered User
Quote
2020-09-17 16:38:30

very good.... thanks Robo!


Robo
Guest
Quote
2020-09-19 00:23:29

cheers count2rfeit - I'm using this in one of my battery meters which looks quite good - not 100% sure if better than dedicated pre-made pictures but maybe do a video and ask everyone...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact