houmee实习日记4.20-22

本文详细介绍了在Cocos2d-x中使用Lua进行UI控件操作的方法,包括通过Name或Tag查找控件,以及如何利用getChildByName和getChildByTag函数实现控件交互。此外,还提供了滑动条跟随listview滑动效果的实现代码,为开发者提供实用的技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考模块与包:

http://www.jellythink.com/archives/526

字符串函数:

http://www.jellythink.com/archives/544 

  1. find

  2. match

  3. gsub

  4. gmatch

cocos studio

http://cn.cocos2d-x.org/tutorial/show?id=502

http://cn.cocos2d-x.org/tutorial/lists?id=39

 

简单说说Lua中的面向对象

http://www.jellythink.com/archives/529

 

 

Mac下使用Cocos2d-x Lua 3.2加载Cocos Studio 1.0beta导出的Json

http://cn.cocos2d-x.org/tutorial/show?id=1408

 linux shell:------------>

http://www.jellythink.com/archives/699

------------cocos2d-x的lua脚本如何获得Cocostudio中UI控件的对象----------------------

如何获取UI上的控件呢?答案是通过Name或Tag查找,使用函数getChildByName() 或 getChildByTag()。
以Button为例,代码如下:
    local function createCocostudioUI()
        local ccsLayout = ccs.GUIReader:shareReader():widgetFromJsonFile("DemoLogin/DemoLogin.json")
        --local ccsButton = ccsLayout:getChildByName("login_Button")
        local ccsButton = ccsLayout:getChildByTag(14)
        ccsButton:addTouchEventListener(function(...)
          ccsLayout:setVisible(false)
          end)
        return ccsLayout
    end

--------------初始的UI加入进来吧---------------------

----初始化基类界面----
function RankingListCtl:InitConsRoot(...)
    self.root = GUIReader:shareReader():widgetFromJsonFile(gRes_CSUIPath.."/RankingList.json") 
end

--------------------GUI系统-------------------------

http://cn.cocos2d-x.org/article/index?type=wiki&url=/doc/cocos-docs-master/manual/framework/native/wiki/containers/zh.md

--------------滑动条跟随listview的滑动效果--------------

local Panel_2 = tolua.cast(UIHelper:seekWidgetByName(self.root,"Panel_2"),"Panel") --容器
     local ListView_right = tolua.cast(UIHelper:seekWidgetByName(self.root,"ListView_right"),"ListView") --列表容器、
     -- local Slider_right = tolua.cast( UIHelper:seekWidgetByName( self.root, "Slider_right" ) , "Slider") --右边滑动条
        self.initHandlerSilder = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc( function (  )
  CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry( self.initHandlerSilder )
  gUtils:SetupScrollIndicator( ListView_right, tolua.cast( UIHelper:seekWidgetByName( self.root , "Slider_right" ) , "Slider") )
 end, 0, false )

--------

转载于:https://my.oschina.net/u/1862653/blog/404053

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值