Cocos2d-x 3.1.1 lua-tests开篇
  本篇博客打算从研究Cocos2d-x引擎提供的測试样例来写起,笔者针对Cocos2d-x 3.1.1这个版本号来介绍怎样来学习它给我们提供的样例,通过这些样例来深入学习Cocos2d-x核心API的使用。在学习过程中,笔者相同跟非常多刚開始学习的人一样有非常多疑惑,为了能帮助到很多其它刚開始学习的人,笔者会提出自己的疑惑然后进行解决,笔者会把每个样例都进行具体说明,对相关代码进行凝视,那么以后刚開始学习的人就能够对比笔者的博客来学习Cocos2d-x的使用,我想会事半功倍的。对笔者来说,什么版本号并不重要,重要的是学习的思路,接下来的系列博客就是笔者学习Cocos2d-x的思路。
  怎样開始呢?
  自然先到Cocos2d-x官网下载对应版本号的引擎,笔者这里是Cocos2d-x 3.1.1
  下载完毕后,希望童鞋们自己试着去搭建好开发环境,网络和笔者前面的博客均有介绍,笔者在这里就不多说了。
  最好要在win32平台、Android平台都执行成功过HelloWorld,有了这个基础之后,就能够找样例学习了。
 Cocos2d-x 3.1.1样例的代码在cocos2d-x-3.1.1\tests下:
 
这里就有我们的C++代码和Lua代码,我们要学习的是Lua项目,怎么执行这些项目呢,看下图:
双击使用Visual Studio打开,笔者这里是2012的。
  
右键设置lua-tests为启动项目,然后进行编译执行,成功之后的效果例如以下:
从这些样例,我们能够了解到Cocos2d-x全部相关API所能实现的基础效果,笔者觉得没有不论什么学习资料能比得上这些样例了。
怎么查看实现以上效果的Lua代码呢,以下笔者会给大家介绍。
笔者用到的一个开发工具是LDT,童鞋们能够到这里下载:http://www.eclipse.org/koneki/ldt/
打开LDT,切换工作空间到我们的lua-tests项目中,例如以下:
然后新建Lua项目,取名为src,这样我们就能够把当前文件夹下src全部的Lua代码都包括进来了:
这样我们就能够非常方便查看每个样例的Lua代码,查看它的具体实现。
我们的Lua项目的入口在哪里呢?
打开win32项目,找到AppDelegate.cpp,打开查看:
  1. #include "cocos2d.h"
  2. #include "AppDelegate.h"
  3. #include "CCLuaEngine.h"
  4. #include "audio/include/SimpleAudioEngine.h"
  5. #include "lua_assetsmanager_test_sample.h"
  6.  
  7. using namespace CocosDenshion;
  8.  
  9. USING_NS_CC;
  10.  
  11. AppDelegate::AppDelegate()
  12. {
  13. }
  14.  
  15. AppDelegate::~AppDelegate()
  16. {
  17. SimpleAudioEngine::end();
  18. }
  19.  
  20. bool AppDelegate::applicationDidFinishLaunching()
  21. {
  22. // 获得导演类实例
  23. auto director = Director::getInstance();
  24. // 获取渲染全部东西的 EGLView NA NA
  25. auto glview = director->getOpenGLView();
  26. if(!glview) {
  27. glview = GLView::createWithRect("Lua Tests", Rect(0,0,900,640));
  28. director->setOpenGLView(glview);
  29. }
  30.  
  31. // turn on display FPS
  32. // 打开显示帧屏
  33. director->setDisplayStats(true);
  34.  
  35. // set FPS. the default value is 1.0/60 if you don't call this
  36. // 设置游戏画面每秒显示的帧数,默认是60帧。
  37. director->setAnimationInterval(1.0 / 60);
  38.  
  39. // 获得屏幕大小
  40. auto screenSize = glview->getFrameSize();
  41.  
  42. // 获得设计大小
  43. auto designSize = Size(480, 320);
  44.  
  45. if (screenSize.height > 320)
  46. {
  47. auto resourceSize = Size(960, 640);
  48. director->setContentScaleFactor(resourceSize.height/designSize.height);
  49. }
  50.  
  51. // 设置屏幕设计分辨率
  52. glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
  53.  
  54. // register lua engine
  55. LuaEngine* pEngine = LuaEngine::getInstance();
  56. ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
  57.  
  58. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
  59. LuaStack* stack = pEngine->getLuaStack();
  60. register_assetsmanager_test_sample(stack->getLuaState());
  61. #endif
  62. // 执行脚本语言
  63. pEngine->executeScriptFile("src/controller.lua");
  64.  
  65. return true;
  66. }
  67.  
  68. // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
  69. void AppDelegate::applicationDidEnterBackground()
  70. {
  71. Director::getInstance()->stopAnimation();
  72.  
  73. SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
  74. }
  75.  
  76. // this function will be called when the app is active again
  77. void AppDelegate::applicationWillEnterForeground()
  78. {
  79. Director::getInstance()->startAnimation();
  80.  
  81. SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
  82. }

我们会发现代码中这么一段:

pEngine->executeScriptFile("src/controller.lua");
这个就是我们的入口文件,我们执行Lua的代码是从controller.lua这个文件開始的。
我们用LDT查看一下它的代码:
  1. -- avoid memory leak
  2. -- 避免内存泄漏
  3. collectgarbage("setpause", 100)
  4. collectgarbage("setstepmul", 5000)
  5.  
  6. require "src/mainMenu"
  7. ----------------
  8.  
  9. -- run
  10.  
  11. local glView = cc.Director:getInstance():getOpenGLView()
  12. local screenSize = glView:getFrameSize()
  13. local designSize = {width = 480, height = 320}
  14. local fileUtils = cc.FileUtils:getInstance()
  15.  
  16. if screenSize.height > 320 then
  17. local searchPaths = {}
  18. table.insert(searchPaths, "hd")
  19. fileUtils:setSearchPaths(searchPaths)
  20. end
  21.  
  22. local targetPlatform = cc.Application:getInstance():getTargetPlatform()
  23. local resPrefix = ""
  24. if cc.PLATFORM_OS_IPAD == targetPlatform or cc.PLATFORM_OS_IPHONE == targetPlatform or cc.PLATFORM_OS_MAC == targetPlatform then
  25. resPrefix = ""
  26. else
  27. resPrefix = "res/"
  28. end
  29.  
  30. local searchPaths = fileUtils:getSearchPaths()
  31. table.insert(searchPaths, 1, resPrefix)
  32. table.insert(searchPaths, 1, resPrefix .. "cocosbuilderRes")
  33.  
  34. if screenSize.height > 320 then
  35. table.insert(searchPaths, 1, resPrefix .. "hd")
  36. table.insert(searchPaths, 1, resPrefix .. "ccs-res")
  37. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd")
  38. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/Images")
  39. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/ArmatureComponentTest")
  40. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/AttributeComponentTest")
  41. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/BackgroundComponentTest")
  42. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/EffectComponentTest")
  43. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/LoadSceneEdtiorFileTest")
  44. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/ParticleComponentTest")
  45. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/SpriteComponentTest")
  46. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/TmxMapComponentTest")
  47. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/UIComponentTest")
  48. table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/TriggerTest")
  49. else
  50. table.insert(searchPaths, 1, resPrefix .. "ccs-res/Images")
  51. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/ArmatureComponentTest")
  52. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/AttributeComponentTest")
  53. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/BackgroundComponentTest")
  54. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/EffectComponentTest")
  55. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/LoadSceneEdtiorFileTest")
  56. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/ParticleComponentTest")
  57. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/SpriteComponentTest")
  58. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/TmxMapComponentTest")
  59. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/UIComponentTest")
  60. table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/TriggerTest")
  61. end
  62.  
  63. fileUtils:setSearchPaths(searchPaths)
  64.  
  65. -- 创建场景
  66. local scene = cc.Scene:create()
  67. -- 加入菜单
  68. scene:addChild(CreateTestMenu())
  69. if cc.Director:getInstance():getRunningScene() then
  70. cc.Director:getInstance():replaceScene(scene)
  71. else
  72. -- 依据给定的场景进入 Director的主循环 仅仅能调用他执行你的第一个场景.
  73. cc.Director:getInstance():runWithScene(scene)
  74. end

然后我们就能够依据这个,来理清整个測试项目的脉路,我们或许想知道,样例中的那些菜单是怎么显示出来的,样例中又是怎样进行切换场景的。仅仅要我们知道怎样開始了,以后我们就能够慢慢分析每个样例所给我提供的代码。

在controller.lua文件里引入了maniMenu.lua
通过这个语句:require "src/mainMenu"
我们来看看mainMenu的代码:
  1. -- 引入资源文件
  2. require "Cocos2d"
  3. require "Cocos2dConstants"
  4. require "Opengl"
  5. require "OpenglConstants"
  6. require "StudioConstants"
  7. require "GuiConstants"
  8. require "src/helper"
  9. require "src/testResource"
  10. require "src/VisibleRect"
  11.  
  12. require "src/AccelerometerTest/AccelerometerTest"
  13. require "src/ActionManagerTest/ActionManagerTest"
  14. require "src/ActionsEaseTest/ActionsEaseTest"
  15. require "src/ActionsProgressTest/ActionsProgressTest"
  16. require "src/ActionsTest/ActionsTest"
  17. require "src/AssetsManagerTest/AssetsManagerTest"
  18. require "src/BugsTest/BugsTest"
  19. require "src/ClickAndMoveTest/ClickAndMoveTest"
  20. require "src/CocosDenshionTest/CocosDenshionTest"
  21. require "src/CocoStudioTest/CocoStudioTest"
  22. require "src/CurrentLanguageTest/CurrentLanguageTest"
  23. require "src/DrawPrimitivesTest/DrawPrimitivesTest"
  24. require "src/EffectsTest/EffectsTest"
  25. require "src/EffectsAdvancedTest/EffectsAdvancedTest"
  26. require "src/ExtensionTest/ExtensionTest"
  27. require "src/FontTest/FontTest"
  28. require "src/IntervalTest/IntervalTest"
  29. require "src/KeypadTest/KeypadTest"
  30. require "src/LabelTest/LabelTest"
  31. require "src/LabelTestNew/LabelTestNew"
  32. require "src/LayerTest/LayerTest"
  33. require "src/MenuTest/MenuTest"
  34. require "src/MotionStreakTest/MotionStreakTest"
  35. require "src/NewEventDispatcherTest/NewEventDispatcherTest"
  36. require "src/NodeTest/NodeTest"
  37. require "src/OpenGLTest/OpenGLTest"
  38. require "src/ParallaxTest/ParallaxTest"
  39. require "src/ParticleTest/ParticleTest"
  40. require "src/PerformanceTest/PerformanceTest"
  41. require "src/RenderTextureTest/RenderTextureTest"
  42. require "src/RotateWorldTest/RotateWorldTest"
  43. require "src/Sprite3DTest/Sprite3DTest"
  44. require "src/SpriteTest/SpriteTest"
  45. require "src/SceneTest/SceneTest"
  46. require "src/SpineTest/SpineTest"
  47. require "src/Texture2dTest/Texture2dTest"
  48. require "src/TileMapTest/TileMapTest"
  49. require "src/TouchesTest/TouchesTest"
  50. require "src/TransitionsTest/TransitionsTest"
  51. require "src/UserDefaultTest/UserDefaultTest"
  52. require "src/ZwoptexTest/ZwoptexTest"
  53. require "src/LuaBridgeTest/LuaBridgeTest"
  54. require "src/XMLHttpRequestTest/XMLHttpRequestTest"
  55. require "src/PhysicsTest/PhysicsTest"
  56.  
  57. -- 行间距
  58. local LINE_SPACE = 40
  59.  
  60. -- 当前位置
  61. local CurPos = {x = 0, y = 0}
  62. -- 開始位置
  63. local BeginPos = {x = 0, y = 0}
  64.  
  65. -- 定义一张表
  66. local _allTests = {
  67. { isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain },
  68. { isSupported = true, name = "ActionManagerTest" , create_func = ActionManagerTestMain },
  69. { isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
  70. { isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
  71. { isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
  72. { isSupported = true, name = "AssetsManagerTest" , create_func = AssetsManagerTestMain },
  73. { isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain },
  74. { isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain },
  75. { isSupported = true, name = "BugsTest" , create_func= BugsTestMain },
  76. { isSupported = false, name = "ChipmunkAccelTouchTest" , create_func= ChipmunkAccelTouchTestMain },
  77. { isSupported = true, name = "ClickAndMoveTest" , create_func = ClickAndMoveTest },
  78. { isSupported = true, name = "CocosDenshionTest" , create_func = CocosDenshionTestMain },
  79. { isSupported = true, name = "CocoStudioTest" , create_func = CocoStudioTestMain },
  80. { isSupported = false, name = "CurlTest" , create_func= CurlTestMain },
  81. { isSupported = true, name = "CurrentLanguageTest" , create_func= CurrentLanguageTestMain },
  82. { isSupported = true, name = "DrawPrimitivesTest" , create_func= DrawPrimitivesTest },
  83. { isSupported = true, name = "EffectsTest" , create_func = EffectsTest },
  84. { isSupported = true, name = "EffectAdvancedTest" , create_func = EffectAdvancedTestMain },
  85. { isSupported = true, name = "ExtensionsTest" , create_func= ExtensionsTestMain },
  86. { isSupported = true, name = "FontTest" , create_func = FontTestMain },
  87. { isSupported = true, name = "IntervalTest" , create_func = IntervalTestMain },
  88. { isSupported = true, name = "KeypadTest" , create_func= KeypadTestMain },
  89. { isSupported = true, name = "LabelTest" , create_func = LabelTest },
  90. { isSupported = true, name = "LabelTestNew" , create_func = LabelTestNew },
  91. { isSupported = true, name = "LayerTest" , create_func = LayerTestMain },
  92. { isSupported = true, name = "LuaBridgeTest" , create_func = LuaBridgeMainTest },
  93. { isSupported = true, name = "MenuTest" , create_func = MenuTestMain },
  94. { isSupported = true, name = "MotionStreakTest" , create_func = MotionStreakTest },
  95. { isSupported = false, name = "MutiTouchTest" , create_func= MutiTouchTestMain },
  96. { isSupported = true, name = "NewEventDispatcherTest" , create_func = NewEventDispatcherTest },
  97. { isSupported = true, name = "NodeTest" , create_func = CocosNodeTest },
  98. { isSupported = true, name = "OpenGLTest" , create_func= OpenGLTestMain },
  99. { isSupported = true, name = "ParallaxTest" , create_func = ParallaxTestMain },
  100. { isSupported = true, name = "ParticleTest" , create_func = ParticleTest },
  101. { isSupported = true, name = "PerformanceTest" , create_func= PerformanceTestMain },
  102. { isSupported = true, name = "PhysicsTest" , create_func = PhysicsTest },
  103. { isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
  104. { isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest },
  105. { isSupported = true, name = "SceneTest" , create_func = SceneTestMain },
  106. { isSupported = true, name = "SpineTest" , create_func = SpineTestMain },
  107. { isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain },
  108. { isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain },
  109. { isSupported = true, name = "Sprite3DTest" , create_func = Sprite3DTest },
  110. { isSupported = true, name = "SpriteTest" , create_func = SpriteTest },
  111. { isSupported = false, name = "TextInputTest" , create_func= TextInputTestMain },
  112. { isSupported = true, name = "Texture2DTest" , create_func = Texture2dTestMain },
  113. { isSupported = false, name = "TextureCacheTest" , create_func= TextureCacheTestMain },
  114. { isSupported = true, name = "TileMapTest" , create_func = TileMapTestMain },
  115. { isSupported = true, name = "TouchesTest" , create_func = TouchesTest },
  116. { isSupported = true, name = "TransitionsTest" , create_func = TransitionsTest },
  117. { isSupported = true, name = "UserDefaultTest" , create_func= UserDefaultTestMain },
  118. { isSupported = true, name = "XMLHttpRequestTest" , create_func = XMLHttpRequestTestMain },
  119. { isSupported = true, name = "ZwoptexTest" , create_func = ZwoptexTestMain }
  120. }
  121.  
  122. local TESTS_COUNT = table.getn(_allTests)
  123.  
  124. -- create scene 创建场景
  125. local function CreateTestScene(nIdx)
  126. cc.Director:getInstance():purgeCachedData()
  127. local scene = _allTests[nIdx].create_func()
  128. return scene
  129. end
  130. -- create menu 创建菜单
  131. function CreateTestMenu()
  132. -- 菜单层
  133. local menuLayer = cc.Layer:create()
  134.  
  135. local function closeCallback()
  136. -- 结束执行,释放正在执行的场景。
  137. cc.Director:getInstance():endToLua()
  138. end
  139.  
  140. -- 菜单回调
  141. local function menuCallback(tag)
  142. print(tag)
  143. local Idx = tag - 10000
  144. local testScene = CreateTestScene(Idx)
  145. if testScene then
  146. -- 切换场景
  147. cc.Director:getInstance():replaceScene(testScene)
  148. end
  149. end
  150.  
  151. -- add close menu 加入关闭菜单
  152. local s = cc.Director:getInstance():getWinSize()
  153. local CloseItem = cc.MenuItemImage:create(s_pPathClose, s_pPathClose)
  154. CloseItem:registerScriptTapHandler(closeCallback)
  155. CloseItem:setPosition(cc.p(s.width - 30, s.height - 30))
  156.  
  157. local CloseMenu = cc.Menu:create()
  158. CloseMenu:setPosition(0, 0)
  159. CloseMenu:addChild(CloseItem)
  160. menuLayer:addChild(CloseMenu)
  161. -- 获取目标平台
  162. local targetPlatform = cc.Application:getInstance():getTargetPlatform()
  163. if (cc.PLATFORM_OS_IPHONE == targetPlatform) or (cc.PLATFORM_OS_IPAD == targetPlatform) then
  164. CloseMenu:setVisible(false)
  165. end
  166.  
  167. -- add menu items for tests
  168. -- 加入菜单项
  169. local MainMenu = cc.Menu:create()
  170. local index = 0
  171. local obj = nil
  172. for index, obj in pairs(_allTests) do
  173. -- 创建文本(obj.name 为文本名称, s_arialPath为字体,24为字体大小)
  174. local testLabel = cc.Label:createWithTTF(obj.name, s_arialPath, 24)
  175. -- 设置锚点
  176. testLabel:setAnchorPoint(cc.p(0.5, 0.5))
  177. -- 创建菜单项标签
  178. local testMenuItem = cc.MenuItemLabel:create(testLabel)
  179. -- 假设此项不支持,则设置菜单项不可用
  180. if not obj.isSupported then
  181. testMenuItem:setEnabled(false)
  182. end
  183. -- 注冊脚本处理句柄
  184. testMenuItem:registerScriptTapHandler(menuCallback)
  185. -- 设置菜单标签显示的位置,设置到居中的位置
  186. testMenuItem:setPosition(cc.p(s.width / 2, (s.height - (index) * LINE_SPACE)))
  187. -- 加入菜单项到菜单中去
  188. MainMenu:addChild(testMenuItem, index + 10000, index + 10000)
  189. end
  190.  
  191. -- 设置菜单内容大小
  192. MainMenu:setContentSize(cc.size(s.width, (TESTS_COUNT + 1) * (LINE_SPACE)))
  193. MainMenu:setPosition(CurPos.x, CurPos.y)
  194. -- 将菜单加入到层中去
  195. menuLayer:addChild(MainMenu)
  196.  
  197. -- handling touch events
  198. -- 处理触摸事件
  199. local function onTouchBegan(touch, event)
  200. -- 获取触摸点的位置
  201. BeginPos = touch:getLocation()
  202. -- CCTOUCHBEGAN event must return true
  203. return true
  204. end
  205.  
  206. -- 手指移动时触发
  207. local function onTouchMoved(touch, event)
  208. local location = touch:getLocation()
  209. local nMoveY = location.y - BeginPos.y
  210. local curPosx, curPosy = MainMenu:getPosition()
  211. local nextPosy = curPosy + nMoveY
  212. local winSize = cc.Director:getInstance():getWinSize()
  213. if nextPosy < 0 then
  214. MainMenu:setPosition(0, 0)
  215. return
  216. end
  217.  
  218. if nextPosy > ((TESTS_COUNT + 1) * LINE_SPACE - winSize.height) then
  219. MainMenu:setPosition(0, ((TESTS_COUNT + 1) * LINE_SPACE - winSize.height))
  220. return
  221. end
  222.  
  223. --
  224. MainMenu:setPosition(curPosx, nextPosy)
  225. BeginPos = {x = location.x, y = location.y}
  226. CurPos = {x = curPosx, y = nextPosy}
  227. end
  228.  
  229. -- 创建事件监听器
  230. local listener = cc.EventListenerTouchOneByOne:create()
  231. -- 注冊事件监听
  232. listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
  233. listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
  234. -- 获取事件派发器
  235. local eventDispatcher = menuLayer:getEventDispatcher()
  236. eventDispatcher:addEventListenerWithSceneGraphPriority(listener, menuLayer)
  237.  
  238. return menuLayer
  239. end

我们就能够发现,这里就是界面中菜单的实现,mainMenu中还引入了其它文件,比方testResource.lua

  1. s_pPathGrossini = "Images/grossini.png"
  2. s_pPathSister1 = "Images/grossinis_sister1.png"
  3. s_pPathSister2 = "Images/grossinis_sister2.png"
  4. s_pPathB1 = "Images/b1.png"
  5. s_pPathB2 = "Images/b2.png"
  6. s_pPathR1 = "Images/r1.png"
  7. s_pPathR2 = "Images/r2.png"
  8. s_pPathF1 = "Images/f1.png"
  9. s_pPathF2 = "Images/f2.png"
  10. s_pPathBlock = "Images/blocks.png"
  11. s_back = "Images/background.png"
  12. s_back1 = "Images/background1.png"
  13. s_back2 = "Images/background2.png"
  14. s_back3 = "Images/background3.png"
  15. s_stars1 = "Images/stars.png"
  16. s_stars2 = "Images/stars2.png"
  17. s_fire = "Images/fire.png"
  18. s_snow = "Images/snow.png"
  19. s_streak = "Images/streak.png"
  20. s_PlayNormal = "Images/btn-play-normal.png"
  21. s_PlaySelect = "Images/btn-play-selected.png"
  22. s_AboutNormal = "Images/btn-about-normal.png"
  23. s_AboutSelect = "Images/btn-about-selected.png"
  24. s_HighNormal = "Images/btn-highscores-normal.png"
  25. s_HighSelect = "Images/btn-highscores-selected.png"
  26. s_Ball = "Images/ball.png"
  27. s_Paddle = "Images/paddle.png"
  28. s_pPathClose = "Images/close.png"
  29. s_MenuItem = "Images/menuitemsprite.png"
  30. s_SendScore = "Images/SendScoreButton.png"
  31. s_PressSendScore = "Images/SendScoreButtonPressed.png"
  32. s_Power = "Images/powered.png"
  33. s_AtlasTest = "Images/atlastest.png"
  34.  
  35. -- tilemaps resource
  36. s_TilesPng = "TileMaps/tiles.png"
  37. s_LevelMapTga = "TileMaps/levelmap.tga"
  38.  
  39. -- spine test resource
  40. s_pPathSpineBoyJson = "spine/spineboy.json"
  41. s_pPathSpineBoyAtlas = "spine/spineboy.atlas"
  42.  
  43. -- fonts resource
  44. s_markerFeltFontPath = "fonts/Marker Felt.ttf"
  45. s_arialPath = "fonts/arial.ttf"
  46. s_thonburiPath = "fonts/Thonburi.ttf"
  47. s_tahomaPath = "fonts/tahoma.ttf"

这个文件定义了全部的资源路径,一些图片、json资源、字体资源等。

其它相关的文件,笔者在这里就不贴代码,这个大家私下去查看,我在这里仅仅是提供相关的思路,让大家理清怎样使用Cocos2d-x给我们提供的样例进行学习。
下一篇博客,笔者将会介绍第一个样例-重力加速器,非常感谢你的关注。

Cocos2d-x 3.1.1 lua-tests 开篇的更多相关文章

  1. Cocos2d Lua 越来越小样本 内存游戏

    1.游戏简介 一个"记忆"类的比赛游戏.你和电脑对战,轮到谁的回合,谁翻两张牌,假设两张牌一样.就消掉这两张牌,得2分,能够继续翻牌,假设两张牌不一样,就换一个人.直到最后.看谁的 ...

  2. 在cocos code ide的基础上构建自己的lua开发调试环境

    对于一种语言,其所谓开发调试环境, 大体有以下两方面的内容: 1.开发, 即代码编写, 主要是代码提示.补齐, 更高级一点的如变量名颜色等. 2.调试, 主要是运行状态下断点.查看变量.堆栈等. 现在 ...

  3. cocos2d-x 使用Lua

    转自:http://www.benmutou.com/blog/archives/49 1. Lua的堆栈和全局表 我们来简单解释一下Lua的堆栈和全局表,堆栈大家应该会比较熟悉,它主要是用来让C++ ...

  4. Cocos Code IDE + Lua初次使用FastTiledMap的坑

    近期想玩玩Lua.又想玩玩Cocos Code IDE.更加想写一个即时战斗的.防守的.会动的.有迷雾的.要探索的(旁白:给我停!)跑地图游戏. 于是我就用Cocos Code IDE来写游戏了.挑战 ...

  5. LTUI v1.1, 一个基于lua的跨平台字符终端UI界面库

    简介 LTUI是一个基于lua的跨平台字符终端UI界面库. 此框架源于xmake中图形化菜单配置的需求,类似linux kernel的menuconf去配置编译参数,因此基于curses和lua实现了 ...

  6. 关于Protobuf在游戏开发中的运用

    最近在研究protobuf在项目中的使用,由于我们项目服务端采用的是C++,客户端是cocos2dx-cpp,客户端与服务端的消息传输是直接对象的二进制流.如果客户端一直用C++来写,问题到不大,但是 ...

  7. A*算法实现

    A* 算法非常简单.算法维护两个集合:OPEN 集和 CLOSED 集.OPEN 集包含待检测节点.初始状态,OPEN集仅包含一个元素:开始位置.CLOSED集包含已检测节点.初始状态,CLOSED集 ...

  8. Windows 安装 python2.7

    Windows 安装 python2.7 python2.7下载地址: https://www.python.org/downloads/release/python-2714/ 安装过程: 设置系统 ...

  9. 数据库性能测试:sysbench用法详解

    1.简介和安装 sysbench是一个很不错的数据库性能测试工具. 官方站点:https://github.com/akopytov/sysbench/ rpm包下载:https://packagec ...

随机推荐

  1. TImage也有OnClick事件,可以当按钮使用,配上合适的图片(背景透明,效果前凸)更是几乎以假乱真

    本质上TImage与TSpeedButton没有什么区别,都是没有句柄的,但都可以执行OnClick事件.有空分析一下.

  2. Oracle管道函数(Pipelined Table Function)介绍

    一 概述: 1.管道函数即是能够返回行集合(能够使嵌套表nested table 或数组 varray)的函数,我们能够像查询物理表一样查询它或者将其  赋值给集合变量. 2.管道函数为并行运行,在普 ...

  3. 支付宝打造公共账号业务网关, RSA密钥对生成

    作者: 玉龙      版权全部,同意转载. 请注明出处(创建金融_玉龙  http://www.weibo.com/u/1872245125) 原文地址: http://blog.csdn.net/ ...

  4. Eclipse用法和技巧十三:自动生成的TODO注释1

    使用eclipse的快捷键自动生成的代码,经常有这样的注释. 一眼看上去这个注释和一般的注释并无什么差别,不过TODO这个字符串的颜色不一样,应该有些内容.TODO是eclipse中提供的一种任务标签 ...

  5. MFC获取rgb图像数据后动态显示及保存图片的方法

    该情况可用于视频通信中获取的位图数据回放显示或显示摄像头捕获的本地图像 第一种方法 #include<vfw.h> 加载 vfw32.lib  链接库 //---------------- ...

  6. Axure RP中线条的设置

    文章来源与网络 来自:非原型不设计

  7. oracle 的常用语句

    第一部分 基本语法 //拼接表字段 select id   ||   'is'   ||   name from admin select * from emp where ename like '% ...

  8. jsp静态化之简单介绍

    package com.zwd.text; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputS ...

  9. hibernate简单介绍

    1.   Hibernate是什么? hibernate是 轻量级的 ORM 框架. ORM全称object/relationmapping [对象/关系映射]. Hibernate主要用来实现Jav ...

  10. C# - ref

    The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by ...