axmol/tests/cpp-tests/Classes/EffectsTest/EffectsTest.cpp

402 lines
10 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-28 16:06:23 +08:00
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
2021-12-28 16:06:23 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-28 16:06:23 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-28 16:06:23 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "EffectsTest.h"
#include "../testResource.h"
USING_NS_AX;
EffectTests::EffectTests()
{
2015-07-08 21:56:14 +08:00
ADD_TEST_CASE(Shaky3DDemo);
ADD_TEST_CASE(Waves3DDemo);
ADD_TEST_CASE(FlipX3DDemo);
ADD_TEST_CASE(FlipY3DDemo);
ADD_TEST_CASE(Lens3DDemo);
ADD_TEST_CASE(Ripple3DDemo);
ADD_TEST_CASE(LiquidDemo);
ADD_TEST_CASE(WavesDemo);
ADD_TEST_CASE(TwirlDemo);
ADD_TEST_CASE(ShakyTiles3DDemo);
ADD_TEST_CASE(ShatteredTiles3DDemo);
ADD_TEST_CASE(ShuffleTilesDemo);
ADD_TEST_CASE(FadeOutTRTilesDemo);
ADD_TEST_CASE(FadeOutBLTilesDemo);
ADD_TEST_CASE(FadeOutUpTilesDemo);
ADD_TEST_CASE(FadeOutDownTilesDemo);
ADD_TEST_CASE(TurnOffTilesDemo);
ADD_TEST_CASE(WavesTiles3DDemo);
ADD_TEST_CASE(JumpTiles3DDemo);
ADD_TEST_CASE(SplitRowsDemo);
ADD_TEST_CASE(SplitColsDemo);
2021-12-28 16:06:23 +08:00
// ADD_TEST_CASE(PageTurn3DDemo); // TODO crash on iPhone X
// ADD_TEST_CASE(PageTurn3DRectDemo);
2015-07-08 21:56:14 +08:00
}
Shaky3DDemo::Shaky3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Shaky3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* Shaky3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return Shaky3D::create(t, Size(15, 10), 5, false);
2015-07-08 21:56:14 +08:00
}
Waves3DDemo::Waves3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Waves3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* Waves3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return Waves3D::create(t, Size(15, 10), 5, 40);
2015-07-08 21:56:14 +08:00
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FlipX3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
auto flipx = FlipX3D::create(t);
2015-07-08 21:56:14 +08:00
auto flipx_back = flipx->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(2);
2015-07-08 21:56:14 +08:00
return Sequence::create(flipx, delay, flipx_back, nullptr);
}
FlipX3DDemo::FlipX3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "FlipX3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FlipY3DDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto flipy = FlipY3D::create(t);
2015-07-08 21:56:14 +08:00
auto flipy_back = flipy->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(2);
2015-07-08 21:56:14 +08:00
return Sequence::create(flipy, delay, flipy_back, nullptr);
}
2015-07-08 21:56:14 +08:00
FlipY3DDemo::FlipY3DDemo()
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
_title = "FlipY3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* Lens3DDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2015-07-08 21:56:14 +08:00
auto size = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
return Lens3D::create(t, Size(15, 10), Vec2(size.width / 2, size.height / 2), 240);
2015-07-08 21:56:14 +08:00
}
Lens3DDemo::Lens3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Lens3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* Ripple3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
auto size = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
return Ripple3D::create(t, Size(32, 24), Vec2(size.width / 2, size.height / 2), 240, 4, 160);
2015-07-08 21:56:14 +08:00
}
Ripple3DDemo::Ripple3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Ripple3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* LiquidDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return Liquid::create(t, Size(16, 12), 4, 20);
2015-07-08 21:56:14 +08:00
}
LiquidDemo::LiquidDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Liquid";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* WavesDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return Waves::create(t, Size(16, 12), 4, 20, true, true);
2015-07-08 21:56:14 +08:00
}
WavesDemo::WavesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "Waves";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* TwirlDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
auto size = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
return Twirl::create(t, Size(12, 8), Vec2(size.width / 2, size.height / 2), 1, 2.5f);
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
TwirlDemo::TwirlDemo()
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
_title = "Twirl";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* ShakyTiles3DDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
return ShakyTiles3D::create(t, Size(16, 12), 5, false);
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
ShakyTiles3DDemo::ShakyTiles3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "ShakyTiles3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* ShatteredTiles3DDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
return ShatteredTiles3D::create(t, Size(16, 12), 5, false);
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
ShatteredTiles3DDemo::ShatteredTiles3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "ShatteredTiles3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* ShuffleTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto shuffle = ShuffleTiles::create(t, Size(16, 12), 25);
2015-07-08 21:56:14 +08:00
auto shuffle_back = shuffle->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(2);
2015-07-08 21:56:14 +08:00
return Sequence::create(shuffle, delay, shuffle_back, nullptr);
}
2015-07-08 21:56:14 +08:00
ShuffleTilesDemo::ShuffleTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "ShuffleTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FadeOutTRTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto fadeout = FadeOutTRTiles::create(t, Size(16, 12));
auto back = fadeout->reverse();
auto delay = DelayTime::create(0.5f);
2015-07-08 21:56:14 +08:00
return Sequence::create(fadeout, delay, back, nullptr);
}
2015-07-08 21:56:14 +08:00
FadeOutTRTilesDemo::FadeOutTRTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "FadeOutTRTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FadeOutBLTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto fadeout = FadeOutBLTiles::create(t, Size(16, 12));
auto back = fadeout->reverse();
auto delay = DelayTime::create(0.5f);
2015-07-08 21:56:14 +08:00
return Sequence::create(fadeout, delay, back, nullptr);
}
2015-07-08 21:56:14 +08:00
FadeOutBLTilesDemo::FadeOutBLTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "FadeOutBLTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FadeOutUpTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto fadeout = FadeOutUpTiles::create(t, Size(16, 12));
auto back = fadeout->reverse();
auto delay = DelayTime::create(0.5f);
2015-07-08 21:56:14 +08:00
return Sequence::create(fadeout, delay, back, nullptr);
}
2015-07-08 21:56:14 +08:00
FadeOutUpTilesDemo::FadeOutUpTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "FadeOutUpTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* FadeOutDownTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto fadeout = FadeOutDownTiles::create(t, Size(16, 12));
auto back = fadeout->reverse();
auto delay = DelayTime::create(0.5f);
2015-07-08 21:56:14 +08:00
return Sequence::create(fadeout, delay, back, nullptr);
}
2015-07-08 21:56:14 +08:00
FadeOutDownTilesDemo::FadeOutDownTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "FadeOutDownTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* TurnOffTilesDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
auto fadeout = TurnOffTiles::create(t, Size(48, 32), 25);
auto back = fadeout->reverse();
auto delay = DelayTime::create(0.5f);
2015-07-08 21:56:14 +08:00
return Sequence::create(fadeout, delay, back, nullptr);
}
2015-07-08 21:56:14 +08:00
TurnOffTilesDemo::TurnOffTilesDemo()
{
2021-12-28 16:06:23 +08:00
_title = "TurnOffTiles";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* WavesTiles3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return WavesTiles3D::create(t, Size(15, 10), 4, 120);
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
WavesTiles3DDemo::WavesTiles3DDemo()
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
_title = "WavesTiles3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* JumpTiles3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return JumpTiles3D::create(t, Size(15, 10), 2, 30);
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
JumpTiles3DDemo::JumpTiles3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "JumpTiles3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* SplitRowsDemo::createEffect(float t)
2010-08-23 10:17:29 +08:00
{
2015-07-08 21:56:14 +08:00
return SplitRows::create(t, 9);
}
2015-07-08 21:56:14 +08:00
SplitRowsDemo::SplitRowsDemo()
{
2021-12-28 16:06:23 +08:00
_title = "SplitRows";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* SplitColsDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
return SplitCols::create(t, 9);
}
2015-07-08 21:56:14 +08:00
SplitColsDemo::SplitColsDemo()
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
_title = "SplitCols";
2015-07-08 21:56:14 +08:00
_subtitle = "";
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* PageTurn3DDemo::createEffect(float t)
2015-07-08 21:56:14 +08:00
{
2021-12-28 16:06:23 +08:00
return PageTurn3D::create(t, Size(15, 10));
2015-07-08 21:56:14 +08:00
}
2015-07-08 21:56:14 +08:00
PageTurn3DDemo::PageTurn3DDemo()
{
2021-12-28 16:06:23 +08:00
_title = "PageTurn3D";
2015-07-08 21:56:14 +08:00
_subtitle = "";
2015-07-08 22:34:33 +08:00
}
2022-10-18 19:17:36 +08:00
ax::ActionInterval* PageTurn3DRectDemo::createEffect(float t)
2015-07-08 22:34:33 +08:00
{
2021-12-28 16:06:23 +08:00
return PageTurn3D::create(t, Size(15, 10));
2015-07-08 22:34:33 +08:00
}
PageTurn3DRectDemo::PageTurn3DRectDemo()
{
2021-12-28 16:06:23 +08:00
_title = "PageTurn3D-Rect";
2015-07-08 22:34:33 +08:00
_subtitle = "";
2010-08-23 10:17:29 +08:00
}
2021-12-28 16:06:23 +08:00
#define SID_RESTART 1
2021-12-28 16:06:23 +08:00
EffectBaseTest::EffectBaseTest() : _gridNodeTarget(nullptr) {}
2015-07-08 22:34:33 +08:00
bool EffectBaseTest::init()
{
2021-12-28 16:06:23 +08:00
if (TestCase::init())
2015-07-08 22:34:33 +08:00
{
2021-12-28 16:06:23 +08:00
LayerColor* background = LayerColor::create(Color4B(32, 128, 32, 255));
this->addChild(background, -20);
if (isRectEffect())
2015-07-08 22:34:33 +08:00
{
Size visibleSize = Director::getInstance()->getVisibleSize();
2021-12-28 16:06:23 +08:00
Rect gridRect = Rect(visibleSize.width * 0.2, visibleSize.height * 0.2, visibleSize.width * 0.6,
visibleSize.height * 0.6);
_gridNodeTarget = NodeGrid::create(gridRect);
2015-07-08 22:34:33 +08:00
}
else
{
_gridNodeTarget = NodeGrid::create();
}
addChild(_gridNodeTarget, 0);
_gridNodeTarget->runAction(createEffect(3));
2021-12-28 16:06:23 +08:00
2015-07-08 22:34:33 +08:00
auto bg = Sprite::create(s_back3);
_gridNodeTarget->addChild(bg, 0);
bg->setPosition(VisibleRect::center());
2021-12-28 16:06:23 +08:00
2015-07-08 22:34:33 +08:00
auto grossini = Sprite::create(s_pathSister2);
_gridNodeTarget->addChild(grossini, 1);
2021-12-28 16:06:23 +08:00
grossini->setPosition(VisibleRect::left().x + VisibleRect::getVisibleRect().size.width / 3,
VisibleRect::center().y);
auto sc = ScaleBy::create(2, 5);
2015-07-08 22:34:33 +08:00
auto sc_back = sc->reverse();
2021-12-28 16:06:23 +08:00
grossini->runAction(RepeatForever::create(Sequence::create(sc, sc_back, nullptr)));
2015-07-08 22:34:33 +08:00
auto tamara = Sprite::create(s_pathSister1);
_gridNodeTarget->addChild(tamara, 1);
2021-12-28 16:06:23 +08:00
tamara->setPosition(VisibleRect::left().x + 2 * VisibleRect::getVisibleRect().size.width / 3,
VisibleRect::center().y);
auto sc2 = ScaleBy::create(2, 5);
2015-07-08 22:34:33 +08:00
auto sc2_back = sc2->reverse();
2021-12-28 16:06:23 +08:00
tamara->runAction(RepeatForever::create(Sequence::create(sc2, sc2_back, nullptr)));
2022-07-15 19:17:01 +08:00
schedule(AX_SCHEDULE_SELECTOR(EffectBaseTest::checkAnim));
2021-12-28 16:06:23 +08:00
2015-07-08 22:34:33 +08:00
return true;
}
return false;
}
void EffectBaseTest::checkAnim(float dt)
2010-08-23 10:17:29 +08:00
{
2021-12-28 16:06:23 +08:00
if (_gridNodeTarget->getNumberOfRunningActions() == 0 && _gridNodeTarget->getGrid() != nullptr)
2016-09-12 09:45:34 +08:00
_gridNodeTarget->setGrid(nullptr);
2010-08-23 10:17:29 +08:00
}
2021-12-28 16:06:23 +08:00
EffectBaseTest::~EffectBaseTest() {}