温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cocos2d-x学习笔记-plist动画

发布时间:2020-04-13 20:46:34 来源:网络 阅读:1542 作者:xhmesh 栏目:游戏开发

 

  1. CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("aaaa.plist");  
  2.           
  3.         CCArray* animFrames = CCArray::create();  
  4.         CCSpriteFrame *frame0;  
  5.         char path[10];  
  6.         for(int i = 4;i<7;i++){  
  7.             sprintf(path, "A1_%d.png", i);  
  8.             if(i == 4){  
  9.                 frame0 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(path);  
  10.             }  
  11.             animFrames->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(path));  
  12.         }  
  13.  
  14.         CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2f);   
  15.         animFrames->release();  
  16.  
  17.         CCArray* animFrames2 = CCArray::create();  
  18.         for(int j = 1;j<7;j++){  
  19.             sprintf(path, "A1_%d.png", j);            
  20.             animFrames2->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(path));  
  21.         }  
  22.         CCAnimation *animation2 = CCAnimation::createWithSpriteFrames(animFrames2, 0.2f);   
  23.         animFrames2->release();  
  24.         CCAnimate *animate2 = CCAnimate::create(animation2);   
  25.  
  26.         //#2:初始化并设置Sprite   
  27.         CCSprite *sprite = CCSprite::spriteWithSpriteFrame(frame0);  
  28.         //设置一个初始frame   
  29.         sprite->setPosition( ccp(size.width/2, size.height/2) );   
  30.         addChild(sprite);    
  31.         //#3:使用animation生成一个动画动作animate   
  32.         CCAnimate *animate = CCAnimate::create(animation);   
  33.  
  34.         CCRepeatForever* action = CCRepeatForever::create(animate);  
  35.         action->setTag(1);  
  36.         //第一种动作  
  37.         sprite->runAction(action);//重复播放   
  38.  
  39.         sprite->stopActionByTag(1);  
  40.         //第二种动作  
  41.         sprite->runAction(CCRepeatForever::create(animate2));//重复播放  

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI