From 6a32ff56f368b08dc038fd6d847dacfeb100c138 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 3 Aug 2020 10:48:52 +0100 Subject: [PATCH] `Display.Color.GetColorFromValue` is a new function that will take a hex color value and return it as an integer, for use in WebGL. This is now used internally by the Tint component and other classes. --- src/display/color/GetColorFromValue.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/display/color/GetColorFromValue.js diff --git a/src/display/color/GetColorFromValue.js b/src/display/color/GetColorFromValue.js new file mode 100644 index 000000000..6b744ef87 --- /dev/null +++ b/src/display/color/GetColorFromValue.js @@ -0,0 +1,23 @@ +/** + * @author Richard Davey + * @copyright 2020 Photon Storm Ltd. + * @license {@link https://opensource.org/licenses/MIT|MIT License} + */ + +/** + * Given a hex color value, such as 0xff00ff (for purple), it will return a + * numeric representation of it (i.e. 16711935) for use in WebGL tinting. + * + * @function Phaser.Display.Color.GetColorFromValue + * @since 3.50.0 + * + * @param {number} red - The hex color value, such as 0xff0000. + * + * @return {number} The combined color value. + */ +var GetColorFromValue = function (value) +{ + return (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); +}; + +module.exports = GetColorFromValue;