Java Code Examples for com.badlogic.gdx.graphics.Color#valueOf()

The following examples show how to use com.badlogic.gdx.graphics.Color#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java    From typing-label with MIT License 6 votes vote down vote up
/** Parses a color from the given string. Returns null if the color couldn't be parsed. */
static Color stringToColor(String str) {
    if(str != null) {

        // Try to parse named color
        Color namedColor = Colors.get(str.toUpperCase());
        if(namedColor != null) {
            return new Color(namedColor);
        }

        // Try to parse hex
        if(str.length() >= 6) {
            try {
                return Color.valueOf(str);
            } catch(NumberFormatException ignored) {
            }
        }
    }

    return null;
}
 
Example 2
Source File: JSONSkinLoader.java    From beatoraja with GNU General Public License v3.0 5 votes vote down vote up
private Color parseHexColor(String hex, Color fallbackColor) {
	try {
		return Color.valueOf(hex);
	} catch (Exception e) {
		return fallbackColor;
	}
}
 
Example 3
Source File: HexColorLmlAttribute.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void process(final LmlParser parser, final LmlTag tag, final Actor actor, final String rawAttributeData) {
    String hexValue = parser.parseString(rawAttributeData, actor);
    try {
        Color color = Color.valueOf(hexValue);
        actor.setColor(color);
    } catch (Exception exception) {
        parser.throwErrorIfStrict(
                "Unable to parse HEX color value from string \"" + hexValue + "\"",
                exception);
    }
}
 
Example 4
Source File: MaterialAsset.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void load() {
    MAP.clear();
    try {
        PropertiesUtils.load(MAP, file.reader());
        // shininess & opacity
        try {
            String value = MAP.get(PROP_SHININESS, null);
            if (value != null) {
                shininess = Float.valueOf(value);
            }
            value = MAP.get(PROP_OPACITY, null);
            if (value != null) {
                opacity = Float.valueOf(value);
            }
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }

        // diffuse color
        String diffuseHex = MAP.get(PROP_DIFFUSE_COLOR);
        if (diffuseHex != null) {
            diffuseColor = Color.valueOf(diffuseHex);
        }

        // asset dependencies
        diffuseTextureID = MAP.get(PROP_DIFFUSE_TEXTURE, null);
        normalMapID = MAP.get(PROP_MAP_NORMAL, null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: Param.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public static Color parseColor(String color) {
	if (color == null || color.trim().isEmpty()) {
		return null; // the default color in the style will be used
	}

	switch (color.trim()) {
	case "black":
		return Color.BLACK;
	case "white":
		return Color.WHITE;
	default:
		return Color.valueOf(color);
	}
}