cocos2d-x中的动画的使用
来源:互联网 发布:knockout js 编辑:程序博客网 时间:2024/05/18 03:09
大体思想:
动画效果的使用:
根据图片创建纹理--》根据纹理创建帧,将帧放入到类似List的对象中anim,将
- CCAnimation *animation=CCAnimation::animationWithFrames(anim,0.04f);
- CCAnimate *animate = CCAnimate::actionWithAnimation(animation, false);
CCAnimation *animation=CCAnimation::animationWithFrames(anim,0.04f);CCAnimate *animate = CCAnimate::actionWithAnimation(animation, false);
用第一帧创建CCSprite,
最后精灵runAction
如果要执行多个动画,可以runAction(CCSequence::actions(...));
先将图片异步加载到缓存,异步加载看cocos2d-x源码就是多线程加载,用的pthread,以后使用图片就会更快,这一步一般都是游戏开始的时候用进度条来显示
- CCTextureCache::sharedTextureCache()->addImageAsync(garden_petal1,this,callfuncO_selector(Garden::loadingCallBack));
- //CCTexture2D *texture1=CCTextureCache::sharedTextureCache()->addImage(garden_petal1);
- CCTextureCache::sharedTextureCache()->addImageAsync(garden_petal2,this,callfuncO_selector(Garden::loadingCallBack));
CCTextureCache::sharedTextureCache()->addImageAsync(garden_petal1,this,callfuncO_selector(Garden::loadingCallBack));//CCTexture2D *texture1=CCTextureCache::sharedTextureCache()->addImage(garden_petal1);CCTextureCache::sharedTextureCache()->addImageAsync(garden_petal2,this,callfuncO_selector(Garden::loadingCallBack));
在回调函数中处理进度条的显示
代码:
- //创建纹理
- CCTexture2D *texture1=CCTextureCache::sharedTextureCache()->addImage(garden_petal1);
- CCTexture2D *texture2=CCTextureCache::sharedTextureCache()->addImage(garden_petal2);
- CCTexture2D *texture3=CCTextureCache::sharedTextureCache()->addImage(garden_petal3);
- CCTexture2D *texture4=CCTextureCache::sharedTextureCache()->addImage(garden_petal4);
- CCTexture2D *texture5=CCTextureCache::sharedTextureCache()->addImage(garden_petal5);
- CCTexture2D *texture6=CCTextureCache::sharedTextureCache()->addImage(garden_petal6);
- CCTexture2D *texture7=CCTextureCache::sharedTextureCache()->addImage(garden_petal7);
- CCTexture2D *texture8=CCTextureCache::sharedTextureCache()->addImage(garden_petal8);
- CCTexture2D *texture9=CCTextureCache::sharedTextureCache()->addImage(garden_petal9);
- CCTexture2D *texture10=CCTextureCache::sharedTextureCache()->addImage(garden_petal10);
- CCTexture2D *texture11=CCTextureCache::sharedTextureCache()->addImage(garden_petal11);
- CCTexture2D *texture12=CCTextureCache::sharedTextureCache()->addImage(garden_petal12);
- //用纹理创建帧
- CCSpriteFrame *frame1 = CCSpriteFrame::frameWithTexture(texture1,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame2 = CCSpriteFrame::frameWithTexture(texture2,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame3 = CCSpriteFrame::frameWithTexture(texture3,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame4 = CCSpriteFrame::frameWithTexture(texture4,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame5 = CCSpriteFrame::frameWithTexture(texture5,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame6 = CCSpriteFrame::frameWithTexture(texture6,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame7 = CCSpriteFrame::frameWithTexture(texture7,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame8 = CCSpriteFrame::frameWithTexture(texture8,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame9 = CCSpriteFrame::frameWithTexture(texture9,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame10 = CCSpriteFrame::frameWithTexture(texture10,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame11 = CCSpriteFrame::frameWithTexture(texture11,CCRectMake(100,100,600,870));
- CCSpriteFrame *frame12 = CCSpriteFrame::frameWithTexture(texture12,CCRectMake(100,100,600,870));
- //添加到类似List的对象中
- CCMutableArray<CCSpriteFrame*>* anim=new CCMutableArray<CCSpriteFrame*>(12);
- anim->addObject(frame1);
- anim->addObject(frame2);
- anim->addObject(frame3);
- anim->addObject(frame4);
- anim->addObject(frame5);
- anim->addObject(frame6);
- anim->addObject(frame7);
- anim->addObject(frame8);
- anim->addObject(frame9);
- anim->addObject(frame10);
- anim->addObject(frame11);
- anim->addObject(frame12);
- //最用精灵运行动画
- CCAnimation *animation=CCAnimation::animationWithFrames(anim,0.4f);
- CCAnimate *animate = CCAnimate::actionWithAnimation(animation, false);
- CCSprite* txs=CCSprite::spriteWithSpriteFrame(frame1);
- txs->setPosition(ccp(100,100));
- this->addChild(txs,1);
- txs->runAction(animate);
- cocos2d-x中的动画的使用
- cocos2d-x中的动画的使用
- cocos2d-x 的动画
- CCBAnimationManager的使用:使用cocos2d-x程序控制,由cocosBuilder生成cbbi中的动画
- CCBAnimationManager的使用:使用cocos2d-x程序控制,由cocosBuilder生成cbbi中的动画
- Cocos2d-x 中的帧动画
- cocos2d-x使用DragonBones动画
- cocos2d-x 使用骨骼动画
- cocos2d-x骨骼动画使用
- cocos2d-x中的CCScrollView的使用
- Cocos2d-x中的CCScrollView的使用
- Cocos2d-x中的 CCSpriteFrameCache , CCTextureCache的使用
- Cocos2d-x中的CCARRAY_FOREACH的使用
- cocos2d-x 自建动画管理器AnimationManager的方法和使用
- cocos2d-x 自建动画管理器AnimationManager的方法和使用
- 骨骼动画 Spine的使用(With Cocos2d-x)
- cocos2d-x v3.0beta2使用cocostudio制作的动画
- cocos2d-x 3.2 使用cocos studio导出的帧动画
- 函数fgets和fputs、fread和fwrite、fscanf和fprintf用法小结
- 提高数据库处理查询速度
- windows eclipse c++ cocos2dx 游戏开发环境搭建
- 交规复习
- linux errno.h文件
- cocos2d-x中的动画的使用
- CString 转换为 double 类型
- ruby 自动测试工具
- android多点触控揭秘
- 推荐19个很有用的 JavaScript 库
- 列导向数据库的优势
- 提升Android应用性能的10大要点
- WinCE中文显示乱码的解决办法
- windows 7 下 myeclipse 部分插件不兼容问题解决办法