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


C++ TMXLayer::getTileAt方法代码示例

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


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

示例1: 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

示例2: tryMovePlayer

void GameMap::tryMovePlayer(Vec2 toPos) {
	//禁止移动事项
	if (isShowDialogue){ return; }

	Vec2 coor = getTileCoordinateAt(toPos - getMapLeftBottomPos());
	Size mapSize = this->_map->getMapSize();

	if (coor.x >= mapSize.width || coor.x < 0 || coor.y >= mapSize.height || coor.y < 0){
		return;//要到达目标在地图外
	}

	TMXLayer* blockLayer = _map->getLayer("block");
	if (blockLayer != NULL &&  blockLayer->getTileAt(coor) != NULL){
		return;//要到达的目标有障碍物
	}

	ValueMap inspectObject = getInspectObjectAt(toPos);
	if (inspectObject != ValueMapNull && inspectObject["isBlock"].asBool() == true){
		return;//当要到达的位置有可以调查的物体且该物体属性为可以被阻挡时
	}

	_player->setPosition(toPos);
}
开发者ID:moonrailgun,项目名称:WhiteWorld-cocos2dx,代码行数:23,代码来源:GameMap.cpp

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


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