cocos2d-x 动画CCAnimation
来源:互联网 发布:网络平台运维监控系统 编辑:程序博客网 时间:2024/05/16 05:30
http://download.csdn.net/detail/wu_123_456/7615263
1.在init()函数中添加如下代码:
CCSprite* sprite2 = CCSprite::create("animation.png",CCRectMake(1,1,200,285));sprite2->setPosition(ccp(200,150));this->addChild(sprite2,4);sprite2->runAction(createAnimation());
CCRectMake功能是在该图片资源中截取某一部分。
2.createAnimation()函数的创建
CCAction* NodeHelloWorld::createAnimation(){CCSpriteBatchNode *bathnode = CCSpriteBatchNode::create("animation.png");int iFrameNum = 4;CCSpriteFrame* frame = NULL;CCArray* frameArray = CCArray::create();for (int i = 0; i < iFrameNum ;++i){int x = i*200+1;int y = 1;frame = CCSpriteFrame::createWithTexture(bathnode->getTexture(),CCRectMake(x,y,200,285));frameArray->addObject(frame);}CCAnimation* animation = CCAnimation::createWithSpriteFrames(frameArray);animation->setLoops(-1);animation->setDelayPerUnit(0.5f);CCAction* action = CCAnimate::create(animation);return action;}
创建动画,过程中使用CCSpriteFrame帧控制,再由帧创建出CCAnimation(名词),要想动起来,还得创建动作(也就是动词)CCAnimate,对于内存中的优化,在上述代码中使用的是CCSpritebatchNode,也可使用精灵帧缓存类CCSpriteFrameCache,如上一篇中所描述,要有plist文件。
参考代码:
CCAction* TollgateScene::createAnimation(){CCSpriteFrameCache *boysCache = CCSpriteFrameCache::sharedSpriteFrameCache();boysCache->addSpriteFramesWithFile("boys.plist","boys.png");CCSpriteFrame *frame = NULL;CCArray* framearray = CCArray::create();for (int i = 1; i <= MAX_BOYS_COUNTS;++i){CCString *str = CCString::createWithFormat("run%d.png",i);frame = boysCache->spriteFrameByName(str->getCString());framearray->addObject(frame);}CCAnimation* animation = CCAnimation::createWithSpriteFrames(framearray);animation->setLoops(-1);animation->setDelayPerUnit(0.03f);CCAction* action = CCAnimate::create(animation);return action;}
0 0
- cocos2d-x 动画CCAnimation
- cocos2d-x CCAnimation实现动画
- Cocos2d-x动画CCAnimate CCAnimation
- CCAnimation创建动画cocos2d-x
- CCAnimation创建动画 cocos2d-x
- Cocos2d-x动画CCAnimate CCAnimation
- cocos2d-x 2.x 简单动画CCAnimation
- 《初学cocos2d-x》- 动画CCAnimation(2)
- CCAnimation创建动画cocos2d-x教程
- CCAnimation创建动画(cocos2d-x)
- Cocos2d-X使用CCAnimation创建动画
- Cocos2d-X使用CCAnimation创建动画
- cocos2d-x -CCSpriteFrameCache-CCAnimation
- CCAnimation创建动画-沈大海cocos2d-x教程22
- 剖析cocos2d-x中的CCAnimation: 从CCTexture2D到CCAnimation
- Cocos2d-x 创建(create)动画对象CCAnimation报错分析
- cocos2d-x节点(CCAnimation.h)API
- cocos2d-x 2.0通过CCAnimation实例获取CCSpriteFrame
- struts validate
- Android中的Activity四种启动模式(launchMode)
- Python程序员的常见错误
- Linux内存管理--笔记(转载)
- android sdk linux 版 64 位
- cocos2d-x 动画CCAnimation
- PNP与NPN 晶体管的检测方法
- 快捷家具酒店厨具的发展趋势
- vim 【Accessing system_clipboard】
- 20个优秀的 HTML5 网站设计案例欣赏
- google map api v3实现将多个标注展示在最佳视野
- 经纬财富:枣庄现货开户流程和投资技巧
- 算法导论,习题8-2,计数排序原址排序
- Hibernate 所有缓存机制详解