~~~~我的生活,我的点点滴滴!!
由于官方的例子EffectsTest已经展示了很多效果,看起来还很不错,这里我不分析代码了,例子中特效的介绍请看:3D特效介绍
下面我直接上我自己写的例子及效果图,里面其实好多重复的代码,这里懒得去逐行去添加注释了。
////第五列 第三行 void HelloWorld::PageTurn3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(800+OFFX, 180)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(1.5, 3); auto pageTrun = PageTurn3D::create(1.5, Size(20,10)); nodeGrid->runAction(Sequence::create(pageTrun, pageTrun->reverse(), nullptr)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("PageTurn3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第四列 第三行 void HelloWorld::SplitRowAndColFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(620+OFFX, 180)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(2, 2); SplitRows *splitRow = SplitRows::create(1, 9); SplitCols *splitCol = SplitCols::create(1, 9); nodeGrid->runAction(Sequence::create(splitRow, splitRow->reverse(), splitCol, splitCol->reverse(), nullptr)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("SplitRowAndCol", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第三列 第四行 void HelloWorld::TurnOffTilesFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(440+OFFX, 50)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(1.5, 3); auto turnOff = TurnOffTiles::create(1.5, Size(25,15), 30); nodeGrid->runAction(Sequence::create(turnOff, turnOff->reverse(), nullptr)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("TurnOffTiles", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第三列 第三行 void HelloWorld::FadeOutALLTilesFunc() { //这里把上、下、左、右四种效果合成一个 NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(440+OFFX, 180)); nodeGrid->addChild(Sp); //从左下-右上 FadeOutBLTiles *FadeOutBL = FadeOutBLTiles::create(0.5, Size(30,25)); //从右上-左下 FadeOutTRTiles *FadeOutTR = FadeOutTRTiles::create(0.5, Size(30,25)); //从上-下 FadeOutDownTiles *FadeOutDown = FadeOutDownTiles::create(0.5, Size(30,25)); //从下-上 FadeOutUpTiles *FadeUp = FadeOutUpTiles::create(0.5, Size(30,25)); nodeGrid->runAction(Sequence::create(FadeOutBL, FadeOutBL->reverse(), DelayTime::create(0.2), FadeOutTR, FadeOutTR->reverse(), DelayTime::create(0.2), FadeOutDown, FadeOutDown->reverse(),DelayTime::create(0.2), FadeUp, FadeUp->reverse(),nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("FadeOutALLTiles", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第二列 第三行 void HelloWorld::ShuffleTilesFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(260+OFFX, 180)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(2, 2); auto shattered = ShuffleTiles::create(2, Size(25,15), 30); nodeGrid->runAction(Sequence::create(shattered, shattered->reverse(), nullptr)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("ShuffleTiles", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第一列 第三行 void HelloWorld::ShatteredTiles3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(80+OFFX, 180)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(1.5, 2); nodeGrid->runAction(ShatteredTiles3D::create(3, Size(25,15),5, true)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("ShatteredTiles3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); ShuffleTilesFunc(); } //第五列 void HelloWorld::LiquidFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(800 + OFFX, 360)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(2, 2); nodeGrid->runAction(Liquid::create(4, Size(15,10),3, 5)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("Liquid", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第五列 void HelloWorld::TwirlFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(800 + OFFX, 540)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(1.5, 2); nodeGrid->runAction(Twirl::create(3, Size(15,10), Vec2(800, 540), 2, 5)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("Twirl", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); LiquidFunc(); } //第四列 void HelloWorld::Ripple3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(620 + OFFX, 360)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(2, 2); nodeGrid->runAction(Ripple3D::create(4, Size(15,10),Vec2(240,160), 25, 5, 30)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("Ripple3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第四列 void HelloWorld::Lens3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(620 + OFFX, 540)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(1, 2); nodeGrid->runAction(Lens3D::create(2, Size(15,10),Vec2(240,160), 45)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("Lens3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); Ripple3DFunc(); } //第三列 void HelloWorld::Flip3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); //X轴 auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(440 + OFFX, 540)); nodeGrid->addChild(Sp); ScaleBy *bottomScaleBy = ScaleBy::create(2.0, 4); auto flipx = FlipX3D::create(2.0); nodeGrid->runAction(Sequence::create(flipx, flipx->reverse(), nullptr)); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("FlipX3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); NodeGrid *nodeGrid1 = NodeGrid::create(); this->addChild(nodeGrid1); //Y轴 auto SpClone = Sprite::create("bang.png"); SpClone->setPosition(Vec2(440 + OFFX, 360)); nodeGrid1->addChild(SpClone); ScaleBy *bottomScaleByClone = ScaleBy::create(1.5, 2); auto flipy = FlipY3D::create(1.5); nodeGrid1->runAction(Sequence::create(flipy, flipy->reverse(), nullptr)); SpClone->runAction(Sequence::create(bottomScaleByClone, bottomScaleByClone->reverse(), nullptr)); m_NodeGrids.push_back(nodeGrid1); auto tf1 = LabelTTF::create("FlipY3D", "Arial", 26); tf1->setPosition(Vec2(SpClone->getPosition().x + OFFX, SpClone->getPosition().y + SpClone->getContentSize().height * 0.5 + tf1->getContentSize().height - 10)); this->addChild(tf1,10); } //第二列 void HelloWorld::WavesTiles3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); ScaleBy *bottomScaleBy = ScaleBy::create(2, 2); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(260 + OFFX, 360)); nodeGrid->addChild(Sp); auto bottomShaky3D = WavesTiles3D::create(4, Size(20,10), 5, 100); nodeGrid->runAction(bottomShaky3D); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(),nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("WavesTiles3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第二列 void HelloWorld::Waves3DFunc() { NodeGrid *nodeGrid = NodeGrid::create(); this->addChild(nodeGrid); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(260 + OFFX, 540)); nodeGrid->addChild(Sp); auto rightShaky3D = Waves3D::create(3, Size(20,10),5, 50); nodeGrid->runAction(rightShaky3D); ScaleBy *rightScaleBy = ScaleBy::create(1.5, 2); Sp->runAction(Sequence::create(rightScaleBy, rightScaleBy->reverse(),nullptr)); m_NodeGrids.push_back(nodeGrid); auto tf = LabelTTF::create("Waves3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); WavesTiles3DFunc(); } //第一列 void HelloWorld::ShakyTiles3DFunc() { ScaleBy *bottomScaleBy = ScaleBy::create(1.5, 3); auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(80 + OFFX, 360)); NodeGrid *nodeGrid = NodeGrid::create(); nodeGrid->addChild(Sp); this->addChild(nodeGrid); m_NodeGrids.push_back(nodeGrid); auto bottomShaky3D = ShakyTiles3D::create(3, Size(20,10), 3, true); nodeGrid->runAction(bottomShaky3D); Sp->runAction(Sequence::create(bottomScaleBy, bottomScaleBy->reverse(),nullptr)); auto tf = LabelTTF::create("ShakyTiles3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); } //第一列 void HelloWorld::Shaky3DFunc() { auto Sp = Sprite::create("bang.png"); Sp->setPosition(Vec2(80 + OFFX, 540)); //3.x中已经改变了,Node中已经没有setGird与getGird接口了,改到NodeGird里面了 NodeGrid *leftNodeGrid = NodeGrid::create(); leftNodeGrid->addChild(Sp); this->addChild(leftNodeGrid); m_NodeGrids.push_back(leftNodeGrid); auto leftShaky3D = Shaky3D::create(3, Size(10,10), 2, true); leftNodeGrid->runAction(leftShaky3D); ScaleBy *leftScaleBy = ScaleBy::create(1.5, 3); Sp->runAction(Sequence::create(leftScaleBy, leftScaleBy->reverse(),nullptr)); auto tf = LabelTTF::create("Shaky3D", "Arial", 26); tf->setPosition(Vec2(Sp->getPosition().x + OFFX, Sp->getPosition().y + Sp->getContentSize().height * 0.5 + tf->getContentSize().height - 10)); this->addChild(tf,10); ShakyTiles3DFunc(); //设置一个update定时器,每帧去查询是否结束了晃动 schedule( schedule_selector(HelloWorld::checkAnim) ); } //这个函数很有用,没有他,效果不会恢复原状 void HelloWorld::checkAnim(float dt) { //由于晃动结束后,他是不会自己恢复原状的,只能设置Node类中一个Grid属性,看Node源码就知道了。 std::vector<NodeGrid*>::iterator iter; for( iter = m_NodeGrids.begin(); iter != m_NodeGrids.end(); ++ iter) { auto s2 = (*iter); //由于这里只有Shaky3D这一种特效,所以用了getNumberOfRunningActions(当前正在运行的Action个数) //及此node是否有grid属性。 if ( s2->getNumberOfRunningActions() == 0 && s2->getGrid() != NULL) { //要设置成NULL,才会恢复原状 s2->setGrid(NULL); } } }
上面用到的最多的是声明一个NodeGrid的对象,然后添加sprite到其里面,最后是NodeGird去runActions(),sprite是不能直接运行Grid3DAction里面效果的,只能是NodeGird对象。
由于屏幕就那么大,选取的精灵图片也小,不如官方例子那样醒目,但是还是能看出效果的,但是gif上传大小受限,只能一减在减,看不到全过程