cocos2dx之裁剪

  • Post author:
  • Post category:其他


--裁剪
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)



版权声明:本文为xi_mi_原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。