使用缩放帧的精灵表动画

Spritesheet animation with scaled frames

本文关键字:精灵 动画 缩放      更新时间:2023-10-16

为了在cocos2d-x 3.2中创建动画,我这样做:

 SpriteFrameCache* cache = SpriteFrameCache::getInstance();
    Vector<SpriteFrame*> animFrames(15);
    for(int i = 1; i <= 7; ++i)
    {
        SpriteFrame* frame = cache->getSpriteFrameByName(String::createWithFormat("%d.png", i)->getCString());
        animFrames.pushBack(frame);
    }

    auto animation = Animation::createWithSpriteFrames(animFrames, 1 / animFrames.size());
    auto animate = Animate::create(animation);
    pSprite->runAction(animate);

但现在我需要一些帧来用-1缩放ByX,以便创建镜像。SpriteFrame没有scale方法。此外,我不能scalepSprite,因为只有一些帧应该缩放。我该如何解决这个问题?

您遇到了一个非常奇怪的情况:)

  1. 您可以在sprite上安排更新选择器,并根据所需条件将flipX设置为true/false这是我个人的喜好

  2. 你不能用这种方式破解SpriteFrame,但你可以使用RenderTexture:http://www.cocos2d-x.org/reference/native-cpp/V3.0alpha0/d9/ddc/classcocos2d_1_1_render_texture.html-在一个新的纹理中翻转你想要的精灵,基本上是动态生成一个新精灵表现在这是个坏主意