cocos2d-x中的动画的使用
来源:互联网 发布:mac卸载java 8 编辑:程序博客网 时间:2024/06/05 01:28
cocos2d-x中的动画的使用
分类: cocos2d-x2012-12-07 15:411338人阅读评论(1)收藏举报
大体思想:
动画效果的使用:
根据图片创建纹理--》根据纹理创建帧,将帧放入到类似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
0 0
- 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导出的帧动画
- SQL替换NULL
- TTL、CMOS及RS232电平的区别
- Debug和Release的区别
- mapreduce中reducers个数设置
- 读技术书籍的困扰和一种解决办法尝试
- cocos2d-x中的动画的使用
- 表单上传文件提交实现ajax方式
- 用homebrew安装mongodb
- win7无线网络共享
- UIViewController在调removeFromParentViewController时遇到的问题
- C# DateTime 日期加1天 减一天 加一月 减一月
- SYSTEMTIME FileTimeToLocalFileTime 使用
- EPM7000/3000的几个全局输入脚GCLK1,OE2(GCLK2),OE1,GLCRn都是干什么的?怎么在编程中使用?
- ibatis #和$的区别