Cocos2d:错误从Cocos2d :: Valuemap到Cocos2d :: CCdictionary的转换函数不存在 [英] Cocos2d: error no suitable conversion function from Cocos2d::Valuemap to Cocos2d::CCdictionary existis
问题描述
我正在关注这个关于在游戏中实现图块贴图的精彩教程 http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1
I'm following this amazing tutorial about implementing tilemaps in my game http://www.raywenderlich.com/39113/cocos2d-x-tile-map-tutorial-part-1
http://www.raywenderlich.com/40544/cocos2d-x-tile-map-tutorial-part-2
但是当我明白这一点时:
But when i get to this:
CCTMXObjectGroup *objectGroup = _tileMap->objectGroupNamed("Objects");
if(objectGroup == NULL){
CCLog("tile map has no objects object layer");
return false;
}
CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
int x = ((CCString)*spawnPoint->valueForKey("x")).intValue();
int y = ((CCString)*spawnPoint->valueForKey("y")).intValue();
_player = new CCSprite();
_player->initWithFile("Player.png");
_player->setPosition(ccp(x,y));
this->addChild(_player);
this->setViewPointCenter(_player->getPosition());
我收到以下错误消息:CCDictionary * spawnPoint = objectGroup-> objectNamed("SpawnPoint");
I get an error on: CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
指出没有函数可以转换此objectGroup.(错误地没有合适的从Cocos2d :: Valuemap到Cocos2d :: CCdictionary的转换函数)
Stating that there is no function to convert this objectGroup. (error no suitable conversion function from Cocos2d::Valuemap to Cocos2d::CCdictionary existis)
从使用的不同cocos版本看,这似乎是一个问题(本教程为v2,我为v3).
This looks like a problem from the diferents cocos' versions used (The tutorial is v2 and i'm v3).
有人知道如何解决此问题吗?
Does anyone knows how to fix this?
推荐答案
为什么不使用自动指针,而是使用常规C ++语法访问返回的无序映射.参见下面的代码示例.
Why don't you use a auto pointer, and access the unordered map returned using the normal C++ syntax. See below for code sample.
auto spawnPoints = objectGroupd->objectNamed("SpawnPoint");
int x = spawnPoints.at("x").asInt();
int y = spawnPoints.at("y").asInt();
这将为您提供raywenderlich教程期望的相同值.
This will get you the same values that the raywenderlich tutorial expects you to have.
这篇关于Cocos2d:错误从Cocos2d :: Valuemap到Cocos2d :: CCdictionary的转换函数不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!