关于cocos2d-x中的一些动作的简单使用(淡入淡出,贝塞尔曲线等)

Size size = Director::getInstance()->getWinSize();
	auto sprite3 = Sprite::create("4.png");
	sprite3->setPosition(size.width/2,size.height/2);
	this->addChild(sprite3);

	auto sprite = Sprite::create("paoku00188.png");
	sprite->setPosition(300,300);
	this->addChild(sprite);
	auto animation = Animation::create();
	for (int i = 188; i <= 199; i++)
	{
	std::string str = StringUtils::format("paoku00%d.png",i);
	animation->addSpriteFrameWithFile(str);
	}
	animation->setDelayPerUnit(0.05);//间隔时间
	animation->setLoops(-1);//播放的次数
	auto animate = Animate::create(animation);
// 	auto pointa = PointArray::create(10);
// 	pointa->addControlPoint(Point(100,0));
// 	pointa->addControlPoint(Point(100,100));
	//auto mov = CardinalSplineBy::create(5,pointa,1);

	ccBezierConfig ccbe = {Point(900,300),Point(400,400),Point(800,200)};
	auto pointa=BezierTo:: create(2,ccbe);
	auto act = Spawn::create(animate,nullptr);
	sprite->runAction(act);

	auto sprite1 = Sprite::create("CloseNormal.png");
	sprite1->setPosition(100,100);
	//sprite1->setVisible(false);
	//sprite1->setOpacity(0);
	sprite1->setAnchorPoint(Point(0,0));
	this->addChild(sprite1);
	//vectArray->push_back(sprite1);

	
	for (int i = 0; i < 10; i++)
	{
		Point p(rand() % 960,rand() % 640);
		sp2 = Sprite::create("CloseNormal.png");
		sp2->setPosition(p);
		this->addChild(sp2);
	}

	auto spt1 = Sprite::create("CloseNormal.png");
	spt1->setPosition(size.width / 2,size.height / 2);
	this->addChild(spt1);
	auto spt2 = Sprite::create("CloseNormal.png");
	spt2->setPosition(size.width / 2,size.height / 2);
	this->addChild(spt2);
	auto spt3 = Sprite::create("CloseNormal.png");
	spt3->setPosition(size.width / 2,size.height / 2);
	this->addChild(spt3);
	auto spt4 = Sprite::create("CloseNormal.png");
	spt4->setPosition(size.width / 2,size.height / 2);
	this->addChild(spt4);

	auto sprite2 = Sprite::create("CloseNormal.png");
	sprite2->setPosition(100,200);
	this->addChild(sprite2);
	//vectArray->push_back(sprite2);


	auto item = MenuItemFont::create("out",[=](Ref* f){
		//淡出
		auto fadeout = FadeOut::create(2);
		sprite1->runAction(fadeout);
		

	});
	auto item2 = MenuItemFont::create("in",[=](Ref* f){
		//淡入
		auto fadein = FadeIn::create(3);
		sprite1->runAction(fadein);
		//auto act1 = RotateBy::create(3,-360 * 10);
		
	});
	auto item3 = MenuItemFont::create("moveBy",[=](Ref*f){
				auto moveb = MoveBy::create(3,0));
				sprite1->runAction(moveb);
// 		auto moveb = MoveTo::create(3,500));
// 		sprite1->runAction(moveb);
	});
	auto item4 = MenuItemFont::create("jumpBy",[=](Ref*f){
		auto jumpb = JumpBy::create(1,Point(100,0),50,2);
		//sprite1->runAction(jumpb);
		//闪烁
		auto blink = Blink::create(2,2);
		//sprite1->runAction(blink);
		auto aa = DelayTime::create(2);//间隔时间
		auto sq = Sequence::create(jumpb,aa,blink,nullptr);
		
		sprite1->runAction(sq);

	});
	auto item5 = MenuItemFont::create("suijiMove",[=](Ref*f){
		Point p(rand()%960,rand()%640);
		auto moveb = MoveTo::create(3,p);
		sprite1->runAction(moveb);
		
	});
	auto item6 = MenuItemFont::create("Disappear",[=](Ref*f){
		
		Point p(rand() % 960,rand() % 640);
		auto moveb = MoveTo::create(3,p);
		//sprite1->runAction(moveb);

		


		sprite2->runAction(moveb);
		auto sp1 = sprite1->getBoundingBox();
		auto sp2 = sprite2->getBoundingBox();
		if (sp1.intersectsRect(sp2))
		{
			sprite1->removeFromParentAndCleanup(true);
			sprite2->removeFromParentAndCleanup(true);
		}
	});
	auto item7 = MenuItemFont::create("DisappearTen",[=](Ref*f){
		Point p(rand() % 960,rand() % 640);
		//Point p1(CCRANDOM_0_1*size.width,CCRANDOM_0_1*size.height);
		auto moveb = MoveTo::create(3,p);
		auto act = JumpBy::create(1,Point(0,100,1);
		sprite1->runAction(act);
		
	});
	auto item8 = MenuItemFont::create("back",[=](Ref*f){
		auto act = MoveTo::create(1,Point(200,100));
		auto act1 = DelayTime::create(1);
		auto act2 = JumpTo::create(2,100),2);
		//stopAction(act2);
		auto sq = Sequence::create(act,act1,act2,nullptr);
		
		sprite1->runAction(sq);

	});
	auto item9 = MenuItemFont::create("bingxingRun",[=](Ref* f){
		auto act1 = RotateBy::create(3,-360 * 10);
		//auto act1 = RotateBy::create(3,Vertex3F(0,360,0));//Vertex3F
		auto act2 = ScaleBy::create(3,0.2);//放大
		auto act3 = MoveBy::create(3,Point(300,0));
		auto act = Spawn::create(act1,act3,nullptr);
		sprite1->runAction(act);
	});
	auto item10 = MenuItemFont::create("fangda",[=](Ref* f){
		auto act2 = ScaleTo::create(3,1.5);
		auto act3 = RotateBy::create(2,360*10);
		auto act4 = Spawn::create(act2,nullptr);//并行
		sprite3->runAction(act4);
	});
	auto item11 = MenuItemFont::create("zuhe",[=](Ref* f){
		SimpleAudioEngine::getInstance()->playBackgroundMusic("11.mp3");
		//auto act33 = DelayTime::create(3);
		auto act1 = MoveTo::create(3,100));
 		auto act2 = JumpTo::create(3,1);
		auto act3 = RotateBy::create(3,3600));
		auto Call = CallFuncN::create([](Node* node){
			SimpleAudioEngine::getInstance()->playEffect("11.mp3");
		});
		auto act4 = Sequence::create(act1,Call,nullptr);//过程执行
		auto reps = Repeat::create(act4,4);//循环动画
		sprite1->runAction(reps);
	});
	auto item12 = MenuItemFont::create("CallFuncN",[=](Ref* f){
		//水平与垂直翻转
		auto fx = FlipX::create(true);
		auto fy = FlipY::create(true);
		auto act = Sequence::create(fx,fy,nullptr);
		sprite1->runAction(act);
		//动画回调
		auto actMove = MoveBy:: create(2,Point(500,0));

		auto actCall = CallFuncN::create([](Node* node){
			node->removeFromParentAndCleanup(true);
		});
		auto actSque = Sequence::create(actMove,actCall,nullptr);
		sprite1->runAction(actSque);
	});
	auto item13 = MenuItemFont::create("CallFuncNN",[=](Ref* f){
		auto spt1Move = MoveTo::create(2,Point(60,40));
		auto act1Call = CallFuncN::create([=](Node* node){
			auto act2Call = CallFuncN::create([=](Node* node){
				auto act3Call = CallFuncN::create([=](Node* node){
					auto spt4Move = MoveTo::create(2,600));
					spt4->runAction(spt4Move);
				});
				auto spt3Move = MoveTo::create(2,Point(900,600));
				auto b = Sequence::create(spt3Move,act3Call,nullptr);
				spt3->runAction(b);

			});
			auto spt2Move = MoveTo::create(2,40));
			auto a = Sequence::create(spt2Move,act2Call,nullptr);
			spt2->runAction(a);
		});
		auto act = Sequence::create(spt1Move,act1Call,nullptr);
		spt1->runAction(act);
	});
	auto item14 = MenuItemFont::create("zhendonghua",[=](Ref* f){
		
	});
	Menu* menu = Menu::create(item,item2,item3,item4,item5,item6,item7,item8,item9,item10,item11,item12,item13,item14,nullptr);
	this->addChild(menu);
	menu->alignItemsVertically();

都是一些简单的动作使用,我就不具体的说明了啊 。

相关文章

操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCENE1_H__#defi...
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,执行Install...
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-2.2.1toolspr...
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysicsContact* evC...
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的,基本都能立...
ScrollView(滚动容器)加载大量item时会导致游戏界面的卡顿,严重时整个界面会出现卡死的情况。最近项...