Chinaunix首页 | 论坛 | 博客
  • 博客访问: 465207
  • 博文数量: 88
  • 博客积分: 1677
  • 博客等级: 上尉
  • 技术积分: 667
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-03 22:17
文章分类

全部博文(88)

文章存档

2013年(1)

2012年(18)

2011年(69)

分类: C/C++

2013-01-06 17:13:44


点击(此处)折叠或打开

  1. bool Loading::init()
  2. {
  3. bool bRet = false;
  4. //Parent class initialization
  5. if ( !CCLayer::init() )
  6. {
  7. return false;
  8. }
  9. do
  10. {
  11. //add background sprite picture;
  12. CCSprite *background=CCSprite::create("facade.png");
  13. CCSize size = background->getContentSize();
  14. // background->setContentSize(CCSizeMake(size.width,size.height));
  15. background->setAnchorPoint(ccp(0,0));
  16. background->setPosition(ccp(0,0));
  17. this->addChild(background);
  18. //add animation
  19. //1创建cache 生成纹理
  20. CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
  21. char strPlist[64] = {0};
  22. char strPng[64] = {0};
  23. sprintf(strPlist,"load.plist");
  24. //sprintf(strPng,"fei.pvr.ccz");
  25. sprintf(strPng,"load.png");
  26. cache->addSpriteFramesWithFile(strPlist, strPng);
  27. //创建动画每一帧,从cache里面读取
  28. CCArray *animFrames = new CCArray(5);
  29. char str[264] = {0};
  30. //2截取每一帧
  31. for(int i = 1; i <= 5; i++)
  32. {
  33. sprintf(str, "loader_frame_%d.png", i);//%d为通配符一般为数字,例如(01,02...)
  34. CCSpriteFrame* frame = cache->spriteFrameByName( str );
  35. animFrames->addObject(frame);
  36. }
  37. //4生成动作
  38. CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.4f);
  39. //5初始化并设置Sprite
  40. CCSprite *sprite = CCSprite::create();
  41. sprite->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2-200) );
  42. addChild(sprite);
  43. //6使用animation生成一个动画动作animate
  44. CCAnimate *animate = CCAnimate::actionWithAnimation(animation);
  45. sprite->runAction(animate);//重复播放
  46. bRet = true;
  47. }while(0);
  48. return bRet;
  49. }
显示效果:
阅读(3383) | 评论(0) | 转发(1) |
0

上一篇:Titanium中Android模块开发指南(中文)

下一篇:没有了

给主人留下些什么吧!~~