cocos2dx TiledMap

map = TMXTiledMap::create("mario.tmx");  
this->addChild(map);  
map->setPosition(Point());  
// 图层  
TMXLayer* land = map->layerNamed("land");  
TMXLayer* pipe = map->layerNamed("pipe");  
Value land_property = land->propertyNamed("isVisible");  

std::string str = land_property.asString();  
land_property.asBool();  
land_property.asInt();  

// 对象层  
TMXObjectGroup* pipeGroup = map->objectGroupNamed("pipe");  
//得一个  
ValueMap pipe_1  = pipeGroup->objectNamed("pipe_1");  
std::string pipeStr = pipe_1["name"].asString();  
float pipeX = pipe_1["x"].asFloat();  
float pipeY= pipe_1["y"].asFloat();;  
float pipeWidht = pipe_1["width"].asFloat();  
float pipeHeight = pipe_1["height"].asFloat();  




//得到精灵   
int blockSize = 16;  
Size mapSize= map->getMapSize();  

Sprite* spriteAll = Sprite::create();  
for (int i = 0; i < pipeWidht/blockSize; i++)  
{  
	for (int j = 0; j < pipeHeight/blockSize; j++)  
	{  
		Sprite* pipeSprite = pipe->tileAt(Point(pipeX/blockSize+i,mapSize.height-1-pipeY/blockSize-j));   
		pipeSprite->retain();  
		//pipeSprite->removeFromParent();  
		//spriteAll->addChild(pipeSprite);  
		MoveBy* action = MoveBy::create(1,Point(0,50));  
		MoveBy* actionR = action->reverse();  
		Sequence* seq = Sequence::create(action, actionR, NULL);  
		pipeSprite->runAction(RepeatForever::create(seq));  
	}  
}  

this->addChild(spriteAll);  


//  MoveBy* action = MoveBy::create(1,Point(0,50));  
//  MoveBy* actionR = action->reverse();  
//  Sequence* seq = Sequence::create(action, actionR, NULL);  
//  spriteAll->runAction(RepeatForever::create(seq));  
//得到一组   
ValueVector pipeVector = pipeGroup->getObjects();  
for (auto& child : pipeVector)    
{  
	ValueMap& dict = child.asValueMap();  

	float X = dict["x"].asFloat();  
	float Y= dict["y"].asFloat();;  
	float Widht = dict["width"].asFloat();  
	float Height = dict["height"].asFloat();  
} 

你可能感兴趣的:(cocos2dx TiledMap)