1.CCNotificationCenter废弃了,建议用EventListnerCustom
layer._Listener1 = cc.EventListenerCustom:create("component game over",onEvent) local eventdispatcher = cc.Director:getInstance():getEventdispatcher() eventdispatcher:addEventListenerWithFixedPriority(layer._Listener1,1)
2.UILabel -------> Text
3. Node节点监听
local function onNodeEvent(event) if "exit" == event then ccexp.AudioEngine:stopAll() end end layer:registerScriptHandler(onNodeEvent)
4. 声效
ccexp.AudioEngine:stopAll()
5 Layercolor
local bgLayer = cc.Layercolor:create(cc.c4b(0,128,255,255));
6 ccui.TextFIEld
local function textFIEldEvent(sender,eventType) if eventType == ccui.TextfiledEventType.attach_with_ime then local textFIEld = sender textFIEld:runAction(cc.MoveBy:create(0.225,cc.p(0,20))) self._displayValueLabel:setString("attach with IME") elseif eventType == ccui.TextfiledEventType.detach_with_ime then local textFIEld = sender textFIEld:runAction(cc.MoveBy:create(0.175,-20))) self._displayValueLabel:setString("detach with IME") elseif eventType == ccui.TextfiledEventType.insert_text then self._displayValueLabel:setString("insert words") elseif eventType == ccui.TextfiledEventType.delete_backward then self._displayValueLabel:setString("delete word") end end local textFIEld = ccui.TextFIEld:create() textFIEld:settouchEnabled(true) textFIEld:setFontname(Font_Textname) textFIEld:setFontSize(30) textFIEld:setPlaceHolder("input words here") textFIEld:setposition(cc.p(WidgetSize.wIDth / 2.0,WidgetSize.height / 2.0)) textFIEld:addEventListener(textFIEldEvent) self._uiLayer:addChild(textFIEld)
7 .PageVIEw getPages():count() -----------> table.getn(cc.PageVIEw:getItems())
8 注册监听返回键
local function touch_key_back(keycode,event) if keyCode == cc.KeyCode.KEY_BACK then end end local Listener = cc.EventListenerKeyboard:create() Listener:registerScriptHandler(touch_key_back,cc.Handler.EVENT_KEYBOARD_RELEASED ) local eventdispatcher = clayer:getEventdispatcher() eventdispatcher:addEventListenerWithSceneGraPHPriority(Listener,clayer)
9自定义消息EventCustom
-- 发送消息 post message-- event将会被传递给消息接收函数,所以所有需要传递的数据都可放到event中local event = cc.EventCustom:new("MSG_TEST")event._usedata = {["state"]=self.curState,["actionID"]=self.actionID}cc.Director:getInstance():getEventdispatcher():dispatchEvent(event)
----
-- Listenerlocal ActorSprite = class("ActorSprite",cc.Node)function ActorSprite:initEventListener() self:enableNodeEvents() -- cc.Node self.eventListeners = {} -- user to delete when dtor local Listener = cc.EventListenerCustom:create(MSG_TEST,handler(self,self.onChangeState)) local eventdispatcher = self:getEventdispatcher() eventdispatcher:addEventListenerWithFixedPriority(Listener,1) table.insert(self.eventListeners,Listener) endfunction DogSprite:onChangeState(event) local dogID = event._usedata["dogID"] local actionID = event._usedata["actionID"] local eventname = event:getEventname()end
cc.Director:getInstance():getEventdispatcher():removeEventListener(var)
10 ListVIEw
-- 让单个Item 在ListVIEw 水平居中ListVIEw:setGravity(ccui.ListVIEwGravity.centerHorizontal)
11
cc.SpriteFrameCache:getInstance():addSpriteFrames("zwoptex/grossini.pList")
12 eventListener
注意 前置层是否有layout,layout默认阻挡触摸
local function ontouchEvent(touch,event) if eventType == "began" then return self:ontouchBegan(touch,event) elseif eventType == "moved" then self:ontouchmoved(touch,event) elseif eventType == "ended" then self:ontouchended(touch,event) elseif eventType == "cancelled" then self:ontouchCancelled(touch,event) end end self._touchListener = nil local Listener = cc.EventListenertouchOneByOne:create() Listener:setSwallowtouches(true) Listener:registerScriptHandler(self.ontouchBegan,cc.Handler.EVENT_touch_BEGAN ) Listener:registerScriptHandler(self.ontouchmoved,cc.Handler.EVENT_touch_MOVED ) Listener:registerScriptHandler(self.ontouchended,cc.Handler.EVENT_touch_ENDED ) Listener:registerScriptHandler(self.ontouchCancelled,cc.Handler.EVENT_touch_CANCELLED ) local eventdispatcher = self:getEventdispatcher() eventdispatcher:addEventListenerWithSceneGraPHPriority(Listener,self)
13 scheduler
scheduleScriptFunc
self.timer_schedulehandler = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(matchroom_ui.timefunction,1,false)
14 帧事件
local node = cc.csloader:createNode("Node.csb") node:setposition(cc.p(100,100)) self.parent:addChild(node) local action = cc.csloader:createTimeline("Node.csb") node:runAction(action) action:gotoFrameAndplay(0,false) local function onFrameEvent(frame) if nil == frame then return end local str = frame:getEvent() cclog("frame event:" .. str) if str == "end" then node:removeFromParentAndCleanup(true) end end action:setFrameEventCallFunc(onFrameEvent)end
15. c 与 c++ 混合编程
#if __cplusplusextern "C" {#endif/*....*/#if __cplusplus}#endif
16 平台判断
local targetPlatform = cc.Application:getInstance():getTargetPlatform()
17 androID uuID
//获得独一无二的Psuedo IDpublic static String getUniquePsuedoID() { String serial = null; String m_szDevIDShort = "35" + Build.BOARD.length()%10+ Build.BRAND.length()%10 + Build.cpu_ABI.length()%10 + Build.DEVICE.length()%10 + Build.disPLAY.length()%10 + Build.HOST.length()%10 + Build.ID.length()%10 + Build.MANUFACTURER.length()%10 + Build.MODEL.length()%10 + Build.PRODUCT.length()%10 + Build.Tags.length()%10 + Build.TYPE.length()%10 + Build.USER.length()%10 ; //13 位 try { serial = androID.os.Build.class.getFIEld("SERIAL").get(null).toString(); //API>=9 使用serial号 return new UUID(m_szDevIDShort.hashCode(),serial.hashCode()).toString(); } catch (Exception exception) { //serial需要一个初始化 serial = "serial"; // 随便一个初始化 } //使用硬件信息拼凑出来的15位号码 return new UUID(m_szDevIDShort.hashCode(),serial.hashCode()).toString();
18.javah 使用
//进入到 src 目录// -d -- 输出目录javah -d ../jni [com.xxxx.xxx (packagename)].Classname
19 cocos Ref
Ref::~Ref(){#if CC_ENABLE_SCRIPT_BINDING && !CC_ENABLE_GC_FOR_NATIVE_OBJECTS // if the object is referenced by Lua engine,remove it if (_luaID) { // add follow 2 lines ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); if (pEngine) ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptObjectByObject(this); } else { ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); if (pEngine != nullptr && pEngine->getScriptType() == kScriptTypeJavaScript) { pEngine->removeScriptObjectByObject(this); } }#endif#if CC_REF_LEAK_DETECTION if (_referenceCount != 0) untrackRef(this);#endif}总结
以上是内存溢出为你收集整理的项目移植手记全部内容,希望文章能够帮你解决项目移植手记所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)