cocos2d-lua 左右移动广播条 跑马灯效果

前端之家收集整理的这篇文章主要介绍了cocos2d-lua 左右移动广播条 跑马灯效果前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

直接上代码

local braodWidth = 150 --跑马灯的长度 
    local label = cc.Label:createWithSystemFont("关于--------------hahhahdasdfwetf,asdlfawefasf","Microsoft YaHei",25) 
     :setPosition(cc.p(0,0)) 
     :setAnchorPoint(cc.p(0,0)) 
    local labelWidth = label:getContentSize().width 
    local time = 3 -- 这里可以根据label多长动态计算时间 
    local scrollViewLayer = cc.Layer:create():setPosition(cc.p(0,0)) 
    scrollViewLayer:setContentSize(label:getContentSize()) 


    local scrollView1 = cc.ScrollView:create() 
    if nil ~= scrollView1 then 
        scrollView1:setViewSize(cc.size(braodWidth,100)) 
        scrollView1:setPosition(cc.p(display.cx,display.cy)) 
        scrollView1:setDirection(cc.SCROLLVIEW_DIRECTION_NONE ) 
        scrollView1:setClippingToBounds(true) 
        scrollView1:setBounceable(true)
         scrollView1:setTouchEnabled(false) 
    end 
    scrollView1:addChild(label) 
    self:addChild(scrollView1) 


    if nil ~= scrollViewLayer_ then 
        scrollView1:setContainer(scrollViewLayer) 
        scrollView1:updateInset() 
    end 


    if labelWidth > braodWidth  then 
     local leftAction = cc.MoveBy:create(time,cc.p(braodWidth -labelWidth,0)) 
     local rightAction = cc.MoveBy:create(time,cc.p(labelWidth - braodWidth,0)) 
     local seqAction = cc.Sequence:create(leftAction,rightAction) 
     label:runAction(cc.RepeatForever:create(seqAction)) 
    end 
原文链接:https://www.f2er.com/cocos2dx/342987.html

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