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();
    }
  • 相关阅读:
    git查看工作状态和历史提交
    PowerDesigner工具栏palette的方法
    WCF证书制作
    ASP.NET.4 高级程序第4版 第3章Web窗体
    tbar居右显示的两种方法
    测试
    转载extj grid
    正值
    网站HTML,XHTML,XML,WML,CSS等测试验证工具介绍[转]
    SQL Server 启用“IP+端口”连接
  • 原文地址:https://www.cnblogs.com/lion-witcher/p/6007597.html
Copyright © 2011-2022 走看看