使用Tiled制作cocosd-x地图

来源:互联网 发布:卡密软件下载 编辑:程序博客网 时间:2024/06/06 01:11

1.下个Tiled,百度,然后下载,偶看。

2.两篇参考的例子:

子龙山的人写的~~

http://www.cnblogs.com/andyque/archive/2011/04/11/2012852.html

http://www.cnblogs.com/andyque/archive/2011/05/03/2033620.html

3.打开tiled



a.图片使用游戏资源文件这个网上的资源

b.文件-》新文件;


c.地图-》新图块


d.加加加,点击右边的东西,再点左边的面板,可以贴图上去,可以用画刷,颜料罐,可以多选;

然后图层保存为Background,文件保存为level01.tmx.(如图)


e.加入到工程中

    /* 加载地图 */    CCTMXTiledMap* map = CCTMXTiledMap::create("map/level01.tmx");    this->addChild(map);     /* 创建玩家 */    Player* mPlayer = Player::createWithTiledMap(map);


    CCSprite* mSprite;    Controller* mController;    CCTMXTiledMap* map;    CCTMXLayer* meta;   /* 检测碰撞的地图层 */    CCTMXLayer* barrier;/* 障碍物层 */

bool Player::initWithTiledMap( CCTMXTiledMap* map ){    /* 加载对象层的所有对象 */    CCTMXObjectGroup* objGroup = map->objectGroupNamed("objects");    /* 加载meta层 */    meta = map->layerNamed("meta");    meta->setVisible(false);    /* 加载障碍物层 */    barrier = map->layerNamed("barrier");    /* 加载玩家坐标对象 */    CCDictionary* playerPointDic = objGroup->objectNamed("PlayerPoint");    float playerX = playerPointDic->valueForKey("x")->floatValue();    float playerY = playerPointDic->valueForKey("y")->floatValue();    /* 保存地图的引用 */     this->map = map;    return true;}