노드 귀속 회색 정령과 ui 컨트롤(9궁도 지원)-lua
-- 3.3final
--
-- Author: rex
-- Date: 2015-02-26 17:11:29
--
local shaderHelper = shaderHelper or {}
function shaderHelper:grayNode(node)
if node and type(node) == "userdata" then
-- fiter
local fiter = cc.GrayFilter:create()
fiter:initSprite(nil)
-- ui
if node.getVirtualRenderer then
--9 9 sprite, :getProtectedChildren
if node.isScale9Enabled ~= nil and node:isScale9Enabled() then
local sp_children = node:getVirtualRenderer():getProtectedChildren()
for k,v in pairs(sp_children) do
self:grayNode(v)
end
else
node:getVirtualRenderer():getSprite():setGLProgram(fiter:getProgram())
end
else
node:setGLProgram(fiter:getProgram())
end
local children = node:getChildren()
for k,v in pairs(children) do
self:grayNode(v)
end
end
end
-- shader
function shaderHelper:clearnShader(node)
if node and type(node) == "userdata" then
if node.getVirtualRenderer then
if node.isScale9Enabled ~= nil and node:isScale9Enabled() then
local sp_children = node:getVirtualRenderer():getProtectedChildren()
for k,v in pairs(sp_children) do
self:clearnShader(v)
end
else
node:getVirtualRenderer():getSprite():setGLProgram(cc.GLProgramCache:getInstance():getGLProgram("ShaderPositionTextureColor_noMVP"))
end
else
node:setGLProgram(cc.GLProgramCache:getInstance():getGLProgram("ShaderPositionTextureColor_noMVP"))
end
local children = node:getChildren()
for k,v in pairs(children) do
self:clearnShader(v)
end
end
end
return shaderHelper
참고: --getProtectedChildren 이 방법은 원본 라이브러리 Scale9Sprite 클래스에 직접 추가하고 Lua 사용 C++ 코드를 다음과 같이 내보냅니다.
Vector<Node*> Scale9Sprite::getProtectedChildren()const
{
return _protectedChildren;
}