--裁剪
local layer = cc.LayerGradient:create(cc.c4b(255, 255, 255, 255), cc.c4b(0, 0, 0, 255))
--渐变层
self:addChild(layer)
--裁剪容器
local clippingNode = cc.ClippingNode:create()
clippingNode:setPosition(Const["CENTER_X"], Const["CENTER_Y"] + 150)
clippingNode:setInverted(true) --设为true则会显示stencil模板外的区域,默认是显示模板stencil的区域
self:addChild(clippingNode)
--向容器中添加内容
local str = ccui.Text:create()
:setFontSize(34)
:setTextColor(cc.c3b(255, 0, 0))
:setString("哈哈哈哈--1-2-3-4-5-6-7-8-9-0--哈哈哈哈")
clippingNode:addChild(str)
--设容器模板,默认显示出模板
local stencil = cc.LayerColor:create(cc.c3b(220, 0, 0))
stencil:setContentSize(cc.size(25, 100))
stencil:ignoreAnchorPointForPosition(false)
stencil:setAnchorPoint(cc.p(0.5, 0.5))
clippingNode:setStencil(stencil)
local moveBy1 = cc.MoveBy:create(2.5, cc.p(str:getContentSize().width / 2 - 10, 0))
local moveBy2 = cc.MoveBy:create(2.5, cc.p(-(str:getContentSize().width / 2) + 10, 0))
local action = cc.RepeatForever:create(cc.Sequence:create(moveBy2, moveBy1, moveBy1, moveBy2))
stencil:runAction(action)