热门IT资讯网

cocos2d-x学习笔记-plist动画

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