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


C++ TMXObjectGroup::getObject方法代码示例

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


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

示例1: addMapMenu

void AttackMapLayer::addMapMenu(){
	//以下全部为设置地图的窗口
	TMXTiledMap * changeMap = TMXTiledMap::create("bakground(1).tmx");
	this->addChild(changeMap);
	float cmX = (vSize.width - changeMap->getContentSize().width) / 2;
	changeMap->setPosition(Vec2(cmX, 0));
	TMXObjectGroup * objectgroup = changeMap->getObjectGroup("object");
	ValueMap valuemap = objectgroup->getObject("object1");
	float x = valuemap.at("x").asFloat();
	float y = valuemap.at("y").asFloat();
	auto menuitem = MenuItemImage::create("stage-9.png", "stage-9.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_1, this));
	menuitem->setPosition(Vec2(x, y));
	auto menu = Menu::create(menuitem, NULL);
	menu->setPosition(Vec2(cmX, 0));
	//房后闪光
	auto flashBG = Sprite::create("crusade_stage_7_curren.png");
	flashBG->setPosition(Vec2(x , y));
	//动画渐入渐出
	auto flashAnimationOut = FadeOut::create(0.5);
	auto flashAnimationIn = FadeIn::create(0.5);
	auto seqAction = Sequence::create(flashAnimationOut, flashAnimationIn, NULL);
	flashBG->runAction(RepeatForever::create(seqAction));
	addChild(flashBG);


	valuemap = objectgroup->getObject("object2");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem1 = MenuItemImage::create("stage-19.png", "stage-19.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_2, this));
	menuitem1->setPosition(Vec2(x, y));
	menu->addChild(menuitem1);

	valuemap = objectgroup->getObject("object3");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem2 = MenuItemImage::create("stage-23.png", "stage-23.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_3, this));
	menuitem2->setPosition(Vec2(x, y));
	menu->addChild(menuitem2);

	valuemap = objectgroup->getObject("object4");
	x = valuemap.at("x").asFloat();
	y = valuemap.at("y").asFloat();
	auto  menuitem3 = MenuItemImage::create("stage-25.png", "stage-25.png", CC_CALLBACK_1(AttackMapLayer::changeMap_a_4, this));
	menuitem3->setPosition(Vec2(x, y));
	menu->addChild(menuitem3);


	this->addChild(menu);
}
开发者ID:joyfish,项目名称:TowerTD,代码行数:49,代码来源:AttackMapLayer.cpp

示例2: addPlayer

void TollgateScene::addPlayer(TMXTiledMap* map){
	Player::delPlayer();
	TMXObjectGroup* objGroup = map->getObjectGroup("objects");

	ValueMap playerPointMap = objGroup->getObject("PlayerPoint");
	float playerX = playerPointMap.at("x").asFloat();
	float playerY = playerPointMap.at("y").asFloat();
	auto num = CsvUtil::getInstance()->getInt(1, 1, "Tollgate/Player.csv");
	auto hp = CsvUtil::getInstance()->getInt(1, 2, "Tollgate/Player.csv");
	auto atk = CsvUtil::getInstance()->getInt(1, 3, "Tollgate/Player.csv");
	auto speed = CsvUtil::getInstance()->getInt(1, 4, "Tollgate/Player.csv");
	auto bullet = CsvUtil::getInstance()->getInt(1, 5, "Tollgate/Player.csv");
	m_player = Player::create(Tank::createWithNum(num));
	m_player->setAtk(atk);
	m_player->setHP(hp);
	m_player->setTiledMap(map);
	m_player->setSpeed(speed);
	m_player->setBullet(bullet);
	m_player->setMaxHP(hp);
	map->addChild(m_player, 10);
	
	auto moveController = FourDirectionMoveController::create();
	this->addChild(moveController);

	m_player->setController(moveController);
	m_player->setTagPosition(playerX, playerY);

}
开发者ID:revengetank,项目名称:revengeTank,代码行数:28,代码来源:TollgateScene.cpp

示例3: onTouchEnded

void HelloWorld::onTouchEnded(Touch* touch, Event* event){
	TMXObjectGroup* objGroup = tiledMap->getObjectGroup("Obj1");
	ValueVector vv = objGroup->getObjects();
	auto o1 = objGroup->getObject("o1");
	int xxx = o1.at("x").asInt();
	int aa = o1.at("aa").asInt();
	log("xxxx->%d,aa->%d", xxx,aa);
}
开发者ID:rereadyou,项目名称:cocos2dx,代码行数:8,代码来源:HelloWorldScene.cpp

示例4: loadGamePlayer

/*
 *加载游戏玩家
*/
void HelloWorld::loadGamePlayer()
{
    TMXObjectGroup* objGroup = m_gamemap->getObjectGroup("objectlayer");
    ValueMap showPoint = objGroup->getObject("PlayerShowPoint");
    int x = showPoint["x"].asInt();
    int y = showPoint["y"].asInt();

    m_player = Sprite::create("029.png");
    m_player->setPosition(Vec2(x + m_player->getContentSize().width / 2
                               , y + m_player->getContentSize().height / 2));
    m_player->setPosition(m_player->getPosition());
    addChild(m_player);
}
开发者ID:ssss3301,项目名称:TileMap,代码行数:16,代码来源:HelloWorldScene.cpp

示例5: addPlayer

//添加角色
void TollgateScene::addPlayer(TMXTiledMap* map)
{
   // Size visibleSize = Director::getInstance()->getVisibleSize();
    
    

    
    
    //创建精灵
    Sprite* playerSprite = Sprite::create("player.png");
    
    
    //讲精灵绑定到对象
    Player* mPlayer = Player::create();
    mPlayer->BindSprite(playerSprite);
    mPlayer->run();
    
    //加载对象层
    TMXObjectGroup* objGroup = map->getObjectGroup("objects");
    
    //加载玩家对象坐标
    
    ValueMap playerPointMap = objGroup->getObject("PlayerPoint");
    
    float playerX = playerPointMap.at("x").asFloat();
    float PlayerY = playerPointMap.at("y").asFloat();
    
    
    
    //设置玩家坐标
    mPlayer->setPosition(Point(playerX,PlayerY));
    
    
    //将玩家添加到地图
    map->addChild(mPlayer);
    
    
    //创建简单的玩家控制器
    SimpleMoveController* simpleMoveControll = SimpleMoveController::create();
    
    
    //设置速度
    simpleMoveControll->setiSpeed(1);
    
    this->addChild(simpleMoveControll);
    
    mPlayer->setController(simpleMoveControll);    

}
开发者ID:wowiwj,项目名称:cocos2dx,代码行数:50,代码来源:TollgateScene.cpp

示例6: init

bool GameScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    if(NULL==map){
        map=TMXTiledMap::create("map/map1.tmx");
    }
    //map->setScale(2);
    addChild(map);

    TMXObjectGroup *objects = map->getObjectGroup("player");
    CCASSERT(NULL != objects, "'Objects' object group not found");
    auto spawnPoint = objects->getObject("playerinit");
    CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
    int x = spawnPoint["x"].asInt();
    int y = spawnPoint["y"].asInt();
    Player * player = new Player();
    global->player=player;
    global->map=map;
    player->setPosition(Vec2(x,y));
    addChild(player,2);
    //player->sprite->runAction(RepeatForever::create(Animate::create(global->createAni(player->texture, 3))));
    TMXObjectGroup *object2=map->getObjectGroup("Event");
    auto transitionpoint=object2->getObject("transitionEvent");
    int x1=transitionpoint["x"].asInt();
    int y1=transitionpoint["y"].asInt();
    transitionPosition=Vec2(x1,y1);
    //CCLOG("over");
    this->runAction(CCFollow::create(player,CCRectMake(0,0,map->getContentSize().width,map->getContentSize().height)));
    schedule(schedule_selector(GameScene::updateEvent), 0.1);
    return true;

}
开发者ID:dingyp,项目名称:MyGame,代码行数:40,代码来源:GameScene.cpp

示例7: init

bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }

	// Add sounds/effect
	SimpleAudioEngine::getInstance()->preloadEffect("error.mp3");
	SimpleAudioEngine::getInstance()->preloadEffect("item.mp3");
	SimpleAudioEngine::getInstance()->preloadEffect("step.mp3");
	SimpleAudioEngine::getInstance()->preloadEffect("wade.mp3");
	SimpleAudioEngine::getInstance()->playBackgroundMusic("background.mp3");
	SimpleAudioEngine::getInstance()->setBackgroundMusicVolume(0.1);

	// Load the tile map
    std::string file = "01.tmx";
    auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
    _tileMap = TMXTiledMap::createWithXML(str->getCString(),"");
    _background = _tileMap->layerNamed("Background");
	_foreground = _tileMap->layerNamed("Foreground01");
	_layer01 = _tileMap->layerNamed("Layer01");
	_layer02 = _tileMap->layerNamed("Layer02");
	_layer03 = _tileMap->layerNamed("Layer03");
	_cross = _tileMap->layerNamed("CanCross01");
	_cross->setVisible(false);
	_blockage = _tileMap->layerNamed("Blockage01");
	_blockage->setVisible(false);
	
	addChild(_tileMap, -1);

	// Position of the player
	TMXObjectGroup *objects = _tileMap->getObjectGroup("Object-Player");
	CCASSERT(NULL != objects, "'Object-Player' object group not found");
	
	auto playerShowUpPoint = objects->getObject("PlayerShowUpPoint");
	CCASSERT(!playerShowUpPoint.empty(), "PlayerShowUpPoint object not found");

	int x = playerShowUpPoint["x"].asInt();
	int y = playerShowUpPoint["y"].asInt();

	_player = Sprite::create("029.png");
	_player->setPosition(x + _tileMap->getTileSize().width / 2, y + _tileMap->getTileSize().height / 2);
	_player->setScale(0.5);

	addChild(_player);

	setViewPointCenter(_player->getPosition());

	// Position of the enemy
	for (auto& eSpawnPoint: objects->getObjects()){
		ValueMap& dict = eSpawnPoint.asValueMap();
		if(dict["Enemy"].asInt() == 1){
			x = dict["x"].asInt();
			y = dict["y"].asInt();
			this->addEnemyAtPos(Point(x, y));
		}
	}


	// Event listener touch
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [&](Touch *touch, Event *unused_event)->bool {return true;};
	listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
	this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	_numCollected = 0;
	_mode = 0;

	this->schedule(schedule_selector(HelloWorld::testCollisions));
	return true;
}
开发者ID:MercuryRozen,项目名称:Old-World-In-Blue,代码行数:72,代码来源:HelloWorldScene.cpp

示例8: init

bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    

    _tileMap = TMXTiledMap::create("ai_map.tmx");
    //_tileMap->initWithTMXFile("ai_map.tmx");
    _background = _tileMap->getLayer("Background");
    
    _foreground_1 = _tileMap->getLayer("Foreground_1");
    _foreground_2 = _tileMap->getLayer("Foreground_2");
    _meta = _tileMap->getLayer("Meta");
    _meta->setVisible(false);
    
    this->addChild(_tileMap);
    
    
    TMXObjectGroup *objectGroup = _tileMap->getObjectGroup("Objects");
    CCASSERT(NULL != objectGroup, "SpawnPoint object not found");
    auto spawnPoint = objectGroup->getObject("SpawnPoint");
    CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
    //CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
    
    //int x = ((CCString)spawnPoint.valueForKey("x")).intValue();
    //int y = ((CCString)spawnPoint.valueForKey("y")).intValue();
    int x = spawnPoint["x"].asInt();
    int y = spawnPoint["y"].asInt();
    
    // player
    _player = Sprite::create("egg.png");
    _player->setTag(5);
    _player->setPosition(x,y);
    addChild(_player);
    setViewPointCenter(_player->getPosition());
    
    // patrol enemy
    searching_enemy = Enemys::createWithLayer(this);
    searching_enemy->setGameLayer(this);
    auto enemy = objectGroup->getObject("EnemySpawn1");
    int x_1 = enemy["x"].asInt();
    int y_1 = enemy["y"].asInt();
    addEnemyAtPos(Point(x_1,y_1));
    _enemies.pushBack(searching_enemy);
    
    // archer
    archer = Sprite::create("Kiwi.png");
    archer->setPosition(positionForTileCoord(Point(12, 4)));
    archer->setTag(23);
    archer->setScale(1.0);
    this->addChild(archer,1);
    _enemies.pushBack(archer);
    
    //boss
    boss = Sprite::create("patrol.png");
    boss->setPosition(positionForTileCoord(Point(26,9)));
    boss->setTag(26);
    boss->setScale(1.7);
    this->addChild(boss);

    _enemies.pushBack(boss);
    
    //a princess
    princess = Sprite::create("Princess.png");
    princess->setPosition(positionForTileCoord(Point(28, 10)));
    princess->setScale(0.6);
    this->addChild(princess);
    
    
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    listener->onTouchBegan     = [&](Touch* touch, Event* unused_event)->bool { return true;  };
    listener->onTouchEnded     = CC_CALLBACK_2(HelloWorld::onTouchEnded, this);
    this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    // a pause button
    auto pauseItem = MenuItemImage::create("pause.png","",CC_CALLBACK_1(HelloWorld::onPause, this));
    auto menu = Menu::create(pauseItem,NULL);
    
    pauseItem->setScale(0.2);
    pauseItem->setPosition(positionForTileCoord(Point(27, 1)));
    
    menu->setPosition(Point::ZERO);
    this->addChild(menu,1,5);

    // add background music
    //CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("SummerNight.wav");
    
    // navigation button:up, down, left and right and an attacking button
    auto left_btn = Sprite::create("left.png");
    left_btn->setScale(0.3);
    left_btn->setPosition(Point(100, 125));
    left_btn->setTag(TAG_LEFT);
    this->addChild(left_btn,1);
    
    auto right_btn = Sprite::create("right.png");
    right_btn->setScale(0.3);
    right_btn->setPosition(Point(250, 125));
//.........这里部分代码省略.........
开发者ID:quanfei,项目名称:ec327-TeamAwesome,代码行数:101,代码来源:HelloWorldScene.cpp

示例9: loadConfig

/*加载资源*/
void ShowLayer::loadConfig(int level)
{
	Size visibleSize = Director::getInstance()->getVisibleSize();
	m_Level = level;

	//初始化随机种子
	randNum();

	if (level == 3)
	{
		int rand = CCRANDOM_0_1() * 5;

		//加载地图资源
		m_Map = CCTMXTiledMap::create("LastMap2.tmx");

		m_MaxLength = 1600;
		m_MinLength = 0;

		//获取地图上player的坐标
		TMXObjectGroup* objGoup = m_Map->getObjectGroup("playerPoint");
		ValueMap playerPointMap = objGoup->getObject("Player");

		float playerX = playerPointMap.at("x").asFloat();
		float playerY = playerPointMap.at("y").asFloat();

		//创建playerManager
		m_PlayerManager = PlayerManager::createWithLevel(Vec2(playerX, playerY + 24), level);
		m_PlayerManager->setPosition(Vec2(0, 0));
		m_Map->addChild(m_PlayerManager, 3);

		//获取地图上怪物坐标
		TMXObjectGroup* mobjGoup = m_Map->getObjectGroup("monsterPoint");
		ValueVector monsterPoints = mobjGoup->getObjects();

		//ValueMap monsterPoint = mobjGoup->getObject("monster1");

		//float monsterX = monsterPoint.at("x").asFloat();
		//float monsterY = monsterPoint.at("y").asFloat();

		PhyscisWorld::createWorld(m_Map, level);

		//创建monsterManager
		m_MonsterManager = MonsterManager::createWithLevel(monsterPoints, level);    //change
		m_MonsterManager->setAnchorPoint(Vec2(0, 0));
		m_MonsterManager->setPosition(Vec2(0, 0));
		m_Map->addChild(m_MonsterManager, 2);

		TMXObjectGroup* bobjGoup = m_Map->getObjectGroup("Boss");
		ValueMap bossPoint = bobjGoup->getObject("boss");

		float bossPointX = bossPoint.at("x").asFloat();
		float bossPointY = bossPoint.at("y").asFloat();

		m_BossManager = BossManager::createWithLevel(Vec2(bossPointX, bossPointY), level);
		m_BossManager->setAnchorPoint(Vec2(0, 0));
		m_BossManager->setPosition(Vec2(0, 0));
		m_BossManager->setBOrigin(Vec2(bossPointX, bossPointY));
		m_Map->addChild(m_BossManager, 2);

		//m_boss->setOrigin(Vec2(bossPointX, bossPointY));
		//m_boss->setPosition(Vec2(bossPointX, bossPointY));
		//this->addChild(m_boss, 3);
		m_GodArmManager = GodArmManager::createWithLevel(1, m_PlayerManager, m_MonsterManager, m_BossManager);
		m_GodArmManager->setPosition(Vec2(0, 0));
		m_Map->addChild(m_GodArmManager, 4);

		m_GodArmManager->runPower();

		this->schedule(schedule_selector(ShowLayer::Monsterlogic), 0.1f);
		this->schedule(schedule_selector(ShowLayer::logic), 1 / 20.0f);
		this->schedule(schedule_selector(ShowLayer::Bosslogic), 1.0f);
		//认领地图
		this->addChild(m_Map, 0, 1);
	}
}
开发者ID:zsn6493,项目名称:EATFUZI,代码行数:76,代码来源:ShowLayer.cpp

示例10: onEnter

void GameLayer::onEnter()
{
	Layer::onEnter();

	auto visibleSize = Director::getInstance()->getVisibleSize();
	this->m_origin = Director::getInstance()->getVisibleOrigin();



	

	m_pTiledMap = TMXTiledMap::create("TYCHEs_COFEE.tmx");
	m_TiledMapSize.setSize(m_pTiledMap->getMapSize().width * m_pTiledMap->getTileSize().width, m_pTiledMap->getMapSize().height * m_pTiledMap->getTileSize().height);
	this->addChild(m_pTiledMap);

	

	TMXObjectGroup *objects = m_pTiledMap->getObjectGroup("Objects");
	CCASSERT(NULL != objects, "'Objects' object group not found");

	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("hero.plist");

	
	auto spawnPoint = objects->getObject("SpawnPoint");
	CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
	Point heroInitPos = m_origin + Point(spawnPoint["x"].asFloat(), spawnPoint["y"].asFloat());
	m_pHero = Hero::create();
	m_pHero->setScale(0.5f);
	m_pHero->setPosition(heroInitPos);
	m_pHero->runIdleAction();
	m_pHero->setLocalZOrder(visibleSize.height - m_pHero->getPositionY());
	m_pHero->setHP(100);
	m_pHero->setIsAttacking(false);
	m_pHero->setJumpStage(0);
	m_pHero->onDeadCallback = CC_CALLBACK_0(GameLayer::onHeroDead, this, m_pHero);
	m_pHero->attack = CC_CALLBACK_0(GameLayer::onHeroAttack, this);
	m_pHero->stop = CC_CALLBACK_0(GameLayer::onHeroStop, this);
	m_pHero->walk = CC_CALLBACK_1(GameLayer::onHeroWalk, this);
	m_pHero->jump = CC_CALLBACK_1(GameLayer::onHeroJump, this);
	this->addChild(m_pHero);
	auto centerOfView = Point(visibleSize.width / 2, visibleSize.height / 2);
	this->setPosition(centerOfView - m_pHero->getPosition());

	m_pForesight = Foresight::create();
	this->addChild(m_pForesight);

	JsonParser* parser = JsonParser::createWithFile("Debug.json");
	parser->decodeDebugData();
	auto list = parser->getList();
	for (auto& v : list)
	{
		ValueMap row = v.asValueMap();

		for (auto& pair : row)
		{
			CCLOG("%s %s", pair.first.c_str(), pair.second.asString().c_str());
			if (pair.first.compare("HeroHSpeed") == 0)
			{
				float s = pair.second.asFloat();
				m_pHero->setWalkVelocity(s);
			}
			else if (pair.first.compare("HeroVSpeed") == 0)
			{
				m_pHero->setJumpVelocity(pair.second.asFloat());
			}
			else if (pair.first.compare("BulletPower") == 0)
			{
				m_pHero->setBullletPower(pair.second.asInt());
			}
			else if (pair.first.compare("BulletSpeed") == 0)
			{
				m_pHero->setBulletLaunchVelocity(pair.second.asFloat());
			}
			else if (pair.first.compare("BulletDisappearTime") == 0)
			{
				m_pHero->setBulletDisappearTime(pair.second.asFloat());
			}
			else if (pair.first.compare("BulletAngle") == 0)
			{
				m_pHero->setBullletAngle(pair.second.asInt());
			}
			else if (pair.first.compare("BulletInterval") == 0)
			{
				m_pHero->setBulletInterval(pair.second.asFloat());
			}
			else if (pair.first.compare("WorldG") == 0)
			{
				//getScene()->getPhysicsWorld()->setGravity(Vec2(0.f, pair.second.asFloat()));
			}
			else if (pair.first.compare("ForesightSpeed") == 0)
			{
				initForesight(pair.second.asFloat());
			}
			else if (pair.first.compare("AmmoCapacity") == 0)
			{
				m_pHero->setMaxAmmoCapacity(pair.second.asInt());
				m_pHero->setAmmoCapacity(pair.second.asInt());
			}
		}
	}
//.........这里部分代码省略.........
开发者ID:jeffcai8888,项目名称:SpaceX,代码行数:101,代码来源:GameLayer.cpp

示例11: onEnter

void PlayMapSix::onEnter() {
	Layer::onEnter();

	bisover = false;
	//visibleSize,屏幕尺寸
	visibleSize = Director::getInstance()->getVisibleSize();

	//添加碰撞监听器
	contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = CC_CALLBACK_1(PlayMapSix::onContactBegin, this);
	contactListener->onContactPostSolve = CC_CALLBACK_2(PlayMapSix::onContactPostSolve, this);
	contactListener->onContactPreSolve = CC_CALLBACK_2(PlayMapSix::onContactPreSolve, this);
	contactListener->onContactSeparate = CC_CALLBACK_1(PlayMapSix::onContactSeparate, this);
	//事件分发器
	auto eventDispatcher = Director::getInstance()->getEventDispatcher();
	eventDispatcher->addEventListenerWithSceneGraphPriority(contactListener, this);

	//网格地图
	auto winSize = Director::getInstance()->getWinSize();
	//map00瓦片地图地图
	tilemap = TMXTiledMap::create("map/map6.tmx");
	tilemap->setAnchorPoint(Vec2(0,0));
	tilemap->setPosition(Vec2(0,0));
	//auto group = tilemap->getObjectGroup("objects");
	this->addChild(tilemap,-1);

	TMXObjectGroup *objects = tilemap->getObjectGroup("objLayer");
	CCASSERT(NULL != objects, "'Objects' object group not found");
	auto spawnPoint = objects->getObject("hero");
	CCASSERT(!spawnPoint.empty(), "SpawnPoint object not found");
	print_x = spawnPoint["x"].asInt();
	print_y = spawnPoint["y"].asInt();


	TMXLayer* layer = tilemap->getLayer("collideLayer");//从map中取出“bricks”图层
	//这个循环嵌套是为了给每个砖块精灵设置一个刚体
	int count = 0; 
	for (int y = 0; y<TMX_HEIGHT; y++)
	{
		log("xxxxxxxxxxxxxxxxxxxx:%d", y); int groundcounter = 0; int deadlinecounter = 0; int dispearcounter = 0; int bodycounter = 0;
		Point groundpoint, deadlinepoint, dispearpoint, bodypoint; Size groundsize, deadlinesize, dispearsize, bodysize;
		for (int x = 0; x<TMX_WIDTH; x++)
		{

			int gid = layer->getTileGIDAt(Vec2(x, y));
			Sprite* sprite = layer->getTileAt(Vec2(x, y));//从tile的坐标取出对应的精灵

			if (gid == GROUND_GID) {

				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (groundcounter == 0) {
					groundpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					groundsize = sprite->getContentSize();
					log("groundcounter==0");
				}
				groundcounter++; log("groundcounter=%d", groundcounter);

			}
			else {
				if (groundcounter != 0) {
					log("make execute!");
					groundsize = Size(groundsize.width*groundcounter, groundsize.height);
					log("point=%f  %f,size=%f  %f", groundpoint.x, groundpoint.y, groundsize.width, groundsize.height);
					this->makePhysicsObjAt(groundpoint, groundsize, false, 0, 0.0f, 0.0f, 0, GROUND_GID, -1);
				}
				groundcounter = 0;
			}/////////////////
			if (gid == DEAD_LINE_GID) {

				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (deadlinecounter == 0) {
					deadlinepoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					deadlinesize = sprite->getContentSize();
					log("groundcounter==0");
				}
				deadlinecounter++; log("groundcounter=%d", deadlinecounter);

			}
			else {
				if (deadlinecounter != 0) {
					log("make execute!");
					deadlinesize = Size(deadlinesize.width*deadlinecounter, deadlinesize.height);
					log("point=%f  %f,size=%f  %f", deadlinepoint.x, deadlinepoint.y, deadlinesize.width, deadlinesize.height);
					this->makePhysicsObjAt(deadlinepoint, deadlinesize, false, 0, 0.0f, 0.0f, 0, DEAD_LINE_GID, -1);
				}
				deadlinecounter = 0;
			}
			if (gid == CAN_DISPEAR_GID) {
				sprite->setTag(count);
				log("sprite->setTag(%d);", count);
				log("sssssssssss  %f,ppppppppppppp %f", sprite->getPosition().x, sprite->getPosition().y);
				if (dispearcounter == 0) {
					dispearpoint = Point(sprite->getPosition().x, sprite->getPosition().y);
					dispearsize = sprite->getContentSize();
					log("groundcounter==0");
				}
				dispearcounter++; log("groundcounter=%d", dispearcounter);

			}
			else {
//.........这里部分代码省略.........
开发者ID:MulticsYin,项目名称:Archer-cocos2d-x,代码行数:101,代码来源:PlayMapSix.cpp

示例12: init

// on "init" you need to initialize your instance
bool TileMap::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    _visibleSize = visibleSize;
    _origin = origin;

    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(TileMap::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));
    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);

    auto label = LabelTTF::create("TileMap", "Arial", 24);
    label->setPosition(Vec2(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);


    _tileMap = TMXTiledMap::create("bg_TileMap.tmx");
	_tileMap->setPosition(Vec2(0,0));
//    _tileMap->setScale(_visibleSize.width/_tileMap->getContentSize().width,_visibleSize.height/_tileMap->getContentSize().height);
	_tileMap->setVisible(true);
    _background = _tileMap->layerNamed("bg");
    _collidable =  _tileMap->layerNamed("Meta");
	_collidable->setVisible(false);
	Director::getInstance()->setProjection(Director::Projection::_2D);
	this->addChild(_tileMap, 0, 50);

	TMXObjectGroup *group = _tileMap->getObjectGroup("Objects");
	ValueMap spawnPoint = group->getObject("SpawnPoint");
	float x = spawnPoint["x"].asFloat();
	float y = spawnPoint["y"].asFloat();

//	ActorManager::getInstance()->_actorTarget = new Vector<Actor*>(50);
//	ActorManager::getInstance()->_monsterTarget = Vector<Actor*>(50);
	_actor = Actor::create();
	_player = Sprite::create("ninja.png");
	_player->setTag(100);
	_player->setPosition(Vec2(x,y));
//	_posInScreen = Vec2(x,y);
	this->addChild(_player, 2);
	auto bld = new ActorBlood(100);
	_actor->setActorSprite(_player);
	_actor->setActorTag(1);
	_actor->setActorBlood(bld);
	ActorManager::getInstance()->_actorTarget.pushBack(_actor);

	_collision = new CollisionBlood(this, ActorManager::getInstance()->_monsterTarget);
	for (int i=1; i<6; i++) {
		ValueMap point = group->getObject("target"+Value(i).asString());
		float x = point["x"].asFloat();
		float y = point["y"].asFloat();
		std::string str = "BasiliskBrown.PNG";
		_collision->addTarget(Vec2(x,y), str);
	}


	/*
	 * screen Touch
	 */
	_listener = EventListenerTouchOneByOne::create();
	_listener->onTouchBegan = CC_CALLBACK_2(TileMap::onTouchBegan,this);
	_listener->onTouchMoved = CC_CALLBACK_2(TileMap::onTouchMoved,this);
	_listener->onTouchEnded = CC_CALLBACK_2(TileMap::onTouchEnded,this);
	_listener->setSwallowTouches(true);//²»ÏòÏ´«µÝ´¥Ãþ
	_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener,this);
	//_listener->setEnabled(false);

	/*
	 * AstartPathFinding
	 */
	AstartPathFinding* astart = new AstartPathFinding(_tileMap->getMapSize().width, _tileMap->getMapSize().height);
	_astart = astart;
	astart->mapInit();
	for (int i=0; i<_tileMap->getMapSize().width; i++)
		for (int j=0; j<_tileMap->getMapSize().height; j++) {
			if (checkNodePassable(Vec2(i,_tileMap->getMapSize().height-j-1)) == false)
				astart->getMap(i,j)->setPassable(false);
		}

//	for (int i=0; i<_tileMap->getMapSize().width; i++)
//		for (int j=0; j<_tileMap->getMapSize().height; j++)  {
//			log("checkNodePassable_[%d][%d] =  %d",i, j,_astart->getMap(i,j)->getPassable());
//		}
//	log("_tileMap->getMapSize().width = %f",_tileMap->getMapSize().width);
//	log("_tileMap->getMapSize().height = %f",_tileMap->getMapSize().height);

//.........这里部分代码省略.........
开发者ID:sevenzou,项目名称:cocos2dx_astart,代码行数:101,代码来源:TileMap.cpp


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