Previous: http://www.cocoachina.com/bbs/read.php?tid=202436
Make the map
制作地图
我们现在已经有了关于如何编写这款游戏的概念。在我们开始编码以前,我们仍需做些准备:
·首先,我们必定需要一张地图来实现我们的程序。
·其次,设定多个路标来引导我们的敌人。
·第三,我们会添加不同种类的敌人。

Settingthe value
Tower defender map
使用瓦片地图编辑器像我在上面展示的那样制造地图。 
Rectangle
在编辑器的右上角创建一个“Object”层。按下“矩形”按钮如我上图所示来创造8个路标。并将它们命名为Waypoing00, Waypoint01, Waypoint02……

Load the map :
读取地图:
把“HelloWorld”的头文件和执行文件名称都改为“TutorialScene”。并且把文件里每一个“HelloWorld”改成“TutorialScene”
删除:
#ifndef HELLOWORLD_SCENE_H
#define HELLOWORLD_SCENE_H
#endif // HELLOWORLD_SCENE_H同样的把“AppDelegate.cpp”里的“HelloWorld”都改为“TutorialScene”。 改:<pre class="brush:cpp; toolbar: true; auto-links: false;">#include “HelloWorld.h” auto scene = HelloWorld::createScene();成:
#include “TutorialScene.h”
auto scene = TutorialScene::createScene();我们要用到的功能基本都存在于“TutorialScene”。所以毫无疑问这个文件将会成为最为复杂的一个。 In the ‘TutorialScene.h’: <pre class="brush:cpp; toolbar: true; auto-links: false;">#pragma once #include “cocos2d.h” USING_NS_CC; …… private: cocos2d::TMXTiledMap*_tileMap; cocos2d::TMXLayer*_background; ……替换所有在“TutorialScene.cpp”里“bool TutorialScene::init()”中的所有代码:
boolTutorialScene::init() { if ( !Layer::init() ) { return false; } Size visibleSize =Director::getInstance()->getVisibleSize(); Point origin =Director::getInstance()->getVisibleOrigin(); std::string file = "01.tmx"; auto str = String::createWithContentsOfFile(FileUtils::getInstance()-> fullPathForFilename(file.c_str()).c_str()); this->_tileMap =TMXTiledMap::createWithXML(str->getCString(),""); this->_background = _tileMap->layerNamed("Background"); addChild(_tileMap, -1); return true; } ``` }这里,我们调用TMXTilemapde的类。现在我们运行VS2012的调试Debug功能。 Our new map 未完待续~(一日一更) Next: http://www.cocoachina.com/bbs/read.php?tid=202870





第一帖和最后一贴···