我尝试将http://www.raywenderlich.com/29460/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-2-x-part-2教程转换为cocos2dx并收到错误 在这一行: CCString * collision = properties-> objectForKey(“Collidable”);
void HelloWorld::setPlayerPosition(CCPoint position)
{
CCPoint tileCoord = this->tileCoordForPosition(position);
int tileGid = _meta->tileGIDAt(tileCoord);
if(tileGid)
{
CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
if(properties)
{
CCString *collision = properties->objectForKey("Collidable");
if(collision && (collision->compare("True")))
return;
}
}
_player->setPosition(position);
}
答案 0 :(得分:0)
编译器抱怨丢失了CCString的“const-ness”。 objectForKey方法返回const CCString*
,但您将其分配给CCString*
,这意味着它不再是const
。
有三个选项可以解决这个问题,从最简单的方法开始:
const CCString *collision = properties->objectForKey("Collidable");
CCString *collision = (CCString*)properties->objectForKey("Collidable");
permissive
标志以忽略此错误。不推荐,因为它允许你违反常量。