CCAnimation创建动画
来源:互联网 发布:服务器怎么打开端口 编辑:程序博客网 时间:2024/06/08 00:18
图片资源:
CCSize s = CCDirector::sharedDirector()->getWinSize();
//载入动画所需纹理图片CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("animations/dragon_animation.png");
// manually add frames to the frame cache// 切图获取每一帧
CCSpriteFrame *frame0 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*0, 132*0, 132, 132));
CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*1, 132*0, 132, 132));
CCSpriteFrame *frame2 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*2, 132*0, 132, 132));
CCSpriteFrame *frame3 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*3, 132*0, 132, 132));
CCSpriteFrame *frame4 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*0, 132*1, 132, 132));
CCSpriteFrame *frame5 = CCSpriteFrame::createWithTexture(texture, CCRectMake(132*1, 132*1, 132, 132));
//
// Animation using Sprite BatchNode
//
CCSprite* sprite = CCSprite::createWithSpriteFrame(frame0);
sprite->setPosition( ccp( s.width/2-80, s.height/2) );
addChild(sprite);
CCArray* animFrames = CCArray::createWithCapacity(6);
animFrames->addObject(frame0);
animFrames->addObject(frame1);
animFrames->addObject(frame2);
animFrames->addObject(frame3);
animFrames->addObject(frame4);
animFrames->addObject(frame5);
CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2f);//这里定义了每一帧,和动画的间隔时间
CCAnimate *animate = CCAnimate::create(animation);//这里创建了动画的Action
CCActionInterval* seq = (CCActionInterval*)(CCSequence::create( animate,
CCFlipX::create(true),
animate->copy()->autorelease(),
CCFlipX::create(false),
NULL) );
sprite->runAction(CCRepeatForever::create( seq ) );
/.//////////////////////////////////////////////////////////////////////////////////////////////////////////貌似很简单,可以在应用中用该方法加入各种特效
但真正游戏中的角色,NPC,需要做碰撞的内容最好还是用SpriteBatchNode 来管理每个Sprite 通过Schedule自定义编程的方式来实现运动和变化。
原文地址:http://blog.csdn.net/sdhjob/article/details/8243980
- CCAnimation创建动画
- CCAnimation创建动画cocos2d-x
- CCAnimation创建动画 cocos2d-x
- CCAnimation创建动画cocos2d-x教程
- CCAnimation创建动画(cocos2d-x)
- 笨小五工作笔录之-动画创建CCAnimation
- Cocos2d-X使用CCAnimation创建动画
- Cocos2d-X使用CCAnimation创建动画
- CCAnimation创建动画-沈大海cocos2d-x教程22
- CCAnimation之 不指定帧数来创建动画
- cocos2d-x 动画CCAnimation
- 创建 和使用 CCAnimation
- cocos2d-x CCAnimation实现动画
- Cocos2d-x动画CCAnimate CCAnimation
- Cocos2d-x动画CCAnimate CCAnimation
- 动画制作——CCAnimation
- Cocos2d-x 创建(create)动画对象CCAnimation报错分析
- cocos2d-x 2.x 简单动画CCAnimation
- 块级元素和行内元素的区别
- Linux下创建共享内存,并应该的小例子
- 努力一阵子,享受一辈子
- 一致性哈希算法 - Consistent Hashing
- 分治法 逆序数
- CCAnimation创建动画
- android笔记
- Documentation_power_apm-acpi
- copy_from_user
- 让Ipad应用程序的default。png等待时间为3秒
- C#发现之旅第四讲 Windows图形开发入门
- Qt 学习过程记录(14-10-2013)
- android笔记1
- 写一个函数,判断一个int型的正整数是否是2的幂,即是否可以表示成2^X的形式(不可以用循环)