From: Alexis Laferrière Date: Mon, 1 Feb 2016 16:45:35 +0000 (-0500) Subject: lib/gamnit: intro `Sprite::tint` X-Git-Url: http://nitlanguage.org lib/gamnit: intro `Sprite::tint` Signed-off-by: Alexis Laferrière --- diff --git a/lib/gamnit/flat.nit b/lib/gamnit/flat.nit index ab433bf..6f9dea4 100644 --- a/lib/gamnit/flat.nit +++ b/lib/gamnit/flat.nit @@ -59,7 +59,15 @@ class Sprite var scale = 1.0 is writable # Transparency applied to the texture on draw - var alpha = 1.0 is writable + fun alpha: Float do return tint[3] + + # Transparency applied to the texture on draw + fun alpha=(value: Float) do tint[3] = value + + # Tint applied to the texture on draw + # + # Require: `tint.length == 4` + var tint: Array[Float] = [1.0, 1.0, 1.0, 1.0] is writable private fun draw do @@ -73,7 +81,7 @@ class Sprite simple_2d_program.scale.array_enabled = false simple_2d_program.translation.uniform(center.x, -center.y, center.z, 0.0) - simple_2d_program.color.uniform(1.0, 1.0, 1.0, alpha) + simple_2d_program.color.uniform(tint[0], tint[1], tint[2], tint[3]) simple_2d_program.scale.uniform scale simple_2d_program.use_texture.uniform true