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


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

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


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

示例1: init

bool CityScene::init()
{
    Layer::init();

    char szRound[260];
    sprintf(szRound, "Round%d.tmx", mRound);
    TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound);
    TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap();
    this->addChild(tmxTileMap);

    mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo);

    mPlayerTank[0]->setObjType(PlayerTank);
    mPlayerTank[0]->getBullet();


    Size tileSize = tmxTileMap->getTileSize();
    Size mapSize = tmxTileMap->getContentSize();
    mPlayerTank[0]->setPosition(Point(mapSize.width / 2 - tileSize.width * 3, tileSize.height));

//
    mLayerPanel = Panel::create();
    addChild(mLayerPanel, 3);
//
    mEnemyAI = EnemyAI::createEnemyAIWithTank(mPlayerTank[0]);

    return true;
}
开发者ID:jypeitao,项目名称:Cocosdx-tk,代码行数:28,代码来源:CityScene.cpp

示例2: addChild

//------------------------------------------------------------------
//
// TMXOrthoTest
//
//------------------------------------------------------------------
TMXOrthoTest::TMXOrthoTest()
{
    //
    // Test orthogonal with 3d camera and anti-alias textures
    //
    // it should not flicker. No artifacts should appear
    //
    //CCLayerColor* color = LayerColor::create( ccc4(64,64,64,255) );
    //addChild(color, -1);

    TMXTiledMap* map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
    addChild(map, 0, kTagTileMap);
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
    
    Array * pChildrenArray = map->getChildren();
    SpriteBatchNode* child = NULL;
    Object* pObject = NULL;
    CCARRAY_FOREACH(pChildrenArray, pObject)
    {
        child = (SpriteBatchNode*)pObject;

        if(!child)
            break;

        child->getTexture()->setAntiAliasTexParameters();
    }
开发者ID:bassarisse,项目名称:LostInCaves,代码行数:33,代码来源:TileMapTest.cpp

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

示例4: init

bool MapLayer::init()
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(!Layer::init());

        Size winSize = Director::getInstance()->getWinSize();

        // 初始化地图
        TMXTiledMap* map = TMXTiledMap::create("iso-test-zorder.tmx");
        map->setPosition((winSize.width - map->getContentSize().width)/2, 0);
        this->addChild(map, 0, kTagTileMap);

        // 初始化任务
        _tamara = Sprite::create("grossinis_sister1.png");
        map->addChild(_tamara, map->getChildren().size());
        _tamara->retain();
        int mapWidth = map->getMapSize().width * map->getTileSize().width;
        int mapHeight = map->getMapSize().height * map->getTileSize().height;
        _tamara->setPosition(mapWidth/2, 112);
        _tamara->setAnchorPoint(Point(0.5f, 0));
        

        _vmove = -1;
        _hmove = -1;
        _stepIndex = -1;
        _myAstar = new Astar();

        this->scheduleUpdate();

        auto listener = EventListenerTouchOneByOne::create();
        listener->onTouchBegan = CC_CALLBACK_2(MapLayer::onTouchBegan, this);
        this->_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

        bRet = true;
    } while (0);

    return bRet;
}
开发者ID:suli1,项目名称:suli1-myGame,代码行数:41,代码来源:MapLayer.cpp

示例5: init

bool CityScene::init() {
    if (!Layer::init()) {
        return false;
    }
    
    char szRound[260];
    sprintf(szRound, "Round%d.tmx", mRound);
    TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound);
    TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap();
    this->addChild(tmxTileMap);
    
    mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo);
    
    
    Size tileSize = tmxTileMap->getTileSize();
    Size mapSize = tmxTileMap->getContentSize();
    mPlayerTank[0]->setPosition(Vec2(mapSize.width / 2 - tileSize.width * 3, tileSize.height));
    
    mLayerPanel = Panel::create();
    addChild(mLayerPanel, 3);
    
    return true;
}
开发者ID:wsbjwjt,项目名称:TanksWar,代码行数:23,代码来源:CityScene.cpp

示例6: createNodeWithFlatBuffers


//.........这里部分代码省略.........
                 errorFilePath = path;
                 fileExist = false;
             }
             break;
         }
             
         default:
             break;
     }
     if (fileExist)
     {
         /* Whether tileset is valid. */
         auto mapInfo = TMXMapInfo::create(path);
         auto& layers = mapInfo->getLayers();
         bool valid = false;
         std::string layerName = "";
         for (const auto &layerInfo : layers)
         {
             valid = false;
             
             if (layerInfo->_visible)
             {
                 Size size = layerInfo->_layerSize;
                 auto& tilesets = mapInfo->getTilesets();
                 if (tilesets.size()>0)
                 {
                     TMXTilesetInfo* tileset = nullptr;
                     for (auto iter = tilesets.crbegin(); iter != tilesets.crend(); ++iter)
                     {
                         tileset = *iter;
                         if (tileset)
                         {
                             for( int y=0; y < size.height; y++ )
                             {
                                 for( int x=0; x < size.width; x++ )
                                 {
                                     int pos = static_cast<int>(x + size.width * y);
                                     int gid = layerInfo->_tiles[ pos ];
                                     
                                     if( gid != 0 )
                                     {
                                         if( (gid & kTMXFlippedMask) >= tileset->_firstGid )
                                         {
                                             valid = true;
                                             break;
                                         }
                                     }
                                 }
                                 
                                 if (valid)
                                 {
                                     break;
                                 }
                             }
                         }
                     }
                 }
                 
                 if (!valid)
                 {
                     layerName = layerInfo->_name;
                     break;
                 }
             }
             else
             {
                 valid = true;
             }
         }
         
         if (!valid)
         {
             Node* node = Node::create();
             setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
             auto label = Label::create();
             label->setString(__String::createWithFormat("Some error of gid are in TMX Layer '%s'", layerName.c_str())->getCString());
             node->setScale(1.0f);
             node->addChild(label);
             return node;
         }
         /**/
         
         tmx = TMXTiledMap::create(path);
         if (tmx)
         {
             //prevent that editor's data does not match in size and resources
             Size fileSize = tmx->getContentSize();
             setPropsWithFlatBuffers(tmx, (Table*)gameMapOptions);
             tmx->setContentSize(fileSize);
         }
     }
     else
     {
         Node* node = Node::create();
         setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
         return node;
     }
     
     return tmx;
 }
开发者ID:602147629,项目名称:PlanetWar,代码行数:101,代码来源:GameMapReader.cpp

示例7:

PushBoxScene::PushBoxScene()
{
    TMXTiledMap* mytmx = TMXTiledMap::create("Pushbox/map.tmx");
    mytmx->setPosition(visibleSize.width / 2, visibleSize.height / 2);
    mytmx->setAnchorPoint(Vec2(0,0));
    myx = (visibleSize.width - mytmx->getContentSize().width) / 2;
    myy = (visibleSize.height - mytmx->getContentSize().height) / 2;
    this->addChild(mytmx, 0);

    count = 0;
    success = 0;
    /*mon = Sprite::create("Pushbox/player.png");
    mon->setAnchorPoint(Vec2(0, 0));
    mon->setPosition(Vec2(SIZE_BLOCK*1+myx, SIZE_BLOCK*8+myy));
    mon->setTag(TAG_PLAYER);
    this->addChild(mon, 1);*/



    TMXObjectGroup* objects = mytmx->getObjectGroup("wall");
    //从对象层中获取对象数组
    ValueVector container = objects->getObjects();
    //遍历对象
    for (auto obj : container) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/wall.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x,y+64));
        mywall.pushBack(temp);
        this->addChild(temp, 1);
    }

    TMXObjectGroup* objects1 = mytmx->getObjectGroup("box");
    //从对象层中获取对象数组
    ValueVector container1 = objects1->getObjects();
    //遍历对象
    for (auto obj : container1) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/box.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mybox.pushBack(temp);
        this->addChild(temp, 3);
    }

    TMXObjectGroup* objects2 = mytmx->getObjectGroup("player");
    //从对象层中获取对象数组
    ValueVector container2 = objects2->getObjects();
    //遍历对象
    for (auto obj : container2) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/player.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mon = temp;
        this->addChild(temp, 2);
    }

    TMXObjectGroup* objects3 = mytmx->getObjectGroup("goal");
    //从对象层中获取对象数组
    ValueVector container3 = objects3->getObjects();
    //遍历对象
    for (auto obj : container3) {
        ValueMap values = obj.asValueMap();
        int x = values.at("x").asInt();
        int y = values.at("y").asInt();
        Sprite* temp = Sprite::create("Pushbox/goal.png");
        temp->setAnchorPoint(Point(0, 0));
        temp->setPosition(Point(x, y+64));
        mygoal.pushBack(temp);
        this->addChild(temp, 1);
    }
}
开发者ID:Coding-Le,项目名称:SE-Cocos2d-Course,代码行数:79,代码来源:PushBoxScene.cpp


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