本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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,
//.........这里部分代码省略.........
示例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);
}
//.........这里部分代码省略.........