axmol/tests/Classes/ActionsEaseTest/ActionsEaseTest.cpp

1130 lines
35 KiB
C++
Raw Normal View History

/****************************************************************************
Copyright (c) 2012 cocos2d-x.org
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
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"
2010-08-25 17:02:58 +08:00
enum {
kTagAction1 = 1,
kTagAction2 = 2,
kTagSlider = 1,
};
Layer* nextEaseAction();
Layer* backEaseAction();
Layer* restartEaseAction();
//------------------------------------------------------------------
//
// SpriteDemo
//
//------------------------------------------------------------------
void EaseSpriteDemo::centerSprites(unsigned int numberOfSprites)
{
auto s = Director::getInstance()->getWinSize();
if( numberOfSprites == 0 )
{
_tamara->setVisible(false);
_kathia->setVisible(false);
_grossini->setVisible(false);
}
else if ( numberOfSprites == 1 )
{
_tamara->setVisible(false);
_kathia->setVisible(false);
_grossini->setPosition(Point(s.width/2, s.height/2));
}
else if( numberOfSprites == 2 )
{
_kathia->setPosition( Point(s.width/3, s.height/2));
_tamara->setPosition( Point(2*s.width/3, s.height/2));
_grossini->setVisible(false);
}
else if( numberOfSprites == 3 )
{
_grossini->setPosition( Point(s.width/2, s.height/2));
_tamara->setPosition( Point(s.width/4, s.height/2));
_kathia->setPosition( Point(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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130,0));
auto move_back = move->reverse();
auto move_ease_in = EaseIn::create(move->clone(), 2.5f);
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseOut::create(move->clone(), 2.5f);
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
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);
schedule(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
{
unschedule(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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130,0));
// id move_back = move->reverse();
auto move_ease_inout1 = EaseInOut::create(move->clone(), 0.65f);
auto move_ease_inout_back1 = move_ease_inout1->reverse();
auto move_ease_inout2 = EaseInOut::create(move->clone(), 1.35f);
auto move_ease_inout_back2 = move_ease_inout2->reverse();
auto move_ease_inout3 = EaseInOut::create(move->clone(), 1.0f);
auto move_ease_inout_back3 = move_ease_inout3->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create( move_ease_inout1, delay, move_ease_inout_back1, delay->clone(), NULL);
auto seq2 = Sequence::create( move_ease_inout2, delay->clone(), move_ease_inout_back2, delay->clone(), NULL);
auto seq3 = Sequence::create( move_ease_inout3, delay->clone(), move_ease_inout_back3, delay->clone(), NULL);
_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 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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130,0));
auto move_back = move->reverse();
auto move_ease_in = EaseExponentialIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseExponentialOut::create(move->clone());
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseExponentialInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse(); //--> reverse()
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create( move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create( move_ease, delay, move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_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 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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseSineIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseSineOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 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
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130,0));
auto move_back = move->reverse();
auto move_ease = EaseSineInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
2010-08-25 17:02:58 +08:00
this->positionForTwo();
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseElasticIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseElasticOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_ease_inout1 = EaseElasticInOut::create(move->clone(), 0.3f);
auto move_ease_inout_back1 = move_ease_inout1->reverse();
auto move_ease_inout2 = EaseElasticInOut::create(move->clone(), 0.45f);
auto move_ease_inout_back2 = move_ease_inout2->reverse();
auto move_ease_inout3 = EaseElasticInOut::create(move->clone(), 0.6f);
auto move_ease_inout_back3 = move_ease_inout3->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move_ease_inout1, delay, move_ease_inout_back1, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_inout2, delay->clone(), move_ease_inout_back2, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_inout3, delay->clone(), move_ease_inout_back3, delay->clone(), NULL);
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseBounceIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseBounceOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseBounceInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseBackIn::create(move->clone());
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseBackOut::create( move->clone());
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseBackInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_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();
auto s = Director::getInstance()->getWinSize();
//
// startPosition can be any coordinate, but since the movement
// is relative to the Bezier curve, make it (0,0)
//
centerSprites(3);
// sprite 1
ccBezierConfig bezier;
bezier.controlPoint_1 = Point(0, s.height/2);
bezier.controlPoint_2 = Point(300, -s.height/2);
bezier.endPosition = Point(300,100);
auto bezierForward = BezierBy::create(3, bezier);
auto bezierEaseForward = EaseBezierAction::create(bezierForward);
bezierEaseForward->setBezierParamer(0.5, 0.5, 1.0, 1.0);
auto bezierEaseBack = bezierEaseForward->reverse();
auto rep = RepeatForever::create(Sequence::create( bezierEaseForward, bezierEaseBack, NULL));
// sprite 2
_tamara->setPosition(Point(80,160));
ccBezierConfig bezier2;
bezier2.controlPoint_1 = Point(100, s.height/2);
bezier2.controlPoint_2 = Point(200, -s.height/2);
bezier2.endPosition = Point(240,160);
auto bezierTo1 = BezierTo::create(2, bezier2);
auto bezierEaseTo1 = EaseBezierAction::create(bezierTo1);
bezierEaseTo1->setBezierParamer(0.5, 0.5, 1.0, 1.0);
// sprite 3
_kathia->setPosition(Point(400,160));
auto bezierTo2 = BezierTo::create(2, bezier2);
auto bezierEaseTo2 = EaseBezierAction::create(bezierTo2);
bezierEaseTo2->setBezierParamer(0.0, 0.5, -5.0, 1.0);
_grossini->runAction( rep);
_tamara->runAction(bezierEaseTo1);
_kathia->runAction(bezierTo2);
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseBezier::subtitle()const
{
return "SpriteEaseBezier action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuadratic
//
//------------------------------------------------------------------
void SpriteEaseQuadratic::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseQuadraticActionIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseQuadraticActionOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseQuadraticActionInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_grossini->runAction( RepeatForever::create(seq1));
_tamara->runAction( RepeatForever::create(seq2));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseQuadraticInOut::subtitle()const
{
return "SpriteEaseQuadraticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuartic
//
//------------------------------------------------------------------
void SpriteEaseQuartic::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseQuarticActionIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseQuarticActionOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 SpriteEaseQuartic::subtitle()const
{
return "SpriteEaseQuartic action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuarticInOut
//
//------------------------------------------------------------------
void SpriteEaseQuarticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseQuarticActionInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_grossini->runAction( RepeatForever::create(seq1));
_tamara->runAction( RepeatForever::create(seq2));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseQuarticInOut::subtitle()const
{
return "SpriteEaseQuarticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuintic
//
//------------------------------------------------------------------
void SpriteEaseQuintic::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseQuinticActionIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseQuinticActionOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 SpriteEaseQuintic::subtitle()const
{
return "SpriteEaseQuintic action";
}
//------------------------------------------------------------------
//
// SpriteEaseQuinticInOut
//
//------------------------------------------------------------------
void SpriteEaseQuinticInOut::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseQuinticActionInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_grossini->runAction( RepeatForever::create(seq1));
_tamara->runAction( RepeatForever::create(seq2));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseQuinticInOut::subtitle()const
{
return "SpriteEaseQuinticInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseCircle
//
//------------------------------------------------------------------
void SpriteEaseCircle::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseCircleActionIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseCircleActionOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 SpriteEaseCircle::subtitle()const
{
return "SpriteEaseCircle action";
}
//------------------------------------------------------------------
//
// SpriteEaseCircleInOut
//
//------------------------------------------------------------------
void SpriteEaseCircleInOut::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseCircleActionInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_grossini->runAction( RepeatForever::create(seq1));
_tamara->runAction( RepeatForever::create(seq2));
}
2014-02-28 23:02:22 +08:00
std::string SpriteEaseCircleInOut::subtitle()const
{
return "SpriteEaseCircleInOut action";
}
//------------------------------------------------------------------
//
// SpriteEaseCubic
//
//------------------------------------------------------------------
void SpriteEaseCubic::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease_in = EaseCubicActionIn::create(move->clone() );
auto move_ease_in_back = move_ease_in->reverse();
auto move_ease_out = EaseCubicActionOut::create(move->clone() );
auto move_ease_out_back = move_ease_out->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease_in, delay->clone(), move_ease_in_back, delay->clone(), NULL);
auto seq3 = Sequence::create(move_ease_out, delay->clone(), move_ease_out_back, delay->clone(), NULL);
_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 SpriteEaseCubic::subtitle()const
{
return "SpriteEaseCubic action";
}
//------------------------------------------------------------------
//
// SpriteEaseCubicInOut
//
//------------------------------------------------------------------
void SpriteEaseCubicInOut::onEnter()
{
EaseSpriteDemo::onEnter();
auto move = MoveBy::create(3, Point(VisibleRect::right().x-130, 0));
auto move_back = move->reverse();
auto move_ease = EaseCubicActionInOut::create(move->clone() );
auto move_ease_back = move_ease->reverse();
auto delay = DelayTime::create(0.25f);
auto seq1 = Sequence::create(move, delay, move_back, delay->clone(), NULL);
auto seq2 = Sequence::create(move_ease, delay->clone(), move_ease_back, delay->clone(), NULL);
this->positionForTwo();
_grossini->runAction( RepeatForever::create(seq1));
_tamara->runAction( RepeatForever::create(seq2));
}
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();
auto s = Director::getInstance()->getWinSize();
// rotate and jump
auto jump1 = JumpBy::create(4, Point(-s.width+80, 0), 100, 4);
auto jump2 = jump1->reverse();
auto rot1 = RotateBy::create(4, 360*2);
auto rot2 = rot1->reverse();
auto seq3_1 = Sequence::create(jump2, jump1, NULL);
auto seq3_2 = Sequence::create( rot1, rot2, NULL);
auto spawn = Spawn::create(seq3_1, seq3_2, NULL);
auto action = Speed::create(RepeatForever::create(spawn), 1.0f);
action->setTag(kTagAction1);
auto action2 = action->clone();
auto action3 = action->clone();
action2->setTag(kTagAction1);
action3->setTag(kTagAction1);
_grossini->runAction(action2);
_tamara->runAction(action3);
_kathia->runAction(action);
this->schedule(schedule_selector(SpeedTest::altertime), 1.0f);//:@selector(altertime:) interval:1.0f];
}
2012-06-08 13:55:28 +08:00
void SpeedTest::altertime(float dt)
{
auto action1 = static_cast<Speed*>(_grossini->getActionByTag(kTagAction1));
auto action2 = static_cast<Speed*>(_tamara->getActionByTag(kTagAction1));
auto action3 = static_cast<Speed*>(_kathia->getActionByTag(kTagAction1));
2013-02-28 14:42:32 +08:00
action1->setSpeed( CCRANDOM_MINUS1_1() * 2 );
action2->setSpeed( CCRANDOM_MINUS1_1() * 2 );
action3->setSpeed( CCRANDOM_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
//
//------------------------------------------------------------------
2010-08-25 17:02:58 +08:00
enum
{
IDC_NEXT = 100,
IDC_BACK,
IDC_RESTART
2010-08-25 17:02:58 +08:00
};
static int sceneIdx = -1;
2010-08-25 17:02:58 +08:00
#define MAX_LAYER 24
2010-08-25 17:02:58 +08:00
Layer* createEaseLayer(int nIndex)
{
switch(nIndex)
{
case 0: return new SpriteEase();
case 1: return new SpriteEaseInOut();
case 2: return new SpriteEaseExponential();
case 3: return new SpriteEaseExponentialInOut();
case 4: return new SpriteEaseSine();
case 5: return new SpriteEaseSineInOut();
case 6: return new SpriteEaseElastic();
case 7: return new SpriteEaseElasticInOut();
case 8: return new SpriteEaseBounce();
case 9: return new SpriteEaseBounceInOut();
case 10: return new SpriteEaseBack();
case 11: return new SpriteEaseBackInOut();
case 12: return new SpriteEaseBezier();
case 13: return new SpriteEaseQuadratic();
case 14: return new SpriteEaseQuadraticInOut();
case 15: return new SpriteEaseQuartic();
case 16: return new SpriteEaseQuarticInOut();
case 17: return new SpriteEaseQuintic();
case 18: return new SpriteEaseQuinticInOut();
case 19: return new SpriteEaseCircle();
case 20: return new SpriteEaseCircleInOut();
case 21: return new SpriteEaseCubic();
case 22: return new SpriteEaseCubicInOut();
case MAX_LAYER-1: return new SpeedTest();
}
return NULL;
2010-08-25 17:02:58 +08:00
}
Layer* nextEaseAction()
2010-08-25 17:02:58 +08:00
{
sceneIdx++;
sceneIdx = sceneIdx % MAX_LAYER;
2010-08-25 17:02:58 +08:00
auto layer = createEaseLayer(sceneIdx);
layer->autorelease();
2010-08-25 17:02:58 +08:00
return layer;
2010-08-25 17:02:58 +08:00
}
Layer* backEaseAction()
2010-08-25 17:02:58 +08:00
{
sceneIdx--;
int total = MAX_LAYER;
if( sceneIdx < 0 )
sceneIdx += total;
auto layer = createEaseLayer(sceneIdx);
layer->autorelease();
2010-08-25 17:02:58 +08:00
return layer;
2010-08-25 17:02:58 +08:00
}
Layer* restartEaseAction()
2010-08-25 17:02:58 +08:00
{
auto layer = createEaseLayer(sceneIdx);
layer->autorelease();
return layer;
}
EaseSpriteDemo::EaseSpriteDemo(void)
{
}
EaseSpriteDemo::~EaseSpriteDemo(void)
{
_grossini->release();
_tamara->release();
_kathia->release();
}
2010-08-25 17:02:58 +08:00
void EaseSpriteDemo::positionForTwo()
{
2013-07-12 14:11:55 +08:00
_grossini->setPosition(Point(VisibleRect::left().x+60, VisibleRect::bottom().y + VisibleRect::getVisibleRect().size.height*1/5));
_tamara->setPosition(Point( 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()
{
BaseTest::onEnter();
2010-08-25 17:02:58 +08:00
// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
_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);
2013-07-12 14:11:55 +08:00
_grossini->setPosition(Point(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*1/5));
_kathia->setPosition(Point(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2.5f/5));
_tamara->setPosition(Point(VisibleRect::left().x + 60, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*4/5));
2010-08-25 17:02:58 +08:00
}
void EaseSpriteDemo::restartCallback(Ref* sender)
2010-08-25 17:02:58 +08:00
{
auto s = new ActionsEaseTestScene();//CCScene::create();
s->addChild(restartEaseAction());
2010-08-25 17:02:58 +08:00
Director::getInstance()->replaceScene(s);
2010-09-10 14:52:38 +08:00
s->release();
2010-08-25 17:02:58 +08:00
}
void EaseSpriteDemo::nextCallback(Ref* sender)
2010-08-25 17:02:58 +08:00
{
auto s = new ActionsEaseTestScene();//CCScene::create();
s->addChild( nextEaseAction() );
Director::getInstance()->replaceScene(s);
2010-09-10 14:52:38 +08:00
s->release();
2010-08-25 17:02:58 +08:00
}
void EaseSpriteDemo::backCallback(Ref* sender)
2010-08-25 17:02:58 +08:00
{
auto s = new ActionsEaseTestScene();//CCScene::create();
s->addChild( backEaseAction() );
Director::getInstance()->replaceScene(s);
2010-09-10 14:52:38 +08:00
s->release();
2010-08-25 17:02:58 +08:00
}
void ActionsEaseTestScene::runThisTest()
2010-08-25 17:02:58 +08:00
{
auto layer = nextEaseAction();
addChild(layer);
2010-08-25 17:02:58 +08:00
Director::getInstance()->replaceScene(this);
2010-08-25 17:02:58 +08:00
}