转载请注明: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文件到我们的程序中去:
- ChatScene.widget=ccs.GUIReader:getInstance():widgetFromJsonFile("ChatUI_1/ChatUI_1.json")
我们在编辑器添加了多个对象:
WorldPanel、PartyPanel、ChatPanel分别对应世界、公会、私聊三个板块,板块下面对应其相应的子节点:WordList、PartyList、ChatList。
我们需要在程序中找到它们:
--[[
- ============================
- 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,通过监听“世界”、“公会”、“私聊”三个按钮来分别切换不同的板块,按钮的触摸监听事件很简单:
--设置按钮监听事件
- worldButton:addTouchEventListener(touchEvent)
- partyButton:addTouchEventListener(touchEvent)
- chatButton:addTouchEventListener(touchEvent)
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提供三组数据
--初始化三组数据
- localarray={}
- fori=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
--设置默认模型
--创建模型
- 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)
--添加自定义项
--获得数组的大小
- 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
--每一项数据
--设置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的点击事件和滚动事件
--设置ListView的监听事件
- worldList:addScrollViewEventListener(scrollViewEvent)
- worldList:addEventListener(listViewEvent)
--ListView点击事件回调
- localfunctionlistViewEvent(sender,eventType)
- --事件类型为点击结束
- ifeventType==ccui.ListViewEventType.ONSELECTEDITEM_ENDthen
- print("selectchildindex=",sender:getCurSelectedIndex())
- ifdialog: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,它就提供了类似富文本的类,满足基本的需求。
代码实现:
==================
- 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修正了。
---键盘事件监听回调方法
- functiononkeyPressed(keycode,event)
- print("keypress")
- ifkeycode==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添加一项就可以了。
这里我监听了发送按钮的点击事件,然后获取到输入框的文本,在把文本添加到列表项中去。
ifsender: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
以上基本是笔者这个聊天系统的重要内容,下面把完整的实现代码给大家:
===============
- 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
- --弹出对话框
- 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
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|