【问题标题】:formatWithString: Cocos2d-x passing in a CCStringformatWithString: Cocos2d-x 传入一个 CCString
【发布时间】:2012-06-22 15:31:50
【问题描述】:

也许我做错了,如果我错了,请告诉我,因为我只是不知道更好。

但我试图将 CCString 传递为以下格式,但没有任何运气。有人可以告诉我将字符串传递给另一个字符串时,C++ 中的字符串参数是什么吗?

代码:

CCString tilt = "";

        if (recalculatedFrames >= 4 && (numberOfTimesRun > 0 && numberOfTimesRun < recalculatedFrames - 1)) {
            tilt = "TR_";
        }

        initalTurnAnimationFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(CCString::stringWithFormat("%s%d.png", tilt, i)));

也可以像我用倾斜一样制作一个空白字符串吗?

【问题讨论】:

    标签: iphone c++ ios cocos2d-iphone cocos2d-x


    【解决方案1】:

    试试这个

    CCString::stringWithFormat("%s%d.png", tilt.getCString(), i)
    

    【讨论】:

    • 嗯,我收到错误 Cannot initalize a parameter of the type 'const char *' with an rvalue of type 'cocos2d::CCString, *'
    • 试试(char*)(CCString::stringWithFormat("%s%d.png", tilt.getCString(), i));
    • 现在已弃用此功能
    • 所以使用 initWithFormat 代替。有问题吗?
    • 现在是 CCString::createWithFormat,所以:- CCString *cs = CCString::createWithFormat("%s%i", "Hello", 21 );
    【解决方案2】:

    我认为tilt 应该是string 的类
    CCString 部分应该是
    CCString::createWithFormat("%s%d.png", tilt.c_str(), i);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      相关资源
      最近更新 更多