cocos2dx之裁剪

前端之家收集整理的这篇文章主要介绍了cocos2dx之裁剪前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. --裁剪 local layer = cc.LayerGradient:create(cc.c4b(255,255,255),cc.c4b(0,255))
  2. --渐变层 self:addChild(layer)
  1. --裁剪容器
  2. local clippingNode = cc.ClippingNode:create()
  3. clippingNode:setPosition(Const["CENTER_X"],Const["CENTER_Y"] + 150)
  4. clippingNode:setInverted(true) --设为true则会显示stencil模板外的区域,默认是显示模板stencil的区域
  5. self:addChild(clippingNode)
  1. --向容器中添加内容
  2. local str = ccui.Text:create()
  3. :setFontSize(34)
  4. :setTextColor(cc.c3b(255,0,0))
  5. :setString("哈哈哈哈--1-2-3-4-5-6-7-8-9-0--哈哈哈哈")
  6. clippingNode:addChild(str)
  1. --设容器模板,默认显示出模板
  2. local stencil = cc.LayerColor:create(cc.c3b(220,0))
  3. stencil:setContentSize(cc.size(25,100))
  4. stencil:ignoreAnchorPointForPosition(false)
  5. stencil:setAnchorPoint(cc.p(0.5,0.5))
  6. clippingNode:setStencil(stencil)
  1. --模板移动,可看的区域移动
  2. 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,moveBy2)) stencil:runAction(action)

猜你在找的Cocos2d-x相关文章