Cocos2dx lua 横向滚动字幕实现

Cocos2dx lua 横向滚动字幕实现,第1张

概述需求:要求设计一个顶部滚动栏,滚动后台推送的游戏消息文本。 要点:1、文本单行显示;2、文本背景半透明黑色(宽度不是全屏的); 设计:可以使用ClippingNode来实现该功能。 UI设计如上图所示。 代码实现: --跑马灯function InputLayer:AddUibroadcastMsg() _Panel_Clipping = UIUtils:GetWidgetByName(

需求:要求设计一个顶部滚动栏,滚动后台推送的游戏消息文本。

要点:1、文本单行显示;2、文本背景半透明黑色(宽度不是全屏的);

设计:可以使用ClipPingNode来实现该功能。



UI设计如上图所示。

代码实现:

--跑马灯function inputLayer:AddUibroadcastMsg()    _Panel_ClipPing = UIUtils:GetWidgetByname(_Widget,{"Panel_input","Panel_MsgOut","Panel_ClipPing"})    local Text_Msg =  UIUtils:GetWidgetByname(_Widget,"Panel_ClipPing","Text_Msg"})    Text_Msg:setVisible(false)    local fWIDth =_Panel_ClipPing:getContentSize().wIDth    local fheight = _Panel_ClipPing:getContentSize().height    local clipper = _Panel_ClipPing:getChildByname("_ClipPingNode")    if not clipper then        clipper = cc.ClipPingNode:create()        clipper:setContentSize(fWIDth,fheight)        clipper:setAnchorPoint(0,0)        clipper:setposition(0,0)        clipper:setname("_ClipPingNode")        _Panel_ClipPing:addChild(clipper)        local stencil = cc.DrawNode:create()        local rectangle = {            {0,0},{fWIDth,fheight},{0,fheight}        }        local rectangle = {cc.p(0,0),cc.p(fWIDth,fheight),cc.p(0,fheight)}        local white = cc.c4f(1,1,1)        stencil:drawpolygon(rectangle,4,white,white)        clipper:setStencil(stencil)    end    _scrollText = clipper:getChildByname("_ScrollText")    self._scrollStartX = fWIDth    if not _scrollText then        _scrollText = Text_Msg:clone()        local strMsg = "各位玩家请文明娱乐,远离赌博。如发现赌博行为,封停账号,并向公安机关举报!"        _scrollText:setString(strMsg)        _scrollText:setVisible(true)        _scrollText:ignoreContentAdaptWithSize(true)        _scrollText:setposition(fWIDth+10,5)        _scrollText:setname("_ScrollText")        clipper:addChild(_scrollText)        self._scrollScheduleID = ToolUtils:schedule(handler(self,self.StartScrollUpdate),0.0,false)    endend--滚动字幕function inputLayer:StartScrollUpdate()    local wIDth = _scrollText:getContentSize().wIDth    local posx = _scrollText:getpositionX()    if posx < -wIDth-10 then        local cuMsg = ""        local tmp = LobbyController:getGameScrollMsgs()        if #tmp > 0  then                cuMsg = tmp[1]            table.remove(tmp,1)        else            _scrollText:getParent():getParent():getParent():setVisible(false)            return        end        _scrollText:setString(cuMsg)        wIDth = _scrollText:getContentSize().wIDth        _scrollText:setpositionX(self._scrollStartX+10)        _scrollText:getParent():getParent():getParent():setVisible(true)    else        _scrollText:setpositionX(posx - 3)    endend
总结

以上是内存溢出为你收集整理的Cocos2dx lua 横向滚动字幕实现全部内容,希望文章能够帮你解决Cocos2dx lua 横向滚动字幕实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1084827.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存