当前位置: 首页>>代码示例>>C++>>正文


C++ TMXTiledMap::getPropertiesForGID方法代码示例

本文整理汇总了C++中TMXTiledMap::getPropertiesForGID方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXTiledMap::getPropertiesForGID方法的具体用法?C++ TMXTiledMap::getPropertiesForGID怎么用?C++ TMXTiledMap::getPropertiesForGID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TMXTiledMap的用法示例。


在下文中一共展示了TMXTiledMap::getPropertiesForGID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onTouchBegan

//触摸事件
bool GameScene::onTouchBegan(Touch * touch, Event * unused_event)
{
	//移除建塔面板
	if (this->getChildByTag(100) != nullptr)
	{
		this->removeChildByTag(100);
	}

	Vec2 now = touch->getLocation();
	log("touch %f %f", now.x, now.y);
	TMXTiledMap * ourMap = (TMXTiledMap*)this->getChildByTag(0);
	//row为横坐标,col为纵坐标
	this->nowRow = (int)(now.x / 56.9);
	this->nowCol = 10-(int)(now.y / 56.9);
	log("%d %d", nowRow, nowCol);
	//获取点击块id
	int touchID = ourMap->getLayer("Layer1")->getTileGIDAt(Vec2(nowRow, nowCol));
	log("touch ID %d", touchID);
	//初始化可放塔标记
	bool canTouch = false;
	//检查该块是否可以建塔
	if (!ourMap->getPropertiesForGID(touchID).isNull())
	{
		auto tileTemp = ourMap->getPropertiesForGID(touchID).asValueMap();
		if (!tileTemp.empty())
		{
			canTouch = true;
			log("canTouch");
		}
	}

	if (canTouch)
	{
		//可以建塔,弹出选择面板
		if(towerInfo[nowCol][nowRow])
		{
			//如果已经有塔,变卖或升级
		}
		else
		{
			addTDSelect(nowRow, 10 - nowCol);
		}
	}
	else
	{
		//不可建塔,弹出错误提示
		auto tips = Sprite::create("notips.png");
		tips->setPosition(Vec2(nowRow * 56.9+28.45, (10 - nowCol) * 56.9+28.45));
		this->addChild(tips);
		tips->runAction(
			Sequence::create(
				DelayTime::create(0.8),
				CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, tips)), NULL));
	}
	return true;
}
开发者ID:feizhuliuq,项目名称:CantFallTower,代码行数:57,代码来源:GameScene.cpp

示例2: onTouchBegan

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

示例3: _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


注:本文中的TMXTiledMap::getPropertiesForGID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。