`
runfeel
  • 浏览: 906792 次
文章分类
社区版块
存档分类
最新评论

【cocos2dx开发技巧5】脚本lua的使用--代码集锦

 
阅读更多

仿照“我叫MT”的控件

代码如下:

	local function createBanner()
		local layerFarm = CCNode:create()

		local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
		cache:addSpriteFramesWithFile("pic.plist")
		local spritebatch = CCSpriteBatchNode:create("pic.png")
		layerFarm:addChild(spritebatch)

		local bg = CCSprite:createWithSpriteFrameName("bg.png")
		spritebatch:addChild(bg)

		cclog("The size of bg is: %0.2f, %0.2f", bg:getContentSize().width, bg:getContentSize().height)

		local px = bg:getContentSize().width / 2;
		local py = bg:getContentSize().height /2;

		local head01 = CCSprite:createWithSpriteFrameName("head01.png")
		spritebatch:addChild(head01)
		head01:setAnchorPoint(ccp(0, 0.5));
		head01:setPosition(-px, 0);

		local lv = CCSprite:createWithSpriteFrameName("lv.png")
		spritebatch:addChild(lv);
		lv:setPosition(-px + 10, -py + 10);
		lv:setAnchorPoint(ccp(0, 0));

		local name = CCLabelTTF:create("yyyy", "Arial", 24)
		layerFarm:addChild(name);
		name:setAnchorPoint(ccp(0, 0));
		name:setPosition(-135, 5);

		local hp = CCLabelTTF:create("7569", "Arial", 24)
		layerFarm:addChild( hp);
		hp:setAnchorPoint(ccp(0, 0));
		hp:setPosition(-140, -35);

		local zhandou = CCLabelTTF:create("2334", "Arial", 24)
		layerFarm:addChild( zhandou);
		zhandou:setAnchorPoint(ccp(0, 0));
		zhandou:setPosition(-25, -35);

		return layerFarm;
	end


	local function createLayerFarm()
		local layerFarm = createBanner()

		layerFarm:setScale(0.8);
		layerFarm:setPosition(origin.x + visibleSize.width / 2 , origin.y + visibleSize.height / 2)

		return layerFarm;
	end


按钮控件

	local function createBtn(name, callback)
		local pMainBtn = CCMenuItemSprite:create(
										CCSprite:createWithSpriteFrameName("d_"..name..".png"),
                                        CCSprite:createWithSpriteFrameName("d_"..name.."_s.png"), 
                                        CCSprite:createWithSpriteFrameName("d_"..name.."_s.png"));
        pMainBtn:registerScriptTapHandler(callback)
        pMainBtn:setAnchorPoint(ccp(0, 0))
        return pMainBtn;
	end

	local function createButtoms()
		local node = CCNode:create();
		local cache = CCSpriteFrameCache:sharedSpriteFrameCache()
		cache:addSpriteFramesWithFile("images/gTopper.plist", "images/gTopper.png");
		
		local function cbHome()
			cclog("home")
		end
		local function cbFuben()
			cclog("cbFuben")
		end
		local function cbZhandou()
			cclog("cbZhandou")
		end
		local function cbStore()
			cclog("cbStore")
		end
		local function cbFriends()
			cclog("cbFriends")
		end
		local function cbGonglve()
			cclog("cbGonglve")
		end
		
		local bHome = createBtn("home", cbHome);
		local bFuben = createBtn("fuben", cbFuben);
		local bZhandou = createBtn("zhandou", cbZhandou);
		local bStore = createBtn("store", cbStore);
		local bFriends = createBtn("friends", cbFriends);
		local bGonglve = createBtn("gonglve", cbGonglve);
                 
		local  menu = CCMenu:create()

        menu:addChild(bHome)
        menu:addChild(bFuben)
        menu:addChild(bZhandou)
        menu:addChild(bStore)
        menu:addChild(bFriends)
        menu:addChild(bGonglve)
        
       	local size = bHome:getContentSize().width;
       	local gap = 8
       	bHome:setPosition(-3*(size + gap), 0)
       	bFuben:setPosition(-2*(size + gap), 0)
       	bZhandou:setPosition(-1*(size + gap), 0)
       	bStore:setPosition(0*(size + gap), 0)
       	bFriends:setPosition(1*(size + gap), 0)
       	bGonglve:setPosition(2*(size + gap), 0)
        
		menu:setPosition( 0, origin.y + visibleSize.height / 2)
		node:addChild(menu)
		
		return node
	end


toluafix, CCNode::registerScriptHandler, toluafix_isfunction

分享到:
评论

相关推荐

    vscode-coco2dx-lua-api.7z

    用vsdoe开发cocos2dx-lua的辅助文件,用于代码提示,提高代码效率。一并提交了制作脚本。 cocos2dx-lua,vscode代码提示文件,附带制作脚本

    cocos2dx-lua在vs2015上的调试插件

    cocos2dx lua debug的插件,可以断点lua,看堆栈信息,单步调试lua。 解压后,先安装BabeLua For 2015 V3.2.2.0.vsix,再安装babelua-compat-1.06-VS2015

    cocos2dx登陆模块客户端lua脚本

    cocos2dx上面的登陆系统lua实现

    quick-cocos2d-x3.3 lua开发曹操传源码

    quick-cocos2d-x3.3 lua开发曹操传源码,可编译通过 引擎版本:Cocos2dx-lua 3.3 语言:纯lua实现,逻辑代码大约2W多行,剧情脚本+数据大约7W多行(采用脚本进行转换的)

    cocos2dx-csd转lua py脚本文件.rar

    软件介绍: cocos 的cocostudio工程文件,Csd_Lua.py是cocos2dx- csd转成对应lua的脚本文件。用得到的同学可以试试。

    cocos2dx lua绑定

    cocos2dx lua绑定,基于tolua++、Python工具实现cococs2dx环境下的lua脚本绑定。

    cocos2d-js/lua游戏【解密】套件

    1. android砸壳 2. 文件解密 2.1. 新版jsc解密 2.2. lua文件自动解密脚本 3. 抓包软件mac&wind 4. 数据报文解密脚本 5. 安卓hook工具包

    cocos2d-x 3.x lua 热更新列表版本解决方案

    cocos2d-x 3.x lua 热更新列表版本解决方案,使用官方assetsManager 在lua脚本端完成,通过版本列表的方式进行迭代更新。

    cocos2dx lua脚本编译工具

    cd 到目录运行script_compile.bat,复制lua代码路径。回车生成编译后的lua文件在out目录。可以直接被cocos2dx 加载运行

    关于手动绑定cocos2dx-lua C++接口详细教程

    该文档详细说明了如何自定cocos2dx-lua(quick) C++接口并导出接口供lua端调用,从环境配置,文件编译,接口测试,平台(Android和Ios)编译一步一步进行详细说明,按照文档一步步操作就能生成你想要的C++接口,简单...

    lua2js4cocos:lua将cocos2d-js转换为javascript

    lua2js4cocos lua转换为cocos的javascript cocos2dx-lua到cocos2dx-js 将lua文件放入输入中运行lua2js.py脚本,该js文件将在输出中生成。

    cocos2d实现slider滑块效果

    哎,真的非常遗憾,我一个人完成游戏的编辑器开发,脚本开发,游戏代码开发,很不容易,因为我学object-c,coco2d才看了2个星期的书就直接开发了,以前是搞c++的吗。感觉4个人开发游戏真的很累,游戏为了脱颖出更加...

    Cocos2D-X游戏开发技术精解.pdf

    《Cocos2D-X游戏开发技术精解》详细介绍如何使用Cocos2D-X引擎开发自己的移动平台游戏。全书共15章,主要内容包括:Cocos2D-X引擎简介;如何建立跨平台的开发环境;引擎的核心模块——渲染框架;如何实现动态画面和...

    cocos2d实现RollNunber(数字滚动效果)

    哎,真的非常遗憾,我一个人完成游戏的编辑器开发,脚本开发,游戏代码开发,很不容易,因为我学object-c,coco2d才看了2个星期的书就直接开发了,以前是搞c++的吗。感觉4个人开发游戏真的很累,游戏为了脱颖出更加...

    使用BabeLua调试Cocos2d-x的Lua脚本

    使用BabeLua调试

    【Cocos2dx-lua 3.11.1】打包lua项目为安卓apk-附件资源

    【Cocos2dx-lua 3.11.1】打包lua项目为安卓apk-附件资源

    lua utf8 unicode ansi 转换

    require "lc" print(lc.help());... u2w(utf8 to unicode) w2a(unicode to ansi) w2u(unicode to utf8) u2a(utf8 to ansi) a2u(ansi to utf8) bstr(bytes of str) help(show this) wunoman@qq.com 2012/03/06

    cocos2dx-csd转lua

    cocos 的cocostudio工程文件 csd转成对应的lua脚本,控件_区分

    CocosLua:swift工程调用Cocos2dx-lua工程配置;

    手把手教你swift项目添加cocos2dx-lua标签(空格分隔): iOS本文所用各版本信息:Xcode9.2 + swift4版本cocos2d-x v3.17集成思路首先网上给出一个C系的思路,本人未亲测,并且以C调用lua,绕过了cocos2d-x的调用...

Global site tag (gtag.js) - Google Analytics