cocos2dx添加动画

//加载timeline
cocostudio::timeline::ActionTimeline* actionTimeline =  CSLoader::createTimeline("CGScene.csb");
//播放动画	
rootNode->runAction(actionTimeline);
//跳转到指定帧播放
actionTimeline->gotoFrameAndPlay(0,false);
//添加动画事件
actionTimeline->addFrameEndCallFunc(105, "enterScene", CC_CALLBACK_0(CGScene::onFrameEndEvent, this));
	
//============骨骼动画======
//动态加载一个骨骼动画对象
cocostudio::ArmatureDataManager* adm = cocostudio::ArmatureDataManager::getInstance();
//骨骼对象
cocostudio::Armature* armature = cocostudio::Armature::create("boss_icedragon");
//动画播放器
cocostudio::ArmatureAnimation* animation = armature->getAnimation();
//播放指定动画`
animation->play("attack",0,10);
//位置
armature->setPosition(100, 100);
rootNode->addChild(armature);

//=================帧动画======
//动画剪辑
Animation* animation = Animation::create();
for (int i = 1; i < 3 ; i++)
	{
		std::string name = StringUtils::format("images/redbird_0%d.png", i);

		SpriteFrame* frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(name);

		animation->addSpriteFrame(frame);//与SpriteFrameCache没关系,重新加载图片,图片转成SpriteFrame
		
		animation->setDelayPerUnit(1);//每一帧间隔,必须要设置
	}
	//动画播放器
	Animate* animate = Animate::create(animation);
	//动作的时长
	animate->setDuration(5);
	//重复次数
	Repeat* repeat = Repeat::create(animate, 10);
	bird->runAction(repeat);

你可能感兴趣的:(cocos2dx)