• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TMXMapInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CCASSERT

bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile, bool isHalf)
{
    CCASSERT(tmxFile.size()>0, "FastTMXTiledMap: tmx file should not be empty");
    
    setContentSize(Size::ZERO);

    TMXMapInfo *mapInfo = TMXMapInfo::create(tmxFile);

    if (! mapInfo)
    {
        return false;
    }
    CCASSERT( !mapInfo->getTilesets().empty(), "FastTMXTiledMap: Map not found. Please check the filename.");
    
    if (isHalf) {
        Size size = mapInfo->getTileSize();
        mapInfo->setTileSize(Size(size.width/2, size.height/2));
        Vector<TMXTilesetInfo*> vec = mapInfo->getTilesets();
        for (int i=0; i<vec.size(); i++) {
            TMXTilesetInfo* tilesetInfo = vec.at(i);
            tilesetInfo->_tileSize.width /= 2;
            tilesetInfo->_tileSize.height /= 2;
            tilesetInfo->_imageSize.width /= 2;
            tilesetInfo->_imageSize.height /= 2;
        }
    }
    
    buildWithMapInfo(mapInfo);

    return true;
}
开发者ID:mixiancheng,项目名称:selfWork,代码行数:31,代码来源:CCFastTMXTiledMap.cpp


示例2: new

TMXMapInfo * TMXMapInfo::createWithXML(const std::string& tmxString, const std::string& resourcePath)
{
    TMXMapInfo *ret = new (std::nothrow) TMXMapInfo();
    if (ret->initWithXML(tmxString, resourcePath))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return nullptr;
}
开发者ID:114393824,项目名称:Cocos2dxShader,代码行数:11,代码来源:CCTMXXMLParser.cpp


示例3: setContentSize

bool TMXTiledMap::initWithXML(const std::string& tmxString, const std::string& resourcePath)
{
    setContentSize(Size::ZERO);

    TMXMapInfo *mapInfo = TMXMapInfo::createWithXML(tmxString, resourcePath);

    CCASSERT( !mapInfo->getTilesets().empty(), "FastTMXTiledMap: Map not found. Please check the filename.");
    buildWithMapInfo(mapInfo);

    return true;
}
开发者ID:mixiancheng,项目名称:selfWork,代码行数:11,代码来源:CCFastTMXTiledMap.cpp


示例4: CC_UNUSED_PARAM

void TMXMapInfo::textHandler(void *ctx, const char *ch, int len)
{
    CC_UNUSED_PARAM(ctx);
    TMXMapInfo *tmxMapInfo = this;
    std::string text(ch, 0, len);

    if (tmxMapInfo->isStoringCharacters())
    {
        std::string currentString = tmxMapInfo->getCurrentString();
        currentString += text;
        tmxMapInfo->setCurrentString(currentString);
    }
}
开发者ID:114393824,项目名称:Cocos2dxShader,代码行数:13,代码来源:CCTMXXMLParser.cpp


示例5: CCASSERT

bool TMXTiledMap::initWithTMXFile(const std::string& tmxFile)
{
    CCASSERT(tmxFile.size()>0, "FastTMXTiledMap: tmx file should not be empty");
    
    setContentSize(Size::ZERO);

    TMXMapInfo *mapInfo = TMXMapInfo::create(tmxFile);

    if (! mapInfo)
    {
        return false;
    }
    CCASSERT( !mapInfo->getTilesets().empty(), "FastTMXTiledMap: Map not found. Please check the filename.");
    buildWithMapInfo(mapInfo);

    return true;
}
开发者ID:Ratel13,项目名称:WarriorQuest,代码行数:17,代码来源:CCFastTMXTiledMap.cpp


示例6: CC_CALLBACK_1

// on "init" you need to initialize your instance
bool GamePlaying::init()
{
	_trans=false;
	_tag=0;
	//////////////////////////////
	// 1. super init first
	if ( !Layer::init() )
	{
	return false;
	}
    
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();
	
	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
	
	auto closeItem = MenuItemImage::create(
						"CloseNormal.png",
						"CloseSelected.png",
						CC_CALLBACK_1(GamePlaying::menuCloseCallback, this));
	Vec2 menupos = Vec2(origin.x + visibleSize.width,
				origin.y + closeItem->getContentSize().height/2);
	menupos.x -=closeItem->getContentSize().width/2;
	closeItem->setPosition(menupos);

	
	//リロード
	auto reloadItem = MenuItemImage::create(
		"reload.png",
		"reload.png",
		CC_CALLBACK_1(GamePlaying::menuReloadCallback, this));
	menupos.x =visibleSize.width/2;
	reloadItem->setPosition(menupos);

	//次へ
	auto nextItem = MenuItemImage::create(
		"next.png",
		"next.png",
		CC_CALLBACK_1(GamePlaying::menuNextCallback, this));
	
	menupos.x =visibleSize.width/2 + nextItem->getContentSize().width*2;
	nextItem->setPosition(menupos);


	// create menu, it's an autorelease object
	auto menu = Menu::create(closeItem, reloadItem ,nextItem, nullptr);
	menu->setPosition(Vec2::ZERO);
	this->addChild(menu, 100);

	int priority=0;


	_pm = PHYSICSSHAPE_MATERIAL_DEFAULT;
	_pm.friction = 0.5f;
	_pm.density = 0.5f;
	/////////////////////////////
	// 3. add your codes below...

	//背景
	auto bg = SpriteBatchNode::create("bg.png");
	auto bg2 = SpriteBatchNode::create("bg2.png");
	int i=0,j=0;
	for(int j=0;j<4;++j){
		for(int i=0;i<2;++i){
			auto sp=Sprite::createWithTexture(bg->getTexture());
			sp->setPosition(128+i*256,128+j*256);
			bg->addChild(sp);
			auto sp2=Sprite::createWithTexture(bg2->getTexture());
			sp2->setPosition(128+i*256,128+j*256);
			bg2->addChild(sp2);
			sp2->runAction(RepeatForever::create(Sequence::createWithTwoActions( FadeIn::create(2.5f),FadeOut::create(2.5f) )));
		}
	}
	addChild(bg);
	addChild(bg2);

	

	TMXTiledMap* tiledmap;
	TMXMapInfo* mapinfo;
	if(stage_no==0){
		_slushLimit=10;
		auto label = LabelTTF::create(GetUTF8FromSJIS("チャンスは1度きり…"), "Arial", 24);
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
					origin.y + visibleSize.height - label->getContentSize().height));
		// add the label as a child to this layer
		this->addChild(label, priority++);
		tiledmap = TMXTiledMap::create("stage1.tmx");
		mapinfo = TMXMapInfo::create("stage1.tmx");
	}else if(stage_no==2){
		_slushLimit=2;
		auto label = LabelTTF::create(GetUTF8FromSJIS("チャンスは2回のみだ"), "Arial", 24);
		// position the label on the center of the screen
		label->setPosition(Vec2(origin.x + visibleSize.width/2,
//.........这里部分代码省略.........
开发者ID:boxerprogrammer,项目名称:BlobSlusher,代码行数:101,代码来源:GamePlayingScene.cpp


示例7: CC_UNUSED_PARAM

void TMXMapInfo::endElement(void *ctx, const char *name)
{
    CC_UNUSED_PARAM(ctx);
    TMXMapInfo *tmxMapInfo = this;
    std::string elementName = name;

    if (elementName == "data")
    {
        if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribBase64)
        {
            tmxMapInfo->setStoringCharacters(false);
            
            TMXLayerInfo* layer = tmxMapInfo->getLayers().back();
            
            std::string currentString = tmxMapInfo->getCurrentString();
            unsigned char *buffer;
            auto len = base64Decode((unsigned char*)currentString.c_str(), (unsigned int)currentString.length(), &buffer);
            if (!buffer)
            {
                CCLOG("cocos2d: TiledMap: decode data error");
                return;
            }
            
            if (tmxMapInfo->getLayerAttribs() & (TMXLayerAttribGzip | TMXLayerAttribZlib))
            {
                unsigned char *deflated = nullptr;
                Size s = layer->_layerSize;
                // int sizeHint = s.width * s.height * sizeof(uint32_t);
                ssize_t sizeHint = s.width * s.height * sizeof(unsigned int);
                
                ssize_t CC_UNUSED inflatedLen = ZipUtils::inflateMemoryWithHint(buffer, len, &deflated, sizeHint);
                CCASSERT(inflatedLen == sizeHint, "inflatedLen should be equal to sizeHint!");
                
                free(buffer);
                buffer = nullptr;
                
                if (!deflated)
                {
                    CCLOG("cocos2d: TiledMap: inflate data error");
                    return;
                }
                
                layer->_tiles = reinterpret_cast<uint32_t*>(deflated);
            }
            else
            {
                layer->_tiles = reinterpret_cast<uint32_t*>(buffer);
            }
            
            tmxMapInfo->setCurrentString("");
        }
        else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribCSV)
        {
            unsigned char *buffer;

            TMXLayerInfo* layer = tmxMapInfo->getLayers().back();

            tmxMapInfo->setStoringCharacters(false);
            std::string currentString = tmxMapInfo->getCurrentString();

            vector<string> gidTokens;
            istringstream filestr(currentString);
            string sRow;
            while(getline(filestr, sRow, '\n')) {
                string sGID;
                istringstream rowstr(sRow);
                while (getline(rowstr, sGID, ',')) {
                    gidTokens.push_back(sGID);
                }
            }

            // 32-bits per gid
            buffer = (unsigned char*)malloc(gidTokens.size() * 4);
            if (!buffer)
            {
                CCLOG("cocos2d: TiledMap: CSV buffer not allocated.");
                return;
            }

            uint32_t* bufferPtr = reinterpret_cast<uint32_t*>(buffer);
            for(auto gidToken : gidTokens) {
                auto tileGid = (uint32_t)strtol(gidToken.c_str(), nullptr, 10);
                *bufferPtr = tileGid;
                bufferPtr++;
            }

            layer->_tiles = reinterpret_cast<uint32_t*>(buffer);

            tmxMapInfo->setCurrentString("");
        }
        else if (tmxMapInfo->getLayerAttribs() & TMXLayerAttribNone)
        {
            _xmlTileIndex = 0;
        }
    }
    else if (elementName == "map")
    {
        // The map element has ended
        tmxMapInfo->setParentElement(TMXPropertyNone);
    }    
//.........这里部分代码省略.........
开发者ID:602147629,项目名称:PlanetWar,代码行数:101,代码来源:CCTMXXMLParser.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TMXObjectGroup类代码示例发布时间:2022-05-31
下一篇:
C++ TMXLayer类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap