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;
}
}
|