今天的收获,关于hellolua~

来源:互联网 发布:句解霸软件官方下载 编辑:程序博客网 时间:2024/05/20 19:49

1.首先是引擎加载lua的方法,如果要执行lua脚本,直接复制过来就好了

  1. #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)  
  2.     CCString* pstrFileContent = CCString::createWithContentsOfFile("helloWorld.lua ");  
  3.     if (pstrFileContent)  
  4.     {  
  5.         pEngine->executeString(pstrFileContent->getCString());  
  6.     }  
  7. #else  
  8.     std::string path = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("helloWorld.lua");  
  9.     pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());  
  10.     pEngine->executeScriptFile(path.c_str());  
  11. #endif  

2.然后看一下helloWorld.lua是怎么写的吧

local winsize=CCDirector:sharedDirector():getWinSize();

local function createHelloLayer()
     local layer=CCLayer:create();
    local sprite=CCSrpite:create();
    sprite:setPosition(ccp(winSise.width,winSize.height));
     layer:addChild(sprite);
   return layer;
end


local scene=CCScene:create();
scene:addChild(createHelloLayer());
CCDirector:sharedDirector:runWithScene(scene);


老实说过一遍别人的博客然后再这写,好像不是很好,但是真的能收获很多知识,希望看到的人也可以再学到一点,嘿嘿~

1.一般的变量都要用local xx的形式来写

2.lua的类型由你来设定,你规定是什么就是什么

3.lua中都是:和.没有::

4.不存在->
0 0
原创粉丝点击