本文整理汇总了C++中TMXLayer类的典型用法代码示例。如果您正苦于以下问题:C++ TMXLayer类的具体用法?C++ TMXLayer怎么用?C++ TMXLayer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TMXLayer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parseLayer
void TMXTiledMap::buildWithMapInfo(TMXMapInfo* mapInfo)
{
_mapSize = mapInfo->getMapSize();
_tileSize = mapInfo->getTileSize();
_mapOrientation = mapInfo->getOrientation();
_objectGroups = mapInfo->getObjectGroups();
_properties = mapInfo->getProperties();
_tileProperties = mapInfo->getTileProperties();
int idx = 0;
auto& layers = mapInfo->getLayers();
for (const auto &layerInfo : layers) {
if (layerInfo->_visible) {
TMXLayer *child = parseLayer(layerInfo, mapInfo);
if (child == nullptr) {
idx++;
continue;
}
addChild(child, idx, idx);
// update content size with the max size
const Size& childSize = child->getContentSize();
Size currentSize = this->getContentSize();
currentSize.width = std::max(currentSize.width, childSize.width);
currentSize.height = std::max(currentSize.height, childSize.height);
this->setContentSize(currentSize);
idx++;
}
}
_tmxLayerNum = idx;
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:35,代码来源:CCTMXTiledMap.cpp
示例2: Vec2
void Player::setTagPosition(int x, int y){
auto spriteSize = m_node->getContentSize();
Vec2 dstPos = Vec2(x + spriteSize.width / 2, y);
Vec2 tiledPos = tileCoorForPosition(Vec2(dstPos.x, dstPos.y));
int tiledGid = meta->getTileGIDAt(tiledPos);
if (tiledGid != 0){
Value properties = m_map->getPropertiesForGID(tiledGid);
ValueMap propertiesMap = properties.asValueMap();
if (propertiesMap.find("Collidable") != propertiesMap.end()){
Value prop = propertiesMap.at("Collidable");
if (prop.asString().compare("true") == 0){
return;
}
}
if (propertiesMap.find("food") != propertiesMap.end()){
Value prop = propertiesMap.at("food");
if (prop.asString().compare("true") == 0){
TMXLayer* barrier = m_map->getLayer("barrier");
barrier->removeTileAt(tiledPos);
}
}
}
Entity::setTagPosition(x, y);
setViewPointByPlayer();
}
开发者ID:bazhijing,项目名称:revengeTank,代码行数:31,代码来源:Player.cpp
示例3: getBoundingBox
void Bullet::bulletBoom()
{
Rect rect = getBoundingBox();
Size mapSize = mTileMapInfo->getTileMap()->getContentSize();
if (rect.getMinX() < 0 || rect.getMaxX() >= mapSize.width || rect.getMinY() < 0
|| rect.getMaxY() >= mapSize.height)
return;
TMXLayer* tmxLayer = mTileMapInfo->getTileMap()->getLayer("layer_0");
Size tileSize = tmxLayer->getMapTileSize();
float MinY = mapSize.height - rect.getMinY();
float MaxY = mapSize.height - rect.getMaxY();
Point pt = Point((int) rect.getMinX() / tileSize.width, (int) (MinY / tileSize.height));
if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
tmxLayer->setTileGID(gidToTileType[tileNone], pt);
pt = Point((int) rect.getMinX() / tileSize.width, (int) (MaxY / tileSize.height));
if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
tmxLayer->setTileGID(gidToTileType[tileNone], pt);
pt = Point((int) rect.getMaxX() / tileSize.width, (int) (MinY / tileSize.height));
if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
tmxLayer->setTileGID(gidToTileType[tileNone], pt);
pt = Point((int) rect.getMaxX() / tileSize.width, (int) (MaxY / tileSize.height));
if (gidToTileType[tmxLayer->getTileGIDAt(pt)] == tileWall)
tmxLayer->setTileGID(gidToTileType[tileNone], pt);
}
开发者ID:jypeitao,项目名称:Cocosdx-tk,代码行数:33,代码来源:Bullet.cpp
示例4: Color4B
//------------------------------------------------------------------
//
// TMXUncompressedTest
//
//------------------------------------------------------------------
TMXUncompressedTest::TMXUncompressedTest()
{
auto color = LayerColor::create( Color4B(64,64,64,255) );
addChild(color, -1);
auto map = TMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
// move map to the center of the screen
auto ms = map->getMapSize();
auto ts = map->getTileSize();
map->runAction(MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
// testing release map
TMXLayer* layer;
auto& children = map->getChildren();
for(const auto &node : children) {
layer= static_cast<TMXLayer*>(node);
layer->releaseMap();
}
}
开发者ID:289997171,项目名称:cocos2d-x,代码行数:31,代码来源:TileMapTest.cpp
示例5: init
bool SelectRoundLayer::init()
{
if (!Layer::init())
return false;
// background
std::string filePath = FileUtils::getInstance()->fullPathForFilename("selectRound.tmx");
TiledMapParser* tiledMapParser = TiledMapParser::create(filePath);
TMXLayer* layer = tiledMapParser->createLayer("backgroundLayer");
addChild(layer);
int max_passed_round = GameController::getInstance()->maxPassedRound();
Point pos;
// round buttons
MapGidToGamePos map;
tiledMapParser->getGidToGamePosMap("roundIconLayer", &map);
MapGidToGamePos::iterator it = map.begin();
for (; map.end() != it; ++it) {
int round = it->first - 1;
createRoundButton(round, GameController::getInstance()->isUnlock(round), it->second);
if (max_passed_round == round)
pos = it->second;
}
Size layer_size = layer->getLayerSize();
Size visibleSize = Director::getInstance()->getVisibleSize();
int height_offset = layer_size.height - visibleSize.height;
Vec2 visibleOrigin = Director::getInstance()->getVisibleOrigin();
setPosition(Vec2(visibleOrigin.x, visibleOrigin.y + height_offset));
setTouchEnabled(true);
return true;
}
开发者ID:has806,项目名称:SushiCrush,代码行数:35,代码来源:SelectRoundLayer.cpp
示例6: initTileDatas
void HelloWorld::initTileDatas()
{
Size mapsize = m_gamemap->getMapSize();
TMXLayer* layer = m_gamemap->layerNamed("block");
assert(layer != NULL);
for (int m = 0; m < mapsize.width; ++m)
{
for (int n = 0; n < mapsize.height; ++n)
{
uint32_t gid = layer->getTileGIDAt(Vec2(m, n));
TileData* data = new TileData(std::make_pair(m, n));
if (gid)
{
ValueMap property = m_gamemap->getPropertiesForGID(gid).asValueMap();
if (property["block"].asString() == "true")
data->setWalkAble(false);
data->setPriority(property["Priority"].asInt());
data->setExtraHScore(property["extra"].asInt());
}
m_tileDatas.push_back(data);
}
}
}
开发者ID:ssss3301,项目名称:TileMap,代码行数:25,代码来源:HelloWorldScene.cpp
示例7: drawCollisionTiles
void SimplePlatformerScene::drawCollisionTiles()
{
TMXLayer* collisionLayer = _tileMapNode->getLayer("edgeLayer");
auto mapSize = _tileMapNode->getMapSize();
auto tileSize = _tileMapNode->getTileSize();
Sprite* tile = nullptr;
Point pos;
for(int i = 0; i < mapSize.width; i++)
{
for(int j = 0; j < mapSize.height; j++)
{
tile = collisionLayer->getTileAt(Point(i, j));
if(tile != nullptr)
{
const ValueMap property = _tileMapNode->getPropertiesForGID(collisionLayer->getTileGIDAt(Point(i, j))).asValueMap();
bool collidable = property.at("collidable").asBool();
if(collidable)
{
pos = collisionLayer->getPositionAt(Point(i, j));
makeBoxObjAt(tile, tileSize, false, PhysicsMaterial(0.2f, 0.5f, 0.5f));
}
}
}
}
}
开发者ID:1007650105,项目名称:RockChipmunk2D,代码行数:25,代码来源:SimplePlatformerScene.cpp
示例8: convertTo2d
bool MapLayer::onTouchBegan(Touch *touch, Event *unused_event)
{
Point beginPos = touch->getLocationInView();
beginPos = Director::getInstance()->convertToGL(beginPos);
TMXTiledMap* map = (TMXTiledMap*)this->getChildByTag(kTagTileMap);
// 获取触摸点在地图位置上的索引
Point mapPos = map->getPosition();
Point aimMapIndex = convertTo2d(Point(beginPos.x - mapPos.x, beginPos.y - mapPos.y));
if(aimMapIndex.x < 0 || aimMapIndex.y < 0 || aimMapIndex.x >= map->getMapSize().width || aimMapIndex.y >= map->getMapSize().height) {
// 超出地图边界
return false;
}
Point herop = _tamara->getPosition();
Point mapIndex = convertTo2d(herop);
TMXLayer* layer = map->getLayer("grass");
int tilegid = layer->getTileGIDAt(aimMapIndex);
Value tileValue = map->getPropertiesForGID(tilegid);
int touchValue = tileValue.asValueMap().at("conflict").asInt();
if(touchValue == 1) {
return false;
}
_path = _myAstar->findPath(mapIndex.x, mapIndex.y, aimMapIndex.x, aimMapIndex.y, map);
if(nullptr != _path && _path->count() >= 2) {
_stepIndex = 1;
} else {
_stepIndex = -1;
}
_smallStepIndex = 0;
return true;
}
开发者ID:suli1,项目名称:suli1-myGame,代码行数:35,代码来源:MapLayer.cpp
示例9: new
// FastTMXLayer - init & alloc & dealloc
TMXLayer * TMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXLayer *ret = new (std::nothrow) TMXLayer();
if (ret->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
ret->autorelease();
return ret;
}
return nullptr;
}
开发者ID:keith1020,项目名称:cocos.github.io,代码行数:11,代码来源:CCFastTMXLayer.cpp
示例10: tilesetForLayer
// private
TMXLayer * TMXTiledMap::parseLayer(TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXTilesetInfo *tileset = tilesetForLayer(layerInfo, mapInfo);
TMXLayer *layer = TMXLayer::create(tileset, layerInfo, mapInfo);
// tell the layerinfo to release the ownership of the tiles map.
layerInfo->_ownTiles = false;
layer->setupTiles();
return layer;
}
开发者ID:mixiancheng,项目名称:selfWork,代码行数:12,代码来源:CCFastTMXTiledMap.cpp
示例11: assert
/**
*加载地图
*/
void HelloWorld::loadMap(const std::string& mapName)
{
String* mapXml = String::createWithContentsOfFile("gamemap.tmx");
m_gamemap = TMXTiledMap::createWithXML(mapXml->getCString(), "");
assert(m_gamemap);
TMXLayer* layer = m_gamemap->layerNamed("block");
if (layer != NULL)
layer->setVisible(false);
this->addChild(m_gamemap);
}
开发者ID:ssss3301,项目名称:TileMap,代码行数:14,代码来源:HelloWorldScene.cpp
示例12: _dealMap
void BattleLayer::_dealMap(){
Size visibleSize = Director::getInstance()->getVisibleSize();
_battleMapBackground = LayerColor::create(Color4B(0, 0, 0, 255), visibleSize.width, visibleSize.height);
_battleMapBackground->setPosition(0, 0);
this->addChild(_battleMapBackground, 0);
TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
TMXLayer *backgroundLayer = tiledMap->getLayer("background");
TMXLayer *walkableLayer = tiledMap->getLayer("walkable");
walkableLayer->setAnchorPoint(Vec2(0.5, 0.5));
walkableLayer->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
_battleMapBackground->addChild(walkableLayer, 1);
backgroundLayer->setAnchorPoint(Vec2(0.5, 0.5));
backgroundLayer->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
_battleMapBackground->addChild(backgroundLayer, 1);
Size mapSize = walkableLayer->getLayerSize();
_battleMapTileSize = Size(20, 30);
_battleTileSize = walkableLayer->getMapTileSize();
_battleMapSize = Size(20 * _battleTileSize.width, 30 * _battleTileSize.height);
_battleMap = LayerColor::create(Color4B(255, 255, 255, 150), _battleMapSize.width, _battleMapSize.height);
_battleMap->ignoreAnchorPointForPosition(false);
_battleMap->setAnchorPoint(Vec2(0.5, 0.5));
_battleMap->setPosition(visibleSize.width / 2, visibleSize.height / 2 + 90);
_battleMapBackground->addChild(_battleMap, 5);
}
开发者ID:Creativegame,项目名称:ClashRoyale,代码行数:31,代码来源:BattleLayer.cpp
示例13: TMXLayer
NS_CC_BEGIN
// TMXLayer - init & alloc & dealloc
TMXLayer * TMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXLayer *pRet = new TMXLayer();
if (pRet->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
pRet->autorelease();
return pRet;
}
return NULL;
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:15,代码来源:CCTMXLayer.cpp
示例14: Point
bool HelloWorld::onTouchBegan(Touch* touch, Event* event)
{
auto m_tBeginPos = Point(touch->getLocation().x,touch->getLocation().y);
auto map = static_cast<TMXTiledMap*>( getChildByTag(1));
Point mapp = map->getPosition();
Point aimmapindex = convertto2d(m_tBeginPos.x - mapp.x,m_tBeginPos.y - mapp.y);
if(aimmapindex.x < 0 || aimmapindex.y < 0 || aimmapindex.x >= map->getMapSize().width || aimmapindex.y >= map->getMapSize().height)
{
return false;
}
TMXLayer* layer = map->layerNamed("grass");
layer->setTileGID(4,aimmapindex);
return true;
}
开发者ID:Ratel13,项目名称:book-code,代码行数:16,代码来源:HelloWorldScene.cpp
示例15: new
NS_CC_BEGIN
// TMXLayer - init & alloc & dealloc
TMXLayer * TMXLayer::create(TMXTilesetInfo *tilesetInfo, TMXLayerInfo *layerInfo, TMXMapInfo *mapInfo)
{
TMXLayer *ret = new (std::nothrow) TMXLayer();
if (ret->initWithTilesetInfo(tilesetInfo, layerInfo, mapInfo))
{
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
return nullptr;
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:16,代码来源:CCTMXLayer.cpp
示例16: switch
bool MapScene::init()
{
if (!Layer::create())
{
return false;
}
/*╪стьмъф╛╣ьм╪*/
switch (this->step)
{
case 1:{
std::string file = "Map.tmx";
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
this->map = TMXTiledMap::createWithXML(str->getCString(), "");
TMXLayer* obscatle= map->layerNamed("obscatle");
obscatle->setVisible(false);
this->objGroup = map->getObjectGroup("Object");
this->addChild(map, 0);
}break;
case 2:{
std::string file = "MapStep2.tmx";
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
this->map = TMXTiledMap::createWithXML(str->getCString(), "");
TMXLayer* obscatle = map->layerNamed("obscatle");
obscatle->setVisible(false);
this->objGroup = map->getObjectGroup("Object");
this->addChild(map, 0);
}break;
case 3:{
std::string file = "MapStep3.tmx";
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
this->map = TMXTiledMap::createWithXML(str->getCString(), "");
TMXLayer* obscatle = map->layerNamed("obscatle");
obscatle->setVisible(false);
this->objGroup = map->getObjectGroup("Object");
this->addChild(map, 0);
}break;
default:
break;
}
return true;
}
开发者ID:tsengkasing,项目名称:AmazingGrave,代码行数:47,代码来源:MapScene.cpp
示例17: _makeAStarData
void BattleLayer::_makeAStarData(){
TMXTiledMap *tiledMap = TMXTiledMap::create("res/map/battle_map.tmx");
TMXLayer *walkableLayer = tiledMap->getLayer("walkable");
Size mapSize = walkableLayer->getLayerSize();
// CCLOG("MapSize: (%f, %f)", mapSize.width, mapSize.height);
AStarDataNode astarDataVec[20][30];
for (int column = 0; column < _battleMapTileSize.width; ++column){
for (int row = 0; row < _battleMapTileSize.height; ++row){
Vec2 tileCoord = Vec2(column + 5, mapSize.height - (row + 5) - 1);
int tileGID = walkableLayer->getTileGIDAt(tileCoord);
if (tileGID > 0){
Value value = tiledMap->getPropertiesForGID(tileGID);
ValueMap valueMap = value.asValueMap();
int walkable = valueMap["walkable"].asInt();
// CCLOG("Column: %d, Row: %d, Walkable: %d", column, row, walkable);
astarDataVec[column][row].column = column;
astarDataVec[column][row].row = row;
astarDataVec[column][row].walkable = (walkable == 0) ? false : true;
}
}
}
for (int column = 0; column < _battleMapTileSize.width; ++column){
std::vector<AStarDataNode> oneList;
std::vector<BattleElement *> oneBattleElementList;
for (int row = 0; row < _battleMapTileSize.height; ++row){
AStarDataNode astarDataNode = AStarDataNode(column, row, astarDataVec[column][row].walkable);
oneList.push_back(astarDataNode);
oneBattleElementList.push_back(nullptr);
}
astarData.push_back(oneList);
battleElements.push_back(oneBattleElementList);
}
// for (int row = 0; row < _battleMapTileSize.height; ++row){
// for (int column = 0; column < _battleMapTileSize.width; ++column){
// printf("%d", astarData[column][row].walkable);
// }
// printf("\n");
// }
}
开发者ID:Creativegame,项目名称:ClashRoyale,代码行数:46,代码来源:BattleLayer.cpp
示例18: addChild
//------------------------------------------------------------------
//
// TMXTilesetTest
//
//------------------------------------------------------------------
TMXTilesetTest::TMXTilesetTest()
{
auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
addChild(map, 0, kTagTileMap);
Size CC_UNUSED s = map->getContentSize();
CCLOG("ContentSize: %f, %f", s.width,s.height);
TMXLayer* layer;
layer = map->getLayer("Layer 0");
layer->getTexture()->setAntiAliasTexParameters();
layer = map->getLayer("Layer 1");
layer->getTexture()->setAntiAliasTexParameters();
layer = map->getLayer("Layer 2");
layer->getTexture()->setAntiAliasTexParameters();
}
开发者ID:289997171,项目名称:cocos2d-x,代码行数:23,代码来源:TileMapTest.cpp
示例19: CCASSERT
// public
TMXLayer * TMXTiledMap::getLayer(const std::string& layerName) const
{
CCASSERT(layerName.size() > 0, "Invalid layer name!");
for (auto& child : _children)
{
TMXLayer* layer = dynamic_cast<TMXLayer*>(child);
if(layer)
{
if(layerName.compare( layer->getLayerName()) == 0)
{
return layer;
}
}
}
// layer not found
return nullptr;
}
开发者ID:FenneX,项目名称:FenneXEmptyProject,代码行数:20,代码来源:CCTMXTiledMap.cpp
示例20: checkMap
// 检测地图上该点是否能通过
bool Astar::checkMap(int col, int row)
{
// 检查地图中是否有碰撞
if(abs(_aimCol - col) > 0 || abs(_aimRow - row) > 0) {
TMXLayer* layer = _map->getLayer("grass");
int tilegid = layer->getTileGIDAt(Point(col, row));
//Dictionary* tiledic = _map->propertiesForGID(tilegid);
//String* mvalue = (String*)tiledic->objectForKey("conflict");
//int mv = mvalue->intValue();
Value tileValue = _map->getPropertiesForGID(tilegid);
int touchValue = tileValue.asValueMap().at("conflict").asInt();
if(touchValue == 1) {
// 检测到有碰撞
return false;
}
}
return true;
}
开发者ID:suli1,项目名称:suli1-myGame,代码行数:21,代码来源:Astar.cpp
注:本文中的TMXLayer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论