直接上代码
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