最近比较忙,也没时间写。。。。OK,我们接着讲下去,现在我们已经创建了一个新的游戏场景,但现在一片空白,我们并没有加载任何东西。那么显然下面,我们应该加载一张地图,说到地图,那我们就需要地图编辑器,这里推荐Tiled地图编辑器,现在tiled地图编辑器主要是qt版的,当然还有java版,
java版下载地址:http://download.csdn.net/detail/kuloveyouwei/5412155
qt版下载地址:http://download.csdn.net/detail/kuloveyouwei/5412251
首先先打开QT版的地图编辑器,新建一个52*52的8*8像素点的:
OK,添加新的图块
最后添加瓦片图片进去,自己折腾把,,
保存生产tmx格式的,其实就是一个xml,我们来看下:
<?xml version="1.0" encoding="UTF-8"?> <map version="1.0" orientation="orthogonal" width="52" height="52" tilewidth="8" tileheight="8"> <tileset firstgid="1" name="tile" tilewidth="8" tileheight="8"> <image source="tile.png" trans="000000" width="224" height="32"/> </tileset> <layer name="bg1" width="52" height="52"> <data encoding="base64" compression="zlib"> eJztmO0KwjAMRaegoO+goKDv/4j2Z3dhvbtL+jGXAyWw0qzmzFA6TRqXNK5ZVLGu9+aVxjuLrdd7E35816uc0jhnEbHWl+W3ziOPNJ5ZRKz1Zfmt80j40RjNjwrmU+uP34O3HxXMp9Yfv4fw819+GN7+kNbnB+/6IKOdH6yEnzm3NO5ZZKh+1Hpjftwf63+fNL5ZZKh+1Hpjftwf63/hZ19+VF+Itz91P/j7VV+Itz91P+GnTG8/CDsPs/7DotrvWH9jsPMw6z8sqv2O9TdG+BnbDwPrq9av9f0OA+ur1q/1/Q4j/MypPa/en7D+VLu+bL16f8L6U+3vP/zs2w/i3X9Gvx9V53vfj4af8vzR/XjT24834ac8P7qf3u/37m+18T5fePnZ+r8Z1c/W/01rP2qd1z5fym/tj171YevXvt/aH8NPOc/a50v5VT8/kOhNCQ== </data> </layer> <layer name="bg2" width="52" height="52"> <data encoding="base64" compression="zlib"> eJzt0bEJACAQA0Ab3UP3H1IX8LEQ8eEOQiBtSgEAAAAAAAAAAOClutKCzqavjKCz2f2Q/Z/T/Xf+uWMCZ9oCcQ== </data> </layer> <objectgroup name="objects" width="52" height="52"> <object name="pl1" x="136" y="384" width="24" height="24"/> <object name="en1" x="4" y="4" width="24" height="24"/> <object name="en2" x="200" y="0" width="24" height="24"/> <object name="en3" x="392" y="0" width="24" height="24"/> <object name="t1" x="132" y="60" width="24" height="24"/> <object name="t2" x="68" y="228" width="24" height="24"/> <object name="t3" x="260" y="196" width="24" height="24"/> <object name="t4" x="324" y="324" width="24" height="24"/> <object name="t5" x="380" y="164" width="24" height="24"/> <object name="t6" x="228" y="116" width="24" height="24"/> <object name="t7" x="316" y="4" width="24" height="24"/> <object name="t8" x="208" y="168" width="24" height="24"/> <object name="t9" x="28" y="124" width="24" height="24"/> <object name="t10" x="4" y="356" width="24" height="24"/> <object name="home" x="192" y="384" width="32" height="32"/> </objectgroup> </map>
OK,地图有了,我们来看怎么加载地图到我们的场景中,
CCSize wSize=CCDirector::sharedDirector()->getVisibleSize(); CCTMXTiledMap *gameMap=CCTMXTiledMap::create("map2.tmx"); //缩放比列 float scale=wSize.height/gameMap->getContentSize().height; gameMap->setScale(scale); gameMap->setPosition(wSize.width/6,0); this->addChild(gameMap, 1);
这里我们直接在场景里里初始化我们的地图,其实应该是新建一个地图层,下一章,我们将新建一个地图层专门来初始化地图。。。。