cocos2d-x中的动画的使用

一、序列帧动画

可以先使用TexturePacker将很多序列帧图片拼成一张大图,在构造函数中使用

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("plane.plist","plane.png");

将资源加载到内存中,

在析构函数中使用

CCSpriteFrameCache::sharedSpriteFrameCache()->removeSpriteFramesFromFile("plane.plist");释放资源

序列帧的播放:

CCArray * array = CCArray::create();
		for(int i=1;i<=2;i++)
		{
			char temp[15];
			sprintf(temp,"plane_0%d.png",i);
			CCSpriteFrame * frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(temp);
			array->addObject(frame);
		}
		CCAnimation * animation = CCAnimation::createWithSpriteFrames(array,0.1f);
		plane -> runAction(CCRepeatForever::create(CCAnimate::create(animation)));

 精灵这个时候也可以通过内存中的资源来创建

plane = CCSprite::createWithSpriteFrameName("plane_01.png");

 

二、普通动画

 

移动动作:CCMoveBy   CCMoveTo

旋转动作:CCRotateBy   CCRotateTo

缩放动作:CCScaleBy   CCScaleTo

 

跳跃动作:CCJumpBy   CCJumpTo

淡入淡出动作:CCFadeBy   CCFadeIn   CCFadeOut

CCMoveTo * moveTo =CCMoveTo::create(0.5f,CCPointMake(400,400));
	CCMoveTo * moveBack =CCMoveTo::create(0.5f,CCPointMake(200,200));
	//sprite->runAction(moveTo);使用方法一
	//sprite->runAction(CCSequence::create(moveTo,moveBack,NULL));//使用方法二(依次执行moveTo,moveBack)
	//sprite->runAction(CCRepeat::create(CCSequence::create(moveTo,moveBack,NULL),2));//重复执行两次
	sprite->runAction(CCRepeatForever::create(CCSequence::create(moveTo,moveBack,NULL)));//一直重复执行

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值