Lua 学习从零开始

来源:互联网 发布:希腊船王 杰奎琳 知乎 编辑:程序博客网 时间:2024/05/21 23:59

今天看见技术群里不少人在谈论Lua脚本语言,于是我有个想法学习Lua!

刚开始呢,什么也不懂。搜了下相关文章,供大家共同学习参考!

另外搜了个Lua语法介绍的文档,该文档在百度文库里也有:http://download.csdn.net/detail/sharkmarine/6209767

以下是相关博文供大家入门参考:

红孩儿的HelloLua的深入分析:http://www.oschina.net/question/565065_101785

Himi的Lua开发:http://www.himigame.com/category/lua-game

笨木头的博客:http://blog.csdn.net/musicvs/article/category/1313448

高姓少年的博客:http://blog.csdn.net/odustggg/article/details/8195137

我现在开始的Lua项目是把我以前游戏的一部分用Lua写出来,有点艰辛,大家慢慢等,毕竟每天学习Lua的时间是有限的\~O..O~/

1、至于在C++中调用lua文件和在lua文件中调用C++函数的方法,麻烦大家还是看看楼上的博文吧~

2、在Lua文件中调用schedule 函数的方法

scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused)
第一个参数是你要注册的回调函数,第二个是执行该函数循环的秒数,第三个参数是是否暂停。

function zhayan_func()       print("I Love You")endCCDirector:sharedDirector():getScheduler():scheduleScriptFunc(zhayan_func,2.5,false)

3、动画的实现

-- 先使用CCTextureCache:sharedTextureCache()取得纹理块管理器,将dog.png放入纹理块管理器产生一张纹理返回给变量textureDoglocal textureDog = CCTextureCache:sharedTextureCache():addImage("dog.png")--创建一个矩形返回给变量rect local rect = CCRectMake(0, 0, frameWidth, frameHeight)--由这个矩形从纹理上取出图块产生一个CCSpriteFrame指针返回给变量frame0local frame0 = CCSpriteFrame:frameWithTexture(textureDog, rect)--换一个新的位置的矩形返回给变量rect中rect = CCRectMake(frameWidth, 0, frameWidth, frameHeight)--由第二个矩形从纹理上取出图块产生一个CCSpriteFrame指针返回给变量frame1local frame1 = CCSpriteFrame:frameWithTexture(textureDog, rect)    --从frame0产生一个精灵返回给变量spriteDog(在C++中是CCSprite指针)local spriteDog = CCSprite:spriteWithSpriteFrame(frame0)--设置初始化时spriteDog.isPaused = false--设置精灵的位置在左上的位置    spriteDog:setPosition(0, winSize.height / 4 * 3)    --生成一个设定大小为2的CCMutableArray类的实例对象。用来存储CCSpriteFrame指针,将其指针返回给变量animFrameslocal animFrames = CCMutableArray_CCSpriteFrame__:new(2)--调用addObject将frame0和frame1放入animFrames    animFrames:addObject(frame0)    animFrames:addObject(frame1)    --由容器类实例对象的指针animFrames创建一个动画帧信息对象,设定每0.5秒更新一帧,返回动画帧信息对象指针给变量animationlocal animation = CCAnimation:animationWithFrames(animFrames, 0.5)--由animation创建出一个动画动作,将这个动画动作的指针给变量animatelocal animate = CCAnimate:actionWithAnimation(animation, false);--设置精灵循环运行这个动作    spriteDog:runAction(CCRepeatForever:actionWithAction(animate))




原创粉丝点击