axmol/tests/cpp-tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp

1024 lines
33 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-10-01 16:24:52 +08:00
https://axmolengine.github.io/
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "ActionsEaseTest.h"
#include "../testResource.h"
USING_NS_AX;
2015-04-09 12:23:47 +08:00
2021-12-28 16:06:23 +08:00
enum
{
kTagAction1 = 1,
kTagAction2 = 2,
2021-12-28 16:06:23 +08:00
kTagSlider = 1,
};
//------------------------------------------------------------------
//
// SpriteDemo
//
//------------------------------------------------------------------
void EaseSpriteDemo::centerSprites(unsigned int numberOfSprites)
{
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
if (numberOfSprites == 0)
{
_tamara->setVisible(false);
_kathia->setVisible(false);
_grossini->setVisible(false);
}
2021-12-28 16:06:23 +08:00
else if (numberOfSprites == 1)
{
_tamara->setVisible(false);
_kathia->setVisible(false);
2021-12-28 16:06:23 +08:00
_grossini->setPosition(s.width / 2, s.height / 2);
}
2021-12-28 16:06:23 +08:00
else if (numberOfSprites == 2)
{
2021-12-28 16:06:23 +08:00
_kathia->setPosition(s.width / 3, s.height / 2);
_tamara->setPosition(2 * s.width / 3, s.height / 2);
_grossini->setVisible(false);
}
2021-12-28 16:06:23 +08:00
else if (numberOfSprites == 3)
{
2021-12-28 16:06:23 +08:00
_grossini->setPosition(s.width / 2, s.height / 2);
_tamara->setPosition(s.width / 4, s.height / 2);
_kathia->setPosition(3 * s.width / 4, s.height / 2);
}
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEase
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEase::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseIn::create(move->clone(), 2.5f);
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseOut::create(move->clone(), 2.5f);
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
auto a2 = _grossini->runAction(RepeatForever::create(seq1));
a2->setTag(1);
auto a1 = _tamara->runAction(RepeatForever::create(seq2));
a1->setTag(1);
auto a = _kathia->runAction(RepeatForever::create(seq3));
a->setTag(1);
2022-07-15 19:17:01 +08:00
schedule(AX_SCHEDULE_SELECTOR(SpriteEase::testStopAction), 6.25f);
2010-08-25 17:02:58 +08:00
}
2012-06-08 13:55:28 +08:00
void SpriteEase::testStopAction(float dt)
2010-08-25 17:02:58 +08:00
{
2022-07-15 19:17:01 +08:00
unschedule(AX_SCHEDULE_SELECTOR(SpriteEase::testStopAction));
_tamara->stopActionByTag(1);
_kathia->stopActionByTag(1);
_grossini->stopActionByTag(1);
2010-08-25 17:02:58 +08:00
}
2014-02-28 23:02:22 +08:00
std::string SpriteEase::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseIn - EaseOut - Stop";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
// id move_back = move->reverse();
auto move_ease_inout1 = EaseInOut::create(move->clone(), 0.65f);
auto move_ease_inout_back1 = move_ease_inout1->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_inout2 = EaseInOut::create(move->clone(), 1.35f);
auto move_ease_inout_back2 = move_ease_inout2->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_inout3 = EaseInOut::create(move->clone(), 1.0f);
auto move_ease_inout_back3 = move_ease_inout3->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move_ease_inout1, delay, move_ease_inout_back1, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_inout2, delay->clone(), move_ease_inout_back2, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_inout3, delay->clone(), move_ease_inout_back3, delay->clone(), nullptr);
_tamara->runAction(RepeatForever::create(seq1));
_kathia->runAction(RepeatForever::create(seq2));
_grossini->runAction(RepeatForever::create(seq3));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseInOut and rates";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseExponential
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseExponential::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseExponentialIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseExponentialOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseExponential::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "ExpIn - ExpOut actions";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseExponentialInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseExponentialInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseExponentialInOut::create(move->clone());
auto move_ease_back = move_ease->reverse(); //--> reverse()
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay, move_ease_back, delay->clone(), nullptr);
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseExponentialInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseExponentialInOut action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseSine
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseSine::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseSineIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseSineOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseSine::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseSineIn - EaseSineOut";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseSineInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseSineInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2010-08-25 17:02:58 +08:00
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseSineInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2010-08-25 17:02:58 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseSineInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseSineInOut action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseElastic
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseElastic::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseElasticIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseElasticOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseElastic::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "Elastic In - Out actions";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseElasticInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseElasticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_ease_inout1 = EaseElasticInOut::create(move->clone(), 0.3f);
auto move_ease_inout_back1 = move_ease_inout1->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_inout2 = EaseElasticInOut::create(move->clone(), 0.45f);
auto move_ease_inout_back2 = move_ease_inout2->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_inout3 = EaseElasticInOut::create(move->clone(), 0.6f);
auto move_ease_inout_back3 = move_ease_inout3->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move_ease_inout1, delay, move_ease_inout_back1, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_inout2, delay->clone(), move_ease_inout_back2, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_inout3, delay->clone(), move_ease_inout_back3, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_tamara->runAction(RepeatForever::create(seq1));
_kathia->runAction(RepeatForever::create(seq2));
_grossini->runAction(RepeatForever::create(seq3));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseElasticInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseElasticInOut action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseBounce
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseBounce::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseBounceIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseBounceOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseBounce::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "Bounce In - Out actions";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseBounceInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseBounceInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseBounceInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseBounceInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseBounceInOut action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseBack
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseBack::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseBackIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseBackOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
2021-12-28 16:06:23 +08:00
_kathia->runAction(RepeatForever::create(seq3));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseBack::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "Back In - Out actions";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpriteEaseBackInOut
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpriteEaseBackInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseBackInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2010-08-25 17:02:58 +08:00
2014-02-28 23:02:22 +08:00
std::string SpriteEaseBackInOut::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "EaseBackInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseBezier
//
//------------------------------------------------------------------
void SpriteEaseBezier::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
2021-12-28 16:06:23 +08:00
//
// startPosition can be any coordinate, but since the movement
// is relative to the Bezier curve, make it (0,0)
//
2021-12-28 16:06:23 +08:00
centerSprites(3);
2021-12-28 16:06:23 +08:00
// sprite 1
ccBezierConfig bezier;
2021-12-28 16:06:23 +08:00
bezier.controlPoint_1 = Vec2(0.0f, s.height / 2);
bezier.controlPoint_2 = Vec2(300.0f, -s.height / 2);
bezier.endPosition = Vec2(300.0f, 100.0f);
auto bezierForward = BezierBy::create(3, bezier);
auto bezierEaseForward = EaseBezierAction::create(bezierForward);
bezierEaseForward->setBezierParamer(0.5f, 0.5f, 1.0f, 1.0f);
2021-12-28 16:06:23 +08:00
auto bezierEaseBack = bezierEaseForward->reverse();
2021-12-28 16:06:23 +08:00
auto rep = RepeatForever::create(Sequence::create(bezierEaseForward, bezierEaseBack, nullptr));
// sprite 2
2021-12-28 16:06:23 +08:00
_tamara->setPosition(80, 160);
ccBezierConfig bezier2;
bezier2.controlPoint_1 = Vec2(100.0f, s.height / 2);
bezier2.controlPoint_2 = Vec2(200.0f, -s.height / 2);
bezier2.endPosition = Vec2(240.0f, 160.0f);
auto bezierTo1 = BezierTo::create(2, bezier2);
auto bezierEaseTo1 = EaseBezierAction::create(bezierTo1);
bezierEaseTo1->setBezierParamer(0.5f, 0.5f, 1.0f, 1.0f);
2021-12-28 16:06:23 +08:00
// sprite 3
2021-12-28 16:06:23 +08:00
_kathia->setPosition(400.0f, 160.0f);
auto bezierTo2 = BezierTo::create(2, bezier2);
auto bezierEaseTo2 = EaseBezierAction::create(bezierTo2);
bezierEaseTo2->setBezierParamer(0.0f, 0.5f, -5.0f, 1.0f);
2021-12-28 16:06:23 +08:00
_grossini->runAction(rep);
_tamara->runAction(bezierEaseTo1);
2014-05-29 14:00:43 +08:00
_kathia->runAction(bezierEaseTo2);
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseBezier::subtitle() const
{
return "SpriteEaseBezier action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuadratic
//
//------------------------------------------------------------------
void SpriteEaseQuadratic::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseQuadraticActionIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseQuadraticActionOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseQuadratic::subtitle() const
{
return "SpriteEaseQuadratic action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuadraticInOut
//
//------------------------------------------------------------------
void SpriteEaseQuadraticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseQuadraticActionInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseQuadraticInOut::subtitle() const
{
return "SpriteEaseQuadraticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuartic
//
//------------------------------------------------------------------
void SpriteEaseQuartic::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseQuarticActionIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseQuarticActionOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseQuartic::subtitle() const
{
return "SpriteEaseQuartic action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuarticInOut
//
//------------------------------------------------------------------
void SpriteEaseQuarticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseQuarticActionInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseQuarticInOut::subtitle() const
{
return "SpriteEaseQuarticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuintic
//
//------------------------------------------------------------------
void SpriteEaseQuintic::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseQuinticActionIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseQuinticActionOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseQuintic::subtitle() const
{
return "SpriteEaseQuintic action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuinticInOut
//
//------------------------------------------------------------------
void SpriteEaseQuinticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseQuinticActionInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseQuinticInOut::subtitle() const
{
return "SpriteEaseQuinticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseCircle
//
//------------------------------------------------------------------
void SpriteEaseCircle::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseCircleActionIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseCircleActionOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseCircle::subtitle() const
{
return "SpriteEaseCircle action";
}
//------------------------------------------------------------------
//
// SpriteEaseCircleInOut
//
//------------------------------------------------------------------
void SpriteEaseCircleInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseCircleActionInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseCircleInOut::subtitle() const
{
return "SpriteEaseCircleInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseCubic
//
//------------------------------------------------------------------
void SpriteEaseCubic::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_in = EaseCubicActionIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease_out = EaseCubicActionOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), nullptr);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
_kathia->runAction(RepeatForever::create(seq3));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseCubic::subtitle() const
{
return "SpriteEaseCubic action";
}
//------------------------------------------------------------------
//
// SpriteEaseCubicInOut
//
//------------------------------------------------------------------
void SpriteEaseCubicInOut::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto move = MoveBy::create(3, Vec2(VisibleRect::right().x - 130, 0.0f));
auto move_back = move->reverse();
2021-12-28 16:06:23 +08:00
auto move_ease = EaseCubicActionInOut::create(move->clone());
auto move_ease_back = move_ease->reverse();
2021-12-28 16:06:23 +08:00
auto delay = DelayTime::create(0.25f);
2021-12-28 16:06:23 +08:00
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), nullptr);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), nullptr);
2021-12-28 16:06:23 +08:00
this->positionForTwo();
2021-12-28 16:06:23 +08:00
_grossini->runAction(RepeatForever::create(seq1));
_tamara->runAction(RepeatForever::create(seq2));
}
2021-12-28 16:06:23 +08:00
std::string SpriteEaseCubicInOut::title() const
{
return "SpriteEaseCubicInOut action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// SpeedTest
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
void SpeedTest::onEnter()
{
EaseSpriteDemo::onEnter();
2021-12-28 16:06:23 +08:00
auto s = Director::getInstance()->getWinSize();
// rotate and jump
2021-12-28 16:06:23 +08:00
auto jump1 = JumpBy::create(4.0f, Vec2(-s.width + 80, 0.0f), 100.0f, 4);
auto jump2 = jump1->reverse();
2021-12-28 16:06:23 +08:00
auto rot1 = RotateBy::create(4.0f, 360 * 2.0f);
auto rot2 = rot1->reverse();
auto seq3_1 = Sequence::create(jump2, jump1, nullptr);
2021-12-28 16:06:23 +08:00
auto seq3_2 = Sequence::create(rot1, rot2, nullptr);
auto spawn = Spawn::create(seq3_1, seq3_2, nullptr);
auto action = Speed::create(RepeatForever::create(spawn), 1.0f);
action->setTag(kTagAction1);
2021-12-28 16:06:23 +08:00
auto action2 = action->clone();
auto action3 = action->clone();
action2->setTag(kTagAction1);
action3->setTag(kTagAction1);
2021-12-28 16:06:23 +08:00
_grossini->runAction(action2);
_tamara->runAction(action3);
_kathia->runAction(action);
2021-12-28 16:06:23 +08:00
2022-07-15 19:17:01 +08:00
this->schedule(AX_SCHEDULE_SELECTOR(SpeedTest::altertime), 1.0f); //:@selector(altertime:) interval:1.0f];
}
2012-06-08 13:55:28 +08:00
void SpeedTest::altertime(float dt)
2021-12-28 16:06:23 +08:00
{
auto action1 = static_cast<Speed*>(_grossini->getActionByTag(kTagAction1));
auto action2 = static_cast<Speed*>(_tamara->getActionByTag(kTagAction1));
auto action3 = static_cast<Speed*>(_kathia->getActionByTag(kTagAction1));
2021-12-28 16:06:23 +08:00
2022-07-16 10:43:05 +08:00
action1->setSpeed(rand_minus1_1() * 2);
action2->setSpeed(rand_minus1_1() * 2);
action3->setSpeed(rand_minus1_1() * 2);
2010-08-25 17:02:58 +08:00
}
2014-02-28 23:02:22 +08:00
std::string SpeedTest::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "Speed action";
}
2010-08-25 17:02:58 +08:00
//------------------------------------------------------------------
//
// EaseSpriteDemo
//
//------------------------------------------------------------------
ActionsEaseTests::ActionsEaseTests()
2010-08-25 17:02:58 +08:00
{
ADD_TEST_CASE(SpriteEase);
ADD_TEST_CASE(SpriteEaseInOut);
ADD_TEST_CASE(SpriteEaseExponential);
ADD_TEST_CASE(SpriteEaseExponentialInOut);
ADD_TEST_CASE(SpriteEaseSine);
ADD_TEST_CASE(SpriteEaseSineInOut);
ADD_TEST_CASE(SpriteEaseElastic);
ADD_TEST_CASE(SpriteEaseElasticInOut);
ADD_TEST_CASE(SpriteEaseBounce);
ADD_TEST_CASE(SpriteEaseBounceInOut);
ADD_TEST_CASE(SpriteEaseBack);
ADD_TEST_CASE(SpriteEaseBackInOut);
ADD_TEST_CASE(SpriteEaseBezier);
ADD_TEST_CASE(SpriteEaseQuadratic);
ADD_TEST_CASE(SpriteEaseQuadraticInOut);
ADD_TEST_CASE(SpriteEaseQuartic);
ADD_TEST_CASE(SpriteEaseQuarticInOut);
ADD_TEST_CASE(SpriteEaseQuintic);
ADD_TEST_CASE(SpriteEaseQuinticInOut);
ADD_TEST_CASE(SpriteEaseCircle);
ADD_TEST_CASE(SpriteEaseCircleInOut);
ADD_TEST_CASE(SpriteEaseCubic);
ADD_TEST_CASE(SpriteEaseCubicInOut);
ADD_TEST_CASE(SpeedTest);
2010-08-25 17:02:58 +08:00
}
2021-12-28 16:06:23 +08:00
EaseSpriteDemo::EaseSpriteDemo() {}
EaseSpriteDemo::~EaseSpriteDemo()
{
_grossini->release();
_tamara->release();
_kathia->release();
}
2010-08-25 17:02:58 +08:00
void EaseSpriteDemo::positionForTwo()
2021-12-28 16:06:23 +08:00
{
_grossini->setPosition(VisibleRect::left().x + 60,
VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height * 1 / 5);
_tamara->setPosition(VisibleRect::left().x + 60,
VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height * 4 / 5);
_kathia->setVisible(false);
2010-08-25 17:02:58 +08:00
}
2014-02-28 23:02:22 +08:00
std::string EaseSpriteDemo::subtitle() const
2010-08-25 17:02:58 +08:00
{
return "No title";
2010-08-25 17:02:58 +08:00
}
void EaseSpriteDemo::onEnter()
{
TestCase::onEnter();
2010-08-25 17:02:58 +08:00
2019-08-20 15:15:40 +08:00
// Or you can create an sprite using a filename. PNG and BMP files are supported.
2021-12-28 16:06:23 +08:00
_grossini = Sprite::create(s_pathGrossini);
_grossini->retain();
_tamara = Sprite::create(s_pathSister1);
_tamara->retain();
_kathia = Sprite::create(s_pathSister2);
_kathia->retain();
addChild(_grossini, 3);
addChild(_kathia, 2);
addChild(_tamara, 1);
_grossini->setPosition(VisibleRect::left().x + 60,
VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height * 1 / 5);
_kathia->setPosition(VisibleRect::left().x + 60,
VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height * 2.5f / 5);
_tamara->setPosition(VisibleRect::left().x + 60,
VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height * 4 / 5);
2010-08-25 17:02:58 +08:00
}