zoukankan      html  css  js  c++  java
  • Animation

    Animation 单独渲染每一个精灵帧, 渲染效率低, 浪费资源.
    1
    auto sprite = Sprite::create("run1.png"); 2 sprite->setScale(2); 3 sprite->setPosition(visibleSize.width/2, visibleSize.height/2); 4 addChild(sprite); 5 6 //创建序列帧动画 7 auto *animation = Animation::create(); 8 char s[20] = {0}; 9 for (int i = 1; i < 9; i++) { 10 sprintf(s, "run%d.png", i); 11 //添加到序列帧动画 12 animation->addSpriteFrameWithFile(s); 13 } 14 //设置循环多少次 15 animation->setLoops(-1); 16 //每张图展示的时间 17 animation->setDelayPerUnit(0.1f); 18 //设置动画结束后恢复到第一帧 19 animation->setRestoreOriginalFrame(true); 20 //创建序列帧动画动作 21 auto action = Animate::create(animation); 22 sprite->runAction(action);

     AnimationCache 帧动画缓存, 使用plist文件

        auto m_frameCache = SpriteFrameCache::getInstance();
        m_frameCache->addSpriteFramesWithFile("run.plist", "run.png");
        Vector<SpriteFrame *> vec;
        for (int i = 1; i < 9; i++) {
            auto frame = m_frameCache->getSpriteFrameByName(String::createWithFormat("run%d.png", i)->getCString());
            vec.pushBack(frame);
        }
        Animation *animation = Animation::createWithSpriteFrames(vec);
        animation->setLoops(-1);
        animation->setDelayPerUnit(0.1);
        
        auto action = Animate::create(animation);
        sprite->runAction(action);

    //内存不足时, 释放
    void releaseCaches(){
        AnimationCache::destroyInstance();
        SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
        Director::getInstance()->getTextureCache()->removeUnusedTextures();
    }
  • 相关阅读:
    Gym
    HDU-2680 Choose the best route 单向边+反向dijkstra
    Hdu1010Tempter of the Bone 深搜+剪枝
    CodeForces
    CodeForces
    Gym-101375C MaratonIME eats japanese food 初始化struct技巧
    Gym
    java was started but returned exit code =-805306369的处理方法
    启动myeclipse弹窗Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance
    eclipse包分层
  • 原文地址:https://www.cnblogs.com/lion-witcher/p/6007597.html
Copyright © 2011-2022 走看看