cocos2dx lua tableview

cocos2dx lua tableview,第1张

概述  function tableview() local origin = CCEGLView:sharedOpenGLView():getVisibleSize(); local TestLayer = CCLayer:create() local NodeBg=CCNode:create(); NodeBg:setPosition(ccp(10,origin.
function tablevIEw()  local origin = CCEGLVIEw:sharedOpenGLVIEw():getVisibleSize();     local TestLayer = cclayer:create()      local NodeBg=CCNode:create();    NodeBg:setposition(ccp(10,origin.height/8))    local data = {}      for i = 1,10 do table.insert(data,"Data"..i) end  --装入tablevIEw的数据源      local h = LuaEventHandler:create(function(fn,table,a1,a2)      local r      if fn == "cellSize" then          r = CCSizeMake(480,100) --每格的尺寸      elseif fn == "cellAtIndex" then              -- 请求“格”对象,a1是格索引(从0开始),a2是缓存的格对象(可能为空)              -- 在此建立“格”对象并填充其要显示的内容。              if not a2 then                  a2 = CCtableVIEwCell:create()                  -- Build cell struct,just like load ccbi or add sprite                  -- 建立“格”对象的结构,不要在此设定其显示的内容。                  a2:addChild(cclabelTTF:create(""..a1,"Arial",20),1)                  --这里就相当cell容器,可以装入ccbi层、精灵、菜单等控件                  local spriteDemo = CCScale9Sprite:create("80.png");                spriteDemo:setAnchorPoint(ccp(0,0))                  spriteDemo:setContentSize(CCSizeMake(300,100))                a2:addChild(spriteDemo)              end                  -- 修改“格”对象的内容                  tolua.cast(a2:getChildByTag(1),"cclabelTTF"):setString(data[a1 + 1])                  r = a2                  a2:setTag(a1+1);        elseif fn == "numberOfCells" then                      r = #data          -- Cell events:          -- 表格事件:                      elseif fn == "celltouched" then              print("按了:".. a1:getTag())       -- A cell was touched,a1 is cell that be touched. This is not necessary.          elseif fn == "celltouchBegan" then           print("按下".. a1:getTag())      -- A cell is touching,a1 is cell,a2 is CCtouch          elseif fn == "celltouchended" then           print("按完".. a1:getTag())      -- A cell was touched,a2 is CCtouch          elseif fn == "cellHighlight" then           print("高亮的:"..a1:getTag() )       -- A cell is highlighting,coco2d-x 2.1.3 or above          elseif fn == "cellUnhighlight" then           print("不是高亮".. a1:getTag())     -- A cell had been unhighlighted,coco2d-x 2.1.3 or above          elseif fn == "cellWillRecycle" then     -- A cell will be recycled,coco2d-x 2.1.3 or above                  print( a1:getTag() )         end               return r       end)      --创建tablevIEw      local t = LuatableVIEw:createWithHandler(h,CCSizeMake(480,400))      t:setBounceable(true)      --节点定位tablevIEw      NodeBg:addChild(t,1)    TestLayer:addChild(NodeBg)    --  parent:addChild(TestLayer)    return TestLayerend
总结

以上是内存溢出为你收集整理的cocos2dx lua tableview全部内容,希望文章能够帮你解决cocos2dx lua tableview所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1005199.html

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

发表评论

登录后才能评论

评论列表(0条)

保存