Cocos2d-x 手游聊天系统Demo实现(Lua实现)

Cocos2d-x 手游聊天系统Demo实现(Lua实现),第1张

概述转载请注明:IT_xiao小巫    本篇博客给大家分享的是一个手游聊天系统,笔者也是第一次使用Cocos2d-x来实现这样一个模块,其中有很多不清楚不明白的地方都是通过自己不断摸索实现的,前面笔者对聊天系统做的简单的需求分析,只是对聊天的一些元素进行的说明还不太够专业。本篇博客会给大家介绍如何实现一个手游聊天Demo,会从代码层面上给大家做相关的说明,如有不对或者错漏的地方请各位明确指出并纠正。

转载请注明:IT_xiao小巫

本篇博客给大家分享的是一个手游聊天系统,笔者也是第一次使用Cocos2d-x来实现这样一个模块,其中有很多不清楚不明白的地方都是通过自己不断摸索实现的,前面笔者对聊天系统做的简单的需求分析,只是对聊天的一些元素进行的说明还不太够专业。本篇博客会给大家介绍如何实现一个手游聊天Demo,会从代码层面上给大家做相关的说明,如有不对或者错漏的地方请各位明确指出并纠正。


首先来给大家看一下动态效果图:



本篇博客内容大纲:

1. 加载Cocostudio制作的UI

2. button的触摸事件监听

3. ListVIEw添加列表项并设置列表点击事件

4. 富文本实现(可显示颜色文字和图片、动画)

5. 文本输入框实现(解决pc键盘无法删除字符的BUG)

6. 动态往ListVIEw添加列表项



一、加载Cocostudio制作的UI

笔者所分享的这个Demo是通过Cocostudio的UI编辑器制作的,童鞋们也可自己制作更加好看的UI,不过一般都会有美工帮我们做好让我使用的。如下图所示:



UI制作完之后,导出项目,然后把资源复制到我们项目的res目录下,笔者这里是把ChatUI_1复制到了res下,然后我们使用Lua代码实现加载Json文件到我们的程序中去:

[JavaScript] view plain copy ChatScene.Widget=ccs.GUIReader:getInstance():WidgetFromJsonfile("ChatUI_1/ChatUI_1.Json")
我们在编辑器添加了多个对象:

WorldPanel、PartyPanel、ChatPanel分别对应世界、公会、私聊三个板块,板块下面对应其相应的子节点:WordList、PartyList、ChatList。

我们需要在程序中找到它们:

copy --[[ ============================ findVIEws() 找到UI控件 ============================ ]]-- functionChatScene.findVIEws() ChatScene.Widget=ccs.GUIReader:getInstance():WidgetFromJsonfile("ChatUI_1/ChatUI_1.Json") ChatScene.Widget:setposition(cc.p(40,40)) loadListVIEwItemFromJson() --获得UI界面上的3个按钮 worldbutton=ChatScene.Widget:getChildByTag(6) partybutton=ChatScene.Widget:getChildByTag(7) chatbutton=ChatScene.Widget:getChildByTag(8) --获得三个每个按钮对应的三个面板 wordPanel=ChatScene.Widget:getChildByTag(5) partyPanel=ChatScene.Widget:getChildByTag(9) chatPanel=ChatScene.Widget:getChildByTag(10) --获得每个面板的ListVIEw worldList=wordPanel:getChildByTag(13) partyList=partyPanel:getChildByTag(14) chatList=chatPanel:getChildByTag(15) --获得输入框 inputBox=ChatScene.Widget:getChildByTag(11) sendbutton=ChatScene.Widget:getChildByTag(12) dialog=ChatScene.Widget:getChildByTag(20) chat=dialog:getChildByTag(21) lahei=dialog:getChildByTag(22) closebutton=dialog:getChildByTag(27) end
每个UI对象有相应的Tag属性,我们可以通过找到其父节点,然后调用getChildByTag传进tag的值找到控件。只有找到这些控件,我们才能去使用它。


二、button的触摸事件监听

笔者这个demo,通过监听“世界”、“公会”、“私聊”三个按钮来分别切换不同的板块,按钮的触摸监听事件很简单:

copy --设置按钮监听事件 worldbutton:addtouchEventListener(touchEvent) partybutton:addtouchEventListener(touchEvent) chatbutton:addtouchEventListener(touchEvent)
copy touchEvent 触摸事件回调方法 localfunctiontouchEvent(sender,eventType) ifsender:getTag()==TAG_WORLD_buttonthen wordPanel:setVisible(true) partyPanel:setVisible(false) chatPanel:setVisible(false) dialog:setVisible( ChatScene.setCurrentTag(TAG_WORLD) elseifsender:getTag()==TAG_PARTY_buttonthen partyPanel:setVisible( wordPanel:setVisible( ChatScene.setCurrentTag(TAG_PARTY) elseifsender:getTag()==TAG_CHAT_buttonthen ChatScene.setCurrentTag(TAG_CHAT) end
以上面这种方式就可以实现切换三个板块了。


三、ListVIEw添加列表项并设置列表点击事件

我们可以看到效果图里面每个板块下面有对应的列表,它是使用Cocos2d-x UI中的ListVIEw所呈现的。

笔者感觉使用ListVIEw比较麻烦,这里笔者给出相应的使用方法供大家参考:

--首先我们为ListVIEw提供三组数据

copy
--初始化三组数据 localarray={} for
i=1,20do
array[i]=string.format("请叫我巫大大%d",i-1) end localarray1={} do
array1[i]=string.format("公会开放啦%d",i-1) end localarray2={} array2[i]=string.format("私聊列表项%d",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> end
--设置默认模型

copy
--创建模型 localdefault_button=ccui.button:create("cocosui/backtotoppressed.png","cocosui/backtotopnormal.png") default_button:setname("Titlebutton") --创建默认item localdefault_itme=ccui.Layout:create() default_itme:settouchEnabled( default_itme:setContentSize(default_button:getContentSize()) default_button:setposition(cc.p(default_itme:getContentSize().wIDth/2.0,default_itme:getContentSize().height/2.0)) default_itme:addChild(default_button) --设置模型 worldList:setItemmodel(default_itme)
--添加自定义项

copy
--获得数组的大小 localcount=table.getn(array) print("count:"..count) --添加自定义item --创建一个button localcustom_button=ccui.button:create("cocosui/button.png","cocosui/buttonHighlighted.png") --设置button名字 custom_button:setname("Titlebutton") --设置按钮使用九宫(scale9)渲染器进行渲染 custom_button:setScale9Enabled( --设置内容尺寸 custom_button:setContentSize(default_button:getContentSize()) --创建一个布局 localcustom_item=ccui.Layout:create() --设置内容大小 custom_item:setContentSize(custom_button:getContentSize()) --设置位置 custom_button:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,custom_item:getContentSize().height/2.0)) --往布局中添加一个按钮 custom_item:addChild(custom_button) --往ListVIEw中添加一个布局 worldList:addChild(custom_item) end
--每一项数据

copy
--设置itemdata items_count=table.getn(worldList:getItems()) --返回一个索引和参数相同的项. localitem=worldList:getItem(i-1) localbutton=item:getChildByname("Titlebutton") localindex=worldList:getIndex(item) button:setTitleText(array[index+1]) end
--设置ListVIEw的点击事件和滚动事件

copy
--设置ListVIEw的监听事件 worldList:addScrollVIEwEventListener(scrollVIEwEvent) worldList:addEventListener(ListVIEwEvent)

copy
--ListVIEw点击事件回调 localfunctionListVIEwEvent(sender,eventType) --事件类型为点击结束 if
eventType==ccui.ListVIEwEventType.ONSELECTEDITEM_ENDthen
print("selectchildindex=",sender:getCurSelectedindex()) if
dialog:isVisible()==truethen
dialog:setVisible(else ChatScene.showDialog() --滚动事件方法回调 functionscrollVIEwEvent(sender,248)"> --滚动到底部 ifeventType==ccui.ScrollvIEwEventType.scrollToBottomthen print("SCRolL_TO_BottOM") --滚动到顶部 elseifeventType==ccui.ScrollvIEwEventType.scrollTotopthen print("SCRolL_TO_top") end

四、富文本实现(可显示颜色文字和图片、动画)

何为富文本?笔者的理解是有着丰富文本的展示方式,比如可以展示颜色文本、图片、动画、还有超链接的这种就叫富文本。以前旧的版本Cocos2d-x可能并未提供这方面的支持,至于是哪个版本支持的笔者也没有去深究,笔者这里使用版本是Cocos2d-x 3.2,它就提供了类似富文本的类,满足基本的需求。



代码实现:

copy ================== RichText 富文本 ================= functionChatScene.RichText() localrichText=ccui.RichText:create() richText:ignoreContentAdaptWithSize( richText:setContentSize(cc.size(100,100)) localre1=ccui.RichElementText:create(1,cc.c3b(255,255),"Thiscoloriswhite.","Helvetica",10) localre2=ccui.RichElementText:create(2,0),"Andthisisyellow.",10) localre3=ccui.RichElementText:create(3,cc.c3b(0,"Thisoneisblue.",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> localre4=ccui.RichElementText:create(4,"Andgreen.",248)"> localre5=ccui.RichElementText:create(5,"Lastoneisred",248)"> localreimg=ccui.RichElementimage:create(6,"cocosui/slIDerballnormal.png") --添加ArmaturefileInfo,由ArmatureDataManager管理 ccs.ArmatureDataManager:getInstance():addArmaturefileInfo("cocosui/100/100.ExportJson") localarr=ccs.Armature:create("100") arr:getAnimation():play("Animation1") localrecustom=ccui.RichElementCustomNode:create(1,arr) localre6=ccui.RichElementText:create(7,127,"Havefun!!",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> richText:pushBackElement(re1) richText:insertElement(re2,1) richText:pushBackElement(re3) richText:pushBackElement(re4) richText:pushBackElement(re5) richText:insertElement(reimg,2) richText:pushBackElement(recustom) richText:pushBackElement(re6) richText:setLocalZOrder(10) returnrichText end

五、文本输入框实现(解决pc键盘无法删除字符的BUG)

CocostudioUI编辑器提供TextFIEld(输入框),笔者在这里也对它进行了实现,聊天系统一般需要玩家输入信息,所以这里提供了一个输入框。但笔者在使用这个UI的时候,发现在win32平台不能对输入的文本进行删除,但在移动设备可以使用输入法对它进行编辑,所以笔者在这里做了相关的处理把这个BUG修正了。

copy
---键盘事件监听回调方法 function
onkeypressed(keycode,event)
print("keypress") if
keycode==cc.KeyCode.KEY_BACKSPACEthen
localstr=inputBox:getStringValue() str=string.sub(str,string.len(str)-1) inputBox:setText(str) --键盘监听事件 localkeyListener=cc.EventListenerKeyboard:create() keyListener:registerScriptHandler(onkeypressed,cc.Handler.EVENT_KEYBOARD_pressed) localeventdispatcher=ChatScene.uiLayer:getEventdispatcher() eventdispatcher:addEventListenerWithSceneGraPHPriority(keyListener,ChatScene.uiLayer)
通过以上方式,我们就可以使用简拼的BackSpace对字符进行删除了。大家请叫我活雷锋。


六、动态往ListVIEw添加列表项

笔者想到聊天系统的列表是不断刷新的,所以可能需要实现动态添加列表项,其实这个实现很简单的,只需要在代码中监听相应的事件,然后往ListVIEw添加一项就可以了。

这里我监听了发送按钮的点击事件,然后获取到输入框的文本,在把文本添加到列表项中去。

copy
if
sender:getTag()==TAG_SEND_buttonthen
print("sendText...") --获得输入框的文本 localvalue=inputBox:getStringValue() localtextVIEw=ccui.Text:create(value,"Arial",20) print("value:"..value) ifeventType==ccui.touchEventType.beganthen --localcustom_text=ChatScene.RichText() localcustom_item=ccui.Layout:create() custom_item:setContentSize(textVIEw:getContentSize()) textVIEw:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,custom_item:getContentSize().height/2.0)) custom_item:addChild(textVIEw) --如果当前Tag为世界 ifChatScene.getCurrentTag()==TAG_WORLDthen --插入自定义项 worldList:insertCustomItem(custom_item,0) --worldList:addChild(custom_item) elseifChatScene.getCurrentTag()==TAG_PARTYthen --partyList:addChild(custom_item) partyList:insertCustomItem(custom_item,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> elseifChatScene.getCurrentTag()==TAG_CHATthen --chatList:addChild(custom_item) chatList:insertCustomItem(custom_item,0) end

以上基本是笔者这个聊天系统的重要内容,下面把完整的实现代码给大家:

copy
@H_272_1404@ =============== ChatSence 聊天系统模块 =============== --类 localChatScene={} ChatScene.uiLayer=nil ChatScene.Widget=nil --窗口大小 localwinSize=nil localworldbutton=nil localpartybutton=nil localchatbutton=nil localwordPanel=nil localpartyPanel=nil localchatPanel=nil localworldList=nil localpartyList=nil localchatList=nil --列表项 localListvIEw_item=nil localhead_icon=nil locallevel=nil localname=nil localtext=nil --列表项个数 localitems_count=nil localinputBox=nil localsendbutton=nil --d出对话框 localdialog=nil localchat=nil locallahei=nil localclosebutton=nil --三个标记 localflag=nil localTAG_WORLD=1--标识世界 localTAG_PARTY=2--标识公会 localTAG_CHAT=3--标识私聊 --一些按钮的Tag localTAG_WORLD_button=1 localTAG_PARTY_button=2 localTAG_CHAT_button=3 localTAG_SEND_button=4 localTAG_CHAT_button2=5 localTAG_LAHEI_button=6 localTAG_CLOSE_button=7 --场景创建 ChatScene.create=function() localscene=cc.Scene:create() scene:addChild(ChatScene.createChatLayer()) returnscene --[[ elseifsender:getTag()==TAG_SEND_buttonthen print("sendText...") --获得输入框的文本 localvalue=inputBox:getStringValue() localtextVIEw=ccui.Text:create(value,20) print("value:"..value) ifeventType==ccui.touchEventType.beganthen --localcustom_text=ChatScene.RichText() custom_item:setContentSize(textVIEw:getContentSize()) textVIEw:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> custom_item:addChild(textVIEw) --如果当前Tag为世界 ifChatScene.getCurrentTag()==TAG_WORLDthen --插入自定义项 worldList:insertCustomItem(custom_item,248)"> --worldList:addChild(custom_item) elseifChatScene.getCurrentTag()==TAG_PARTYthen --partyList:addChild(custom_item) partyList:insertCustomItem(custom_item,248)"> elseifChatScene.getCurrentTag()==TAG_CHATthen --chatList:addChild(custom_item) chatList:insertCustomItem(custom_item,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> elseifsender:getTag()==TAG_CHAT_button2then chatPanel:setVisible(true) elseifsender:getTag()==TAG_LAHEI_buttonthen print("我就把你拉黑,逗比") elseifsender:getTag()==TAG_CLOSE_buttonthen elseifsender:getTag()==8then ifeventType==ccui.touchEventType.endedthen ChatScene.Widget:setVisible(notChatScene.Widget:isVisible()) functiononExit(strEventname) ChatScene.uiLayer:release() ChatScene.uiLayer=nil --[[ addOpenbutton 添加一个打开的按钮 ================= ]]-- functionChatScene.addOpenbutton() localopenbutton=ccui.button:create()--创建一个按钮 openbutton:settouchEnabled(true)--设置可触摸 openbutton:loadTextures("cocosui/animationbuttonnormal.png","cocosui/animationbuttonpressed.png","")--加载纹理 openbutton:setAnchorPoint(cc.p(0,0)) openbutton:setposition(cc.p(winSize.wIDth-100,winSize.height-50)) ChatScene.uiLayer:addChild(openbutton,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> openbutton:setTag(8) openbutton:addtouchEventListener(touchEvent) ============== textFIEldEvent 输入框监听事件回调方法 ============== functiontextFIEldEvent(sender,153); Font-weight:bold; background-color:inherit">ifeventType==ccui.TextfiledEventType.attach_with_imethen print("attach_with_ime") elseifeventType==ccui.TextfiledEventType.detach_with_imethen print("detach_with_ime") elseifeventType==ccui.TextfiledEventType.insert_textthen print("insert_text") elseifeventType==ccui.TextfiledEventType.delete_backwardthen print("delete_backward") --ListVIEw点击事件回调 ==================== createChatLayer 创建聊天层 ==================== functionChatScene.createChatLayer() ChatScene.uiLayer=cc.Layer:create()--创建ui层 print("getReferenceCount1:"..ChatScene.uiLayer:getReferenceCount()) winSize=cc.Director:getInstance():getWinSize()--获得屏幕大小 ChatScene.setCurrentTag(TAG_WORLD) ChatScene.addOpenbutton() ChatScene.findVIEws() ChatScene.settouchEnabled() ChatScene.setTags() ChatScene.addtouchEventListener() --初始化三组数据 localarray={} array[i]=string.format("请叫我巫大大%d",248)"> localarray1={} array1[i]=string.format("公会开放啦%d",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> localarray2={} array2[i]=string.format("私聊列表项%d",108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --创建模型 worldList:setItemmodel(default_itme) --这里是5项 -- --print("i:"..i) ----压栈一个默认项(通过克隆创建的)进ListVIEw. --worldList:pushBackDefaultItem() --end -- ----插入默认项 -- ----插入一个默认项(通过克隆创建的)进ListVIEw. --worldList:insertDefaultItem(0) --使用cleanup清空容器(container)中的所有子节点(children) --worldList:removeAllChildren() --localtestSprite=cc.Sprite:create("cocosui/backtotoppressed.png") --testSprite:setposition(cc.p(200,200)) --worldList:addChild(testSprite) --获得数组的大小 localcount=table.getn(array) print("count:"..count) --添加自定义item --创建一个button localcustom_button=ccui.button:create("cocosui/button.png","cocosui/buttonHighlighted.png") --设置button名字 custom_button:setname("Titlebutton") --设置按钮使用九宫(scale9)渲染器进行渲染 custom_button:setScale9Enabled( --设置内容尺寸 custom_button:setContentSize(default_button:getContentSize()) --创建一个布局 --设置内容大小 custom_item:setContentSize(custom_button:getContentSize()) --设置位置 custom_button:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,248)"> --往布局中添加一个按钮 custom_item:addChild(custom_button) --往ListVIEw中添加一个布局 worldList:addChild(custom_item) --localfunctioncustombuttonListener(sender,touchType) ifsender:getTag()==1then --dialog:setVisible( --end custom_button:setname("wwj") partyList:addChild(custom_item) custom_button:setname("wwj") chatList:addChild(custom_item) localcustom_text=ChatScene.RichText() custom_item:settouchEnabled( custom_item:setContentSize(custom_text:getContentSize()) custom_text:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> custom_item:addChild(custom_text) chatList:addChild(custom_item) --localcustom_button=ccui.button:create("cocosui/button.png",248)"> --custom_button:setname("wwj") --custom_button:setScale9Enabled( --custom_button:setContentSize(default_button:getContentSize()) --localcustom_item2=ccui.Layout:create() --custom_item2:setContentSize(custom_button:getContentSize()) --custom_button:setposition(cc.p(custom_item2:getContentSize().wIDth/0.6,custom_item2:getContentSize().height/0.6)) --custom_item2:addChild(custom_button) --custom_button:setTag(i) --custom_button:addtouchEventListener(custombuttonListener) --chatList:addChild(custom_item2) --插入自定义item localitems=worldList:getItems()--返回项的集合 --获得项的个数 localitems_count=table.getn(items) --custom_button:setname("Titlebutton")--改变Widget的名字,使用名字可以更轻松地识别出该Widget true)--设置按钮使用九宫(scale9)渲染器进行渲染 --localcustom_item=ccui.Layout:create() --custom_item:setContentSize(custom_button:getContentSize()) --custom_button:setposition(cc.p(custom_item:getContentSize().wIDth/2.0,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> --custom_item:addChild(custom_button) --custom_item:setTag(1) --worldList:insertCustomItem(custom_item,items_count) --设置itemdata items_count=table.getn(worldList:getItems()) --返回一个索引和参数相同的项. localitem=worldList:getItem(i-1) localbutton=item:getChildByname("Titlebutton") localindex=worldList:getIndex(item) button:setTitleText(array[index+1]) localpartyListItems_count=table.getn(partyList:getItems()) localitem=partyList:getItem(i-1) localbutton=item:getChildByname("wwj") localindex=partyList:getIndex(item) button:setTitleText(array1[index+1]) localchatListItems_count=table.getn(chatList:getItems()) localitem=chatList:getItem(i-1) localbutton=item:getChildByname("wwj") localindex=chatList:getIndex(item) button:setTitleText(array2[index+1]) --移除Tag=1的子节点 --worldList:removeChildByTag(1) --移除项byindex --items_count=table.getn(worldList:getItems()) --worldList:removeItem(items_count-1) --设置ListVIEw对齐方式为横向居中 worldList:setGravity(ccui.ListVIEwGravity.centerVertical) --setitemsmargin worldList:setItemsmargin(2.0) worldList:setBounceEnabled( --设置ListVIEw对齐方式为横向居中 partyList:setGravity(ccui.ListVIEwGravity.centerVertical) --setitemsmargin partyList:setItemsmargin(2.0) inputBox:addEventListener(textFIEldEvent) ChatScene.uiLayer:addChild(ChatScene.Widget) ChatScene.Widget:setVisible( --ChatScene.uiLayer:registerScriptHandler(onExit) returnChatScene.uiLayer functionListVIEwItem() locallayout=ccui.Layout:create() layout:setSizePercent(cc.p(200,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> layout:setBackGroundcolorType(ccui.LayoutBackGroundcolorType.solID) layout:setBackGroundcolor(cc.c3b(255,248)"> localimage=ccui.ImageVIEw:create("") layout:addChild(image) returnlayout functionloadListVIEwItemFromJson() ListvIEw_item=ccs.GUIReader:getInstance():WidgetFromJsonfile("res/ListvIEw_item/ListvIEw_item.ExportJson") head_icon=ListvIEw_item:getChildByTag(6) level=ListvIEw_item:getChildByTag(7) name=ListvIEw_item:getChildByTag(8) text=ListvIEw_item:getChildByTag(9) =================== 设置相关标记 functionChatScene.setTags() worldbutton:setTag(TAG_WORLD_button) partybutton:setTag(TAG_PARTY_button) chatbutton:setTag(TAG_CHAT_button) sendbutton:setTag(TAG_SEND_button) chat:setTag(TAG_CHAT_button2) lahei:setTag(TAG_LAHEI_button) closebutton:setTag(TAG_CLOSE_button) addtouchEventListener 添加触摸事件 ================== functionChatScene.addtouchEventListener() --设置按钮监听事件 worldbutton:addtouchEventListener(touchEvent) partybutton:addtouchEventListener(touchEvent) chatbutton:addtouchEventListener(touchEvent) sendbutton:addtouchEventListener(touchEvent) chat:addtouchEventListener(touchEvent) lahei:addtouchEventListener(touchEvent) closebutton:addtouchEventListener(touchEvent) --设置ListVIEw的监听事件 worldList:addEventListener(ListVIEwEvent) partyList:addScrollVIEwEventListener(scrollVIEwEvent) partyList:addEventListener(ListVIEwEvent) chatList:addScrollVIEwEventListener(scrollVIEwEvent) chatList:addEventListener(ListVIEwEvent) ---键盘事件监听回调方法 functiontextFIEldCompleteHandler() ===================== settouchEnabled 设置一些控件可触摸 functionChatScene.settouchEnabled() --设置可触摸 worldbutton:settouchEnabled( partybutton:settouchEnabled( chatbutton:settouchEnabled( sendbutton:settouchEnabled( chat:settouchEnabled( lahei:settouchEnabled( closebutton:settouchEnabled( inputBox:settouchEnabled( setCurrentTag 设置当前Tag functionChatScene.setCurrentTag(tag) flag=tag; ================ 获得当前Tag functionChatScene.getCurrentTag() returnflag 显示dialog functionChatScene.showDialog() localpopup=cc.Sequence:create(cc.Scaleto:create(0.0,0.0), cc.Scaleto:create(0.06,1.05), cc.Scaleto:create(0.08,0.95),248)"> cc.Scaleto:create(0.08,1.0),108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> nil) dialog:runAction(popup) --返回场景 returnChatScene 总结

以上是内存溢出为你收集整理的Cocos2d-x 手游聊天系统Demo实现(Lua实现)全部内容,希望文章能够帮你解决Cocos2d-x 手游聊天系统Demo实现(Lua实现)所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存