本文整理汇总了C++中TMXLayer::getTileGIDAt方法的典型用法代码示例。如果您正苦于以下问题:C++ TMXLayer::getTileGIDAt方法的具体用法?C++ TMXLayer::getTileGIDAt怎么用?C++ TMXLayer::getTileGIDAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMXLayer
的用法示例。
在下文中一共展示了TMXLayer::getTileGIDAt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bulletBoom
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);
}
示例2: 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));
}
}
}
}
}
示例3: 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;
}
示例4: 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);
}
}
}
示例5: _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");
// }
}
示例6: 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;
}
示例7: tileAllowMove
bool Global::tileAllowMove(Point MovePoint)
{
TMXLayer *metaLayer = global->tileMap->getLayer("Meta");
Point tileCoord = tilePosFromLocation(MovePoint, global->tileMap);
int tileGid = metaLayer->getTileGIDAt(tileCoord);
if (tileGid)
{
auto properties = tileMap->getPropertiesForGID(tileGid).asValueMap();
if (!properties.empty())
{
auto collision = properties["Collidable"].asString();
if ("True" == collision)
return false;
else
return true;
}
else
return true;
}
return true;
}
示例8: 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 {
//.........这里部分代码省略.........
示例9: openq
std::vector<cocos2d::Vec2> SpriteInMap::findPath(cocos2d::Vec2 src, cocos2d::Vec2 dst)
{
int iter_sin[]={0,1,0,-1};
int iter_cos[]={1,0,-1,0};
struct path_element {
int x,y;
float f,g;
int prev_x,prev_y;
bool closedset;
bool openset;
};
// int prev[(int)map_isize.width][(int)map_isize.height][3]; // 0 prev_x 1 prev_y 2 cost
path_element mapa[(int)map_isize.width][(int)map_isize.height];
for (int i=0;i<(int)map_isize.width;i++)
for (int j=0;j<(int)map_isize.height;j++) {
mapa[i][j].closedset=false;
mapa[i][j].openset=false;
}
//vector<path_element> closed;
priority_queue<path_element*,vector<path_element*>,function<bool(path_element*,path_element*)> > openq( [] (path_element *a, path_element *b) {
return (a->f > b->f);
});
TMXLayer *maplayer = themap->getLayer("main");
//themap->getLayer("selection")->setTileGID(13,Vec2(0,0));
int sx=src.x;
int sy=src.y;
path_element *start = &mapa[sx][sy];
start->x=src.x;
start->y=src.y;
start->g=0;
start->f=0+abs(src.x-dst.x)+abs(src.y-dst.y);
start->openset=true;
openq.push(start);
vector<Vec2> reverse_path;
reverse_path.clear();
while ( !openq.empty() ) {
//cout << "openqueue size: " <<openq.size() <<"\n";
path_element *current = openq.top(); openq.pop();
//cout << "selected ("<<current->x<<","<<current->y<<")\n";
if ( abs(current->x-dst.x)<0.5 && abs(current->y-dst.y)<0.5 ) {
//cout<<"found\n";
path_element *e = current;
do {
reverse_path.push_back(Vec2(e->x,e->y));
e=&mapa[e->prev_x][e->prev_y];
} while (e!=start);
return reverse_path;
}
int cx=(int)current->x;
int cy=(int)current->y;
mapa[cx][cy].closedset=true;
mapa[cx][cy].openset=false;
for (int i=0;i<4;i++) {
int nx=cx+iter_cos[i];
int ny=cy+iter_sin[i];
if (maplayer->getTileGIDAt(Vec2(nx,ny))!=0) continue;
path_element *nb = &mapa[nx][ny];
//cout << "n ("<<nx<<","<<ny<<")\n";
if (nb->closedset) continue;
if (nx<0 || ny<0 || nx>map_isize.width-1 || ny>map_isize.height-1) continue;
if ( (!nb->openset) || (1+current->g<nb->g) ) {
//cout << "changed\n";
nb->x=nx;
nb->y=ny;
nb->g=1+current->g;
nb->f=nb->g+abs(nb->x-dst.x)+abs(nb->y-dst.y);
nb->prev_x=cx;
nb->prev_y=cy;
if (!nb->openset) openq.push(nb);
nb->openset=true;
// cout<<"f: "<<nb->g<<" g: "<<nb->f<<" \n";
}
}
}
return reverse_path;
}