Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
[2016.10] Sprite:setBlendMode(src, dst) — Gideros Forum

[2016.10] Sprite:setBlendMode(src, dst)

n1cken1cke Maintainer
edited November 2016 in Announcements
In Gideros 2016.10 `setBlendMode` has extended version with 2 parameters (blend functions): `src` and `dst`. They define how top sprite colors (`src`) will be blended with bottom sprite colors (`dst`). If you are familiar with image editors like Gimp or Photoshop you know they have many ready blend modes to mix layers in various ways for great effects. Those blend modes are just combinations of aforementioned blend functions so we have added direct support of those functions to Gideros.
There are 11 of them: Sprite.ZERO, Sprite.ONE, Sprite.SRC_COLOR, Sprite.ONE_MINUS_SRC_COLOR, Sprite.DST_COLOR, Sprite.ONE_MINUS_DST_COLOR, Sprite.SRC_ALPHA, Sprite.ONE_MINUS_SRC_ALPHA, Sprite.DST_ALPHA, Sprite.ONE_MINUS_DST_ALPHA, Sprite.SRC_ALPHA_SATURATE. This constants are represented in Lua as integers from 1 to 11. Therefore in Gideros we have 11 * 11 = 121 way to mix colors :)
To test extended `setBlendMode` you can use following snippet:
local topTex = Texture.new("top.png",true)
local btmTex = Texture.new("btm.png",true)
 
lh @ 10 -- label height
 
local w = (application:getDeviceWidth() - lh) / 11
local h = (application:getDeviceHeight() - lh) / 11
local s = math.min(w, h)
 
for x = 1, 11 do
	for y = 1, 11 do
		local top = Pixel.new(topTex, s, s)
		local btm = Pixel.new(btmTex, s, s)
		stage:addChild(btm)
		btm:addChild(top)
		btm:setBlendMode(x, y)
		btm:setPosition(lh + s * (x-1), lh + s * (y-1))
	end
end
 
local t = {}
for k,v in pairs(Sprite) do
	if tonumber(v) == v then t[v] = k end
end
 
for n = 1, 11 do
	local label = TextField.new(nil, t[n], "|")
	label:setX(lh + (n-1) * s + 2)
	label:setY(1)
	label:setClip(0, 0, s - 2, lh)
	stage:addChild(label)
	local line = Pixel.new(0x666666, 1, 1, lh + 11*s)
	line:setX(lh + n * s)
	stage:addChild(line)
end
 
for n = 1, 11 do
	local label = TextField.new(nil, t[n], "|")
	label:setY(lh + (n-0) * s - 2)
	label:setX(1)
	label:setRotation(-90)
	label:setClip(0, 0, s - 2, lh)
	stage:addChild(label)
	local line = Pixel.new(0x666666, 1, lh + 11*s, 1)
	line:setY(lh + n * s)
	stage:addChild(line)
end
Source images and screenshot are attached below but I suggest you to also experiment with other images to better understand how blend functions work.
blending.png
765 x 765 - 278K
btm.png
256 x 256 - 23K
top.png
256 x 256 - 2K
+1 -1 (+4 / -0 )Share on Facebook
«1

Comments

Sign In or Register to comment.