版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
quick-cocos2d-x學(xué)習(xí)系列之十四測試用例 定義變量,創(chuàng)建13個場景名字localitems={"framework.helper","framework.native","framework.display","framework.crypto","work","framework.luabinding","framework.event","erface","framework.socketTcp","framework.timer","framework.gamestate","framework.transition","framework.nvgdrawnode"}game.createMenu函數(shù)用于創(chuàng)建一個UIListView,并向其中添加所有menu(每個menu的回調(diào)都為opentest).在滑動UIListView的時設(shè)置變量game.bListViewMove=true(停止滑動時重新設(shè)置為false),該值為true時,menu不調(diào)用。game.createSceneClass(name)用于創(chuàng)建一個class類。每個類創(chuàng)建兩個函數(shù)prepare,runTest。其中prepare函數(shù)創(chuàng)建一個Layer,設(shè)置觸摸,創(chuàng)建一個RETURN按鈕點(diǎn)擊返回到mainscene,創(chuàng)建一個label顯示標(biāo)題。如果有參數(shù)則顯示另一個label.其中runtest函數(shù)調(diào)用和自己Memu名字同名且多了一個Test單詞的函數(shù)。framework.helper調(diào)用game.createMenu函數(shù)增加menu.(這也是為什么該函數(shù)放在game.lua文件上的原因了)回調(diào)函數(shù)為runtest函數(shù)。該函數(shù)所有場景類均一致。該例加載config.lua文件。framework.native包含7個items,localitems={addImageAsync異步加載圖片display.addImageAsync("Coin0001.png",function(event,texture)printf("display.addImageAsync(\"Coin0001.png\")-event=%s,texture=%s",tostring(event),tostring(texture))self.coin=display.newSprite("Coin0001.png",display.left+100,display.cy)self:addChild(self.coin)end)加載完畢后調(diào)用函數(shù),顯示圖片到場景中。scale9Sprite通過命令newScale9Sprite,創(chuàng)建圖片GreenButton.png創(chuàng)建精靈設(shè)置精靈范圍最后設(shè)置fadeout和fadein.tilesSprite通過如下命令創(chuàng)建一個圖片組成的tilesprite,密集恐懼癥的小朋友要慎入。self.tilesSprite_=display.newTilesSprite("close.png",cc.rect(10,10,100,100)):pos(display.left+10,display.bottom+10):addTo(self)tiledBatchNode代碼如下:localcb=function(plist,image)self.tiledBatchNode_=display.newTiledBatchNode("#blocks9.png","blocks9ss.png",cc.size(170,170),10,10):pos(display.left+10,display.bottom+150):addTo(self)enddisplay.addSpriteFrames("blocks9ss.plist","blocks9ss.png",cb)加載圖片到幀,然后調(diào)用函數(shù)cb.其中函數(shù)display.addSpriteFrames()display.addSpriteFrames(plistFilename,image,handler)將指定的SpriteSheets材質(zhì)文件及其數(shù)據(jù)文件載入圖像幀緩存。格式:display.addSpriteFrames(數(shù)據(jù)文件名,材質(zhì)文件名)12345678<br>--同步加載紋理display.addSpriteFrames("Sprites.plist","Sprites.png")
--異步加載紋理localcb=function(plist,image)
--dosomethingenddisplay.addSpriteFrames("Sprites.plist","Sprites.png",cb)SpriteSheets通俗一點(diǎn)解釋就是包含多張圖片的集合。SpriteSheets材質(zhì)文件由多張圖片組成,而數(shù)據(jù)文件則記錄了圖片在材質(zhì)文件中的位置等信息。Parametersstring
plistFilename
數(shù)據(jù)文件名string
image
材質(zhì)文件名drawNode初始化了一個node節(jié)點(diǎn),進(jìn)行畫圖。一個實(shí)心圓,一個空心圓,一個方形,一個直線,一個三角型。progress創(chuàng)建一個原型的進(jìn)度條localprogress=display.newProgressTimer("Coin0001.png",display.PROGRESS_TIMER_RADIAL):pos(100,100):addTo(self)progress:setPercentage(60)gressNode_=progresslayerMultiTouch創(chuàng)建一個新的Layer.為其增加監(jiān)聽,回調(diào)函數(shù)為onTouch函數(shù)。onTouch函數(shù)實(shí)現(xiàn)多點(diǎn)觸摸。framework.cryptolocalitems={"AES256","XXTEA","Base64","MD5File","MD5",}AES256進(jìn)行AES256加密解密操作。XXTEAXXTEA加密,如下代碼:localp="Test123"localk="KEYKEY"localc=crypto.encryptXXTEA(p,k)printf("source:%s",p)printf("encryptXXTEA:%s",bin2hex(c))printf("decryptXXTEA:%s",crypto.decryptXXTEA(c,k))localp=string.rep("HELLO",15)localk="keykey"localc=crypto.encryptXXTEA(p,k)printf("source:%s",p)printf("encryptXXTEA:%s",bin2hex(c))printf("decryptXXTEA:%s",crypto.decryptXXTEA(c,k))Base64Base64加密解密操作。同XXTEA。MD5FileMD5算法,對文件進(jìn)行md5計(jì)算,代碼如下localfile=cc.FileUtils:getInstance():fullPathForFilename("config.lua")printf("md5filetest:%s->%s",file,crypto.md5file(file))MD5對字符串進(jìn)行MD5計(jì)算,如下代碼:localp=string.rep("HELLO",5)printf("md5Test:%s->%s",p,crypto.md5(p))worklocalitems={"createHTTPRequest","createHTTPRequestBadDomain","senddatatoserver","isLocalWiFiAvailable","isInternetConnectionAvailable","isHostNameReachable","getInternetConnectionStatus",}其中onResponse函數(shù)處理HTTP相關(guān)事件。如果事件不是progress則報(bào)錯,如果是competeled則獲取數(shù)據(jù)長度,如果dumpResponse為true則打印String。其他則打印”----------------------------------”。createHTTPRequestlocalurl="/feed/"self.requestCount=self.requestCount+1localindex=self.requestCountlocalrequest=network.createHTTPRequest(function(event)iftolua.isnull(self)thenprintf("REQUEST%dCOMPLETED,BUTSCENEHASQUIT",index)returnendself:onResponse(event,index)end,url,"GET")printf("REQUESTSTART%d",index)request:start()見14.3中對createHTTPRequest函數(shù)的解釋createHTTPRequestBadDomain代碼同上,只是連接到一個不存在的HTTP地址上去。senddatatoserver通過POST命令,發(fā)送數(shù)據(jù)到SERVER。isLocalWiFiAvailable判斷本地WIFI是否可用。isInternetConnectionAvailable判斷網(wǎng)連接是否可用。isHostNameReachable判斷一個網(wǎng)址是否可達(dá)。getInternetConnectionStatus通過network.getInternetConnectionStatus()命令,判斷互聯(lián)網(wǎng)、WIFI、3G網(wǎng)絡(luò)是否可用。framework.luabindinglocalitems={"avoidPeertableGC","getCppFunction",}avoidPeertableGClocalnode=display.newNode()node:addNodeEventListener(cc.NODE_EVENT,function(event)printf("nodeevent%s",)end)node.customVar=1node:setTag(1)self:addChild(node)printf("1.node.customVar=%s,expected=1",tostring(node.customVar))--1collectgarbage()collectgarbage()printf("2.node.customVar=%s,expected=1",tostring(node.customVar))--1self:performWithDelay(function()printf("3.node.customVar=%s,expected=1",tostring(self:getChildByTag(1).customVar))--1localnode2=self:getChildByTag(1)collectgarbage()collectgarbage()printf("4.node.customVar=%s,expected=1",tostring(node2.customVar))--1self:removeChildByTag(1)printf("5.node=%s,expected=nil",tostring(self:getChildByTag(1)))--nilprintf("6.node.customVar=%s,expected=nil",tostring(node2.customVar))--nilend,1.0)getCppFunction--overrideC++classmethodfunctioncc.Node:setPosition(x,y)printf("cc.Node:setPosition(%0.2f,%0.2f)",x,y)--calloriginC++methodlocalcfunction=tolua.getcfunction(cc.Node,"setPosition")cfunction(self,x,y)endlocalnode=display.newNode()self:addChild(node)print("expected'cc.Node:setPosition(100.00,100.00)'")node:setPosition(100,100)--cc.Node:setPosition(100.00,100.00)localx,y=node:getPosition()printf("x,y=%0.2f,%0.2f,expected100.00,100.00",x,y)--restoreC++methodcc.Node.setPosition=tolua.getcfunction(cc.Node,"setPosition")print("expected-nooutput")node:setPosition(100,100)重寫C++類函數(shù),并重新加載函數(shù)。framework.eventlocalitems={"addEventListener","removeEventListener","removeAllListener","removeCoin","sendEvent"}先進(jìn)行初始化,創(chuàng)建node增加圖片Coin0001.png.增加事件監(jiān)聽EventTest1,EventTest2addEventListener為代理事件增加事件監(jiān)聽EventTest3,EventTest4。self.eventProxy:addEventListener("EventTest3",function(event)print("eventlistener3")dump(event)end,"tag3")self.eventProxy:addEventListener("EventTest4",function(event)print("eventlistener4")dump(event)end)removeEventListener移除事件EventTest1,EventTest2,EventTest3.通過三種不同的方法如下:self.eventProxy:removeEventListener(self.eventHandle2)localeventHandle1=self.eventProxy:getEventHandle("EventTest1")self.eventProxy:removeEventListener(eventHandle1)self.eventProxy:removeAllEventListenersForEvent("EventTest3")removeAllListener移除所有監(jiān)聽程序。removeCoin移除coin精靈,當(dāng)coin移除的時候添加的事件監(jiān)聽程序也消失。sendEvent分發(fā)EventTest事件。事件名字EventTest1,EventTest2,EventTest3,EventTerfacelocalitems={"register","modebase","functions"}主要是3個常用接口。Registerlocalregister=require("framework.cc.Registry")localeventProtocol=register.newObject("components.behavior.EventProtocol")--創(chuàng)建一個事件協(xié)議對象。register.setObject(eventProtocol,"cryptoTest1") ifnotregister.isObjectExists("cryptoTest1")then printError("ERRORsomethingwrongpleasecheckRegister") end register.getObject("cryptoTest1") register.removeObject("cryptoTest1") ifregister.isObjectExists("cryptoTest1")then printError("ERRORsomethingwrongpleasecheckRegister") end ifnotregister.exists("components.behavior.EventProtocol")then printError("ERRORsomethingwrongpleasecheckRegister") endModebaselocalmvcBase=require("framework.cc.mvc.ModelBase")functions創(chuàng)建兩個類Animal,Duck.Iskindof函數(shù)用于判斷對象是否屬于指定的類。調(diào)用math相關(guān)函數(shù)等LUA相關(guān)的函數(shù)。framework.socketTcplocalitems={"Connect","SendData","Close"}Init函數(shù)創(chuàng)建一個SocketTCP對象。并添加SocketTCP相關(guān)的事件EVENT_DATAEVENT_CLOSEEVENT_CLOSEDEVENT_CONNECTEDEVENT_CONNECT_FAILUREConnect鏈接。SendData向Socket發(fā)送信息。Close關(guān)閉Socket對象。framework.timer創(chuàng)建一個定時器ifself.timer_thenreturnend localTimer=require("framework.cc.utils.Timer")localappTimer=Timer.new()--響應(yīng)CITYHALL_UPGRADE_TIMER事件localfunctiononCityHallUpgradeTimer(event)ifevent.countdown>0then--倒計(jì)時還未結(jié)束,更新用戶界面上顯示的時間print("timercounting")else--倒計(jì)時已經(jīng)結(jié)束,更新用戶界面顯示升級后的城防大廳print("timerover")endend--注冊事件appTimer:addEventListener("CITYHALL_UPGRADE_TIMER",onCityHallUpgradeTimer)--城防大廳升級需要3600秒,每30秒更新一次界面顯示appTimer:addCountdown("CITYHALL_UPGRADE_TIMER",600,10)appTimer:start()self.timer_=appTimeraddCountdown命令framework.gamestate初始化函數(shù)如下: localstateListener=function(event) ifevent.errorCodethen print("ERROR,load:"..event.errorCode) return end if"load"==then localstr=crypto.decryptXXTEA(event.values.data,"scertKey")localgameData=json.decode(str)dump(gameData,"gameData:") elseif"save"==then localstr=json.encode(event.values)ifstrthenstr=crypto.encryptXXTEA(str,"scertKey")returnValue={data=str}else print("ERROR,encodefail")returnend return{data=str} end end gameState.init(stateListener,"gameState.dat","keyHTL")保存游戲狀態(tài)之用。分別調(diào)用gameState.load()和gameState.save(data)函數(shù)。framework.transition創(chuàng)建10個金幣,分別執(zhí)行不同的動作。創(chuàng)建兩個grossini_blue_,一個運(yùn)行動作一次,另一個永久運(yùn)行。framework.nvgdrawnode--nvgdraw繪畫函數(shù)localquarLB=cc.p(display.cx/2,display.cy/2) localquarRT=cc.p(display.width-quarLB.x,display.height-quarLB.y) localdrawNode1=cc.NVGDrawNode:create() self:addChild(drawNode1) drawNode1:drawPoint(cc.p(display.cx-100,display.cy),cc.c4f(1,0,0,1)) localpoints={} fori=1,10do points[i]=cc.p(display.width/10*i,10) end localdrawNode2=cc.NVGDrawNode:create():addTo(self) drawNode2:drawPoints(points,10,cc.c4f(0,1,0,1))localdrawNode3=cc.NVGDrawNode:create() self:addChild(drawNode3)drawNode3:drawLine(quarLB,quarRT,cc.c4f(0,0,1,1))localdrawNode4=cc.NVGDrawNode:create() self:addChild(drawNode4)drawNode4:drawRect(quarLB,quarRT,cc.c4f(1,1,0,1)) points={} points[1]=cc.p(100,200) points[2]=cc.p(100,100) points[3]=cc.p(200,100) points[4]=cc.p(300,150) localdrawNode5=cc.NVGDrawNode:create() self:addChild(drawNode5)drawNode5:drawPolygon(points,4,true,cc.c4f(0,1,1,1)) localdrawNode6=cc.NVGDrawNode:create() self:addChild(drawNode6) drawNode6:drawCircle(cc.p(display.cx,display.cy),20,cc.c4f(1,0,1,1))localdrawNode7=cc.NVGDrawNode:create() self:addChild(drawNode7)drawNode7:drawQuadBezier(quarLB,cc.p(quarRT.x,quarLB.y),quarRT,cc.c4f(1,1,1,1)) localdrawNode8=cc.NVGDrawNode:create() self:addChild(drawNode8)drawNode8:drawCubicBezier(cc.p(300,400),cc.p(350,500),cc.p(500,300),cc.p(600,400),cc.c4f(0.5,0,0,1))localdrawNode9=cc.NVGDrawNode:create() self:addChild(drawNode9)drawNode9:drawDot(cc.p(display.cx,display.cy),5,cc.c4f(0,0.5,0,1))localdrawNode10=cc.NVGDrawNode:create() self:addChild(drawNode10) drawNode10:setColor(cc.c4f(1,1,1,1))drawNode10:drawSolidRect(cc.p(330,120),cc.p(430,220),cc.c4f(0,0,0.5,1))points={} points[1]=cc.p(500,400) points[2]=cc.p(600,400) points[3]=cc.p(550,500) localdrawNode11=cc.NVGDrawNode:create() self:addChild(drawNode11)drawNode11:drawSolidPolygon(points,3,cc.c4f(0.5,0.5,0,1))localdrawNode12=cc.NVGDrawNode:create() self:addChild(drawNode12) drawNode12:setFill(true) drawNode12:setFillColor(cc.c4f(1,1,1,1))drawNode12:drawArc(cc.p(50,200),50,30,200,1,cc.c4f(0,0.5,0.5,1)) localpoints={} points[1]=cc.p(10,300) points[2]=cc.p(200,320) points[3]=cc.p(180,350) points[4]=cc.p(220,410) localdrawNode13=cc.NVGDrawNode:create() self:addChild(drawNode13)drawNode13:setLineWidth(4)drawNode13:setColor(cc.c4f(0,0.5,0.5,1))drawNode13:drawSolidPolygon(points,4,cc.c4f(0.5,0,0.5,1))相關(guān)函數(shù)device提供設(shè)備相關(guān)屬性的查詢,以及設(shè)備功能的訪問當(dāng)框架初始完成后,device模塊提供下列屬性:device.platform返回當(dāng)前運(yùn)行平臺的名字,可用值:ios,android,mac,windows.device.model返回設(shè)備型號,可用值:unknown,iphone,ipaddevice.language返回設(shè)備當(dāng)前使用的語言,可用值:cn:中文fr:法語it:意大利語gr:德語sp:西班牙語ru:俄語jp:日語en:英語device.writablePath返回設(shè)備上可以寫入數(shù)據(jù)的首選路徑:iOS上返回應(yīng)用程序所在的Documents目錄Android上返回存儲卡的根目錄其他平臺的返回值由quick-x-player決定device.cachePath返回設(shè)備上可以寫入數(shù)據(jù)的緩存目錄:iOS上返回應(yīng)用程序所在的Library/Caches目錄其他平臺的返回值同device.writablePathdevice.directorySeparator目錄分隔符,在Windows平臺上是“\”,其他平臺都是“/”device.pathSeparator路徑分隔符,在Windows平臺上是“;”,其他平臺都是“:”Functionsdevice.showActivityIndicator()顯示活動指示器device.hideActivityIndicator()隱藏正在顯示的活動指示器device.showAlert(title,
message,
buttonLabels,
listener)顯示一個包含按鈕的彈出對話框device.cancelAlert()取消正在顯示的對話框。device.getOpenUDID()返回設(shè)備的OpenUDID值HYPERLINK"/article/index?type=quick_api&url=/doc/api_quick/device.h
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025版市政基礎(chǔ)設(shè)施文明施工與環(huán)境保護(hù)責(zé)任協(xié)議3篇
- 2025年陜西燃?xì)饧瘓F(tuán)工程有限公司招聘筆試參考題庫含答案解析
- 2025年度個人門面房出租合同(含家具配置及經(jīng)營指導(dǎo)協(xié)議)4篇
- 2025年度個人信用卡透支擔(dān)保合同協(xié)議書4篇
- 2025年度個人醫(yī)療健康保險繳費(fèi)協(xié)議書4篇
- 2025年全球及中國智能直播一體機(jī)行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報(bào)告
- 2024年六五環(huán)境日網(wǎng)絡(luò)知識競賽測試題庫及答案
- 設(shè)計(jì)合同協(xié)議書
- 2025年度個人挖機(jī)租賃合同變更通知合同4篇
- 二零二五年度車輛收費(fèi)員薪資待遇及福利協(xié)議材料詳盡條款4篇
- 第1課 隋朝統(tǒng)一與滅亡 課件(26張)2024-2025學(xué)年部編版七年級歷史下冊
- 2025-2030年中國糖醇市場運(yùn)行狀況及投資前景趨勢分析報(bào)告
- 冬日暖陽健康守護(hù)
- 水處理藥劑采購項(xiàng)目技術(shù)方案(技術(shù)方案)
- 2024級高一上期期中測試數(shù)學(xué)試題含答案
- 盾構(gòu)標(biāo)準(zhǔn)化施工手冊
- 天然氣脫硫完整版本
- 山東省2024-2025學(xué)年高三上學(xué)期新高考聯(lián)合質(zhì)量測評10月聯(lián)考英語試題
- 不間斷電源UPS知識培訓(xùn)
- 三年級除法豎式300道題及答案
- 人教版八級物理下冊知識點(diǎn)結(jié)
評論
0/150
提交評論