【问题标题】:Why initWithSpriteFrameName() and initWithFile() have different effect on Sprite?为什么 initWithSpriteFrameName() 和 initWithFile() 对 Sprite 有不同的影响?
【发布时间】:2016-02-03 07:08:45
【问题描述】:

我需要一个粉碎效果,我可以用这两种不同的方法成功初始化我的精灵,但是粉碎效果不同。

  1. The Effect I use initWithFile()
  2. The Effect I use initWithSpriteFrameName()

(忽略图片中的文字,下面是代码)

bool ShatterSprite::init(const string &texFileName, float gridSideLen, GameTextureResType resType)
{
    m_gridSideLen = gridSideLen;
    switch (resType) {
        case PLIST:
            Sprite::initWithSpriteFrameName(texFileName); //sprite Frame
            break;
        case LOCAL:
            Sprite::initWithFile(texFileName);
            break;
        default:
            CCASSERT(0, "no here");
            break;
    }
    createShatter();
    return true;
}

我用initWithSpriteFrameName的方法不能得到我需要的效果,谁能告诉我原因?

【问题讨论】:

标签: cocos2d-x sprite init


【解决方案1】:

initWithSpriteFrameName 需要帧名,initWithFile 需要文件名。你在两者中都发送相同的。 file 表示磁盘上的实际文件,frame 表示您缓存在内存中的帧名称。通过以下代码,您可以在内存中添加帧

SpriteFrameCache* cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");

【讨论】:

  • 我之前加过Frame,我可以用initWithSpriteFrameName成功初始化我的Sprite。但是 initWithSpriteFrameName 的 sprite init 与 initWithFile 有不同的粉碎效果。
  • 对您的问题进行更多解释,因为对我而言,两者的工作方式相同,并且从不采取不同的行动。
  • 参考github.com/wantnon2/EffectNodes-for-cocos2dx/tree/v3,我实现了我的粉碎效果。根据他的例子,我使用了一个.png文件,它可以实现粉碎效果。但是,当我使用 .plist 文件时,我无法实现这种效果。
  • 如果您的问题仍然存在。你能分享一下plist和相关的png吗?
  • 非常感谢,已将部分代码和资源提交到GitHub:github.com/LongJDoing/Question_Demo/tree/master/ShatterEffect
猜你喜欢
  • 1970-01-01
  • 2023-03-16
  • 2016-08-02
  • 2013-01-18
  • 2019-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多