Cocos2D-X 动画与特效

1.动画

1.先实例化一个动画类
2.向这个动画类添加帧图片
3.设置这个动画类的属性
4.将动画转换为动作
5.运行动作

代码示例:

Animation* Animation_1 = Animation::create();

for (size_t i = 0; i <= 15; i++)
{
	char str[128];
	sprintf_s(str, "WuGui\\wugui_%d.png", i);
	Animation_1->addSpriteFrameWithFileName(str);
}
Animation_1->setDelayPerUnit(0.05f);
Animation_1->setLoops(CC_REPEAT_FOREVER);
Animation_1->setRestoreOriginalFrame(false);
Animate* animate_1 = Animate::create(Animation_1);
wuGui->runAction(animate_1);

2.特效

特效实际上是属于间隔动作
特效类:GridAction(也叫做网格动作)
GridAction的直接子类: Grid3DAction / TiledGrid3DAction
其类关系如图:
在这里插入图片描述

1.实例化一个特效对象
2.将这个特效对象添加到当前层
3.将精灵作为子节点添加到特效对象下
4.运行特效 特效->runAction(某种特效::create(…));

代码示例:

	Sprite* fSprite_1 = Sprite::create("f.png");
	fSprite_1->setPosition(Vec2(visibleSize.width / 2 + 100,visibleSize.height / 2 + 100));
	fSprite_1->setScale(0.3);
	nodeGrid_1 = NodeGrid::create();
	this->addChild(nodeGrid_1);
	nodeGrid_1->addChild(fSprite_1);

	for (size_t i = 1; i <= 10; i++)
	{
		char num[16];
		sprintf_s(num, "%d", i);
		Label* l = Label::createWithTTF(num, "fonts/Marker Felt.ttf", 24);
		menuItemLabelArr[i - 1] = MenuItemLabel::create(l, CC_CALLBACK_1(Scene_9::menuItemLabelArrFunc,this));
		menuItemLabelArr[i - 1]->setPosition(i * 50 + 50,200);
		menuItemLabelArr[i - 1]->setTag(i - 1);
	}
	Menu* menu_1 = Menu::create(menuItemLabelArr[0], menuItemLabelArr[1], menuItemLabelArr[2],
		menuItemLabelArr[3],menuItemLabelArr[4],menuItemLabelArr[5],
		menuItemLabelArr[6],menuItemLabelArr[7], menuItemLabelArr[8],
		menuItemLabelArr[9],nullptr
		);

	this->addChild(menu_1);
	

}

void Scene_9::menuItemLabelArrFunc(Ref* pSender)
{
	MenuItemLabel* m = (MenuItemLabel*)pSender;
	switch (m->getTag()){
	case 0:
		nodeGrid_1->stopAllActions();
		nodeGrid_1->runAction(FlipX3D::create(2.0f));
		break;
	case 1:
		nodeGrid_1->stopAllActions();
		nodeGrid_1->runAction(PageTurn3D::create(2.0f,Size(15,10)));
		break;
	case 2:
		nodeGrid_1->stopAllActions();
		nodeGrid_1->runAction(Shaky3D::create(2.0f,Size(15,10),5,false));
		break;
	case 3:
		nodeGrid_1->stopAllActions();
		nodeGrid_1->runAction(Waves3D::create(2.0f, Size(15, 10), 5, 5));
		break;
	case 4:
		nodeGrid_1->stopAllActions();
		nodeGrid_1->runAction(JumpTiles3D::create(3.0f, Size(3, 2), 3, 40));
		break;
	case 5:
		break;
	case 6:
		break;
	case 7:
		break;
	case 8:
		break;
	case 9:
		break;
	}
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浔汐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值