CCAnimation创建动画cocos2d-x教程
2013-10-14 19:39
351 查看
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 ) );
//载入动画所需纹理图片
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 ) );
相关文章推荐
- CCAnimation创建动画-沈大海cocos2d-x教程22
- CCAnimation创建动画(cocos2d-x)
- Cocos2d-X使用CCAnimation创建动画
- Cocos2d-x教程(4)-创建动画效果,TexturePacker工具
- 自定义精灵类并为你的精灵设置攻击帧(指定开始帧)以及扩展Cocos2d源码的CCAnimation简化动画创建
- Cocos2d-x教程(4)-创建动画效果,TexturePacker工具
- CCAnimation创建动画 cocos2d-x
- Cocos2d-x 创建(create)动画对象CCAnimation报错分析
- cocos2d-x教程-CCAnimationa创建动画
- 【iOS-Cocos2d游戏开发之二十一 】自定义精灵类并为你的精灵设置攻击帧(指定开始帧)以及扩展Cocos2d源码的CCAnimation简化动画创建!
- CCAnimation创建动画cocos2d-x
- Cocos2d-x 创建(create)动画对象CCAnimation报错分析
- Cocos2d-X使用CCAnimation创建动画
- 【iOS-Cocos2d游戏开发之二十一 】自定义精灵类并为你的精灵设置攻击帧(指定开始帧)以及扩展Cocos2d源码的CCAnimation简化动画创建!
- Cocos2d-x教程 CocoStudio篇 (1) 创建骨骼动画
- 【iOS-Cocos2d游戏开发之二十一 】自定义精灵类并为你的精灵设置攻击帧(指定开始帧)以及扩展Cocos2d源码的CCAnimation简化动画创建!
- Cocos2d-X使用CCAnimation创建动画
- 使用cocos2d-iphone和cocos2d-x创建帧动画
- quick-cocos2d-x教程13:实现帧动画
- cocos2d-x 3.x 创建动画