zoukankan      html  css  js  c++  java
  • [Lua]基于cc.load('mvc') .ViewBase索引资源方案

    local MainScene = class("MainScene", cc.load("mvc").ViewBase)
    
    MainScene.RESOURCE_FILENAME = "MainScene.csb"
    
    function MainScene:nodeFromPath(path, root)
        root = root or self:getResourceNode()
        assert(root, 'need root node')
        local nn = string.split(path, '.')
    
        local node = root
        for i = 1, #nn do
            node = node:getChildByName(nn[i])
        end
        return node
    end
    
    function MainScene:indexResource(parent, map)
        assert(parent, 'need parent node')
        for key, name in pairs(map) do
            self[key] = parent:getChildByName(name)
        end
        return self
    end
    
    function MainScene:onCreate()
        printf("resource node = %s", tostring(self:getResourceNode()))
        self:indexResource(self:nodeFromPath('ProjectNode_1.BottomBar.Pc_Bg_4'),
        {
            BtnAltar='BtnAltar_4';
            BtnLvl='BtnLvl_6';
            BtnPVP='BtnPVP_8';
            BtnShop='BtnShop_10';
            BtnFrd='BtnFrd_12';
            BtnSetting='BtnSetting_14'
        })
        self.BtnSetting:onTouch(handler(self, self.onSettingClicked))
    end
    
    function MainScene:onSettingClicked(event)
        dump(event, 'onSetting')
    end
    
    return MainScene

    以上基于cocos 示例MainMenu的脚本修改。

  • 相关阅读:
    php环境下所有的配置文件以及作用
    获取登陆用户的ip
    curl模拟post和get请求
    linux 下安装php curl扩展
    php常用面试知识点
    git使用步骤
    laravel框架基础知识点
    ci框架基础知识点
    ajax
    Mysql 中需不需要commit
  • 原文地址:https://www.cnblogs.com/qianwen36/p/5698497.html
Copyright © 2011-2022 走看看