2014-01-14 06:48:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "ActionsTest.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "../testResource.h"
|
2012-06-19 13:50:11 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/renderer/CCRenderer.h"
|
|
|
|
#include "2d/renderer/CCCustomCommand.h"
|
|
|
|
#include "2d/renderer/CCGroupCommand.h"
|
2013-12-25 09:51:55 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static std::function<Layer*()> createFunctions[] = {
|
2013-06-19 06:06:53 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
CL(ActionManual),
|
|
|
|
CL(ActionMove),
|
|
|
|
CL(ActionRotate),
|
2014-02-23 11:16:42 +08:00
|
|
|
CL(ActionRotateBy3D),
|
2013-06-07 08:12:28 +08:00
|
|
|
CL(ActionScale),
|
|
|
|
CL(ActionSkew),
|
|
|
|
CL(ActionRotationalSkew),
|
|
|
|
CL(ActionRotationalSkewVSStandardSkew),
|
|
|
|
CL(ActionSkewRotateScale),
|
|
|
|
CL(ActionJump),
|
|
|
|
CL(ActionCardinalSpline),
|
|
|
|
CL(ActionCatmullRom),
|
|
|
|
CL(ActionBezier),
|
|
|
|
CL(ActionBlink),
|
|
|
|
CL(ActionFade),
|
|
|
|
CL(ActionTint),
|
|
|
|
CL(ActionAnimate),
|
|
|
|
CL(ActionSequence),
|
|
|
|
CL(ActionSequence2),
|
|
|
|
CL(ActionRemoveSelf),
|
|
|
|
CL(ActionSpawn),
|
|
|
|
CL(ActionReverse),
|
|
|
|
CL(ActionDelayTime),
|
|
|
|
CL(ActionRepeat),
|
|
|
|
CL(ActionRepeatForever),
|
|
|
|
CL(ActionRotateToRepeat),
|
|
|
|
CL(ActionRotateJerk),
|
|
|
|
CL(ActionCallFunction),
|
2013-06-22 05:58:52 +08:00
|
|
|
CL(ActionCallFuncN),
|
2013-06-07 08:12:28 +08:00
|
|
|
CL(ActionCallFuncND),
|
2013-06-22 05:58:52 +08:00
|
|
|
CL(ActionCallFuncO),
|
2013-06-07 08:12:28 +08:00
|
|
|
CL(ActionReverseSequence),
|
|
|
|
CL(ActionReverseSequence2),
|
|
|
|
CL(ActionOrbit),
|
|
|
|
CL(ActionFollow),
|
|
|
|
CL(ActionTargeted),
|
2013-08-01 10:28:18 +08:00
|
|
|
CL(ActionTargetedReverse),
|
2013-06-07 08:12:28 +08:00
|
|
|
CL(ActionMoveStacked),
|
|
|
|
CL(ActionMoveJumpStacked),
|
|
|
|
CL(ActionMoveBezierStacked),
|
|
|
|
CL(ActionCardinalSplineStacked),
|
|
|
|
CL(ActionCatmullRomStacked),
|
|
|
|
CL(PauseResumeActions),
|
|
|
|
CL(Issue1305),
|
|
|
|
CL(Issue1305_2),
|
|
|
|
CL(Issue1288),
|
|
|
|
CL(Issue1288_2),
|
|
|
|
CL(Issue1327),
|
|
|
|
CL(Issue1398)
|
2013-02-28 14:42:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int sceneIdx=-1;
|
|
|
|
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* nextAction()
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* backAction()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-02-28 14:42:45 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
static Layer* restartAction()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = (createFunctions[sceneIdx])();
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionsTestScene::runThisTest()
|
|
|
|
{
|
2013-02-28 14:42:45 +08:00
|
|
|
sceneIdx = -1;
|
|
|
|
addChild(nextAction());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionsDemo::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "ActionsTest";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionsDemo::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionsDemo::onEnter()
|
|
|
|
{
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onEnter();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Or you can create an sprite using a filename. only PNG is supported now. Probably TIFF too
|
2013-07-24 06:20:22 +08:00
|
|
|
_grossini = Sprite::create(s_pathGrossini);
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
_tamara = Sprite::create(s_pathSister1);
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
_kathia = Sprite::create(s_pathSister2);
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_grossini, 1);
|
|
|
|
addChild(_tamara, 2);
|
|
|
|
addChild(_kathia, 3);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition(Vector2(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/3));
|
|
|
|
_tamara->setPosition(Vector2(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height*2/3));
|
|
|
|
_kathia->setPosition(Vector2(VisibleRect::center().x, VisibleRect::bottom().y+VisibleRect::getVisibleRect().size.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionsDemo::onExit()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->release();
|
|
|
|
_tamara->release();
|
|
|
|
_kathia->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-07 08:12:28 +08:00
|
|
|
BaseTest::onExit();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionsDemo::restartCallback(Ref* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ActionsTestScene();
|
2013-02-28 14:42:45 +08:00
|
|
|
s->addChild( restartAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionsDemo::nextCallback(Ref* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ActionsTestScene();
|
2013-02-28 14:42:45 +08:00
|
|
|
s->addChild( nextAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void ActionsDemo::backCallback(Ref* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new ActionsTestScene();
|
2013-02-28 14:42:45 +08:00
|
|
|
s->addChild( backAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionsDemo::centerSprites(unsigned int numberOfSprites)
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if( numberOfSprites == 0 )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setVisible(false);
|
|
|
|
_kathia->setVisible(false);
|
|
|
|
_grossini->setVisible(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if ( numberOfSprites == 1 )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setVisible(false);
|
|
|
|
_kathia->setVisible(false);
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition(Vector2(s.width/2, s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if( numberOfSprites == 2 )
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition( Vector2(s.width/3, s.height/2));
|
|
|
|
_tamara->setPosition( Vector2(2*s.width/3, s.height/2));
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->setVisible(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if( numberOfSprites == 3 )
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition( Vector2(s.width/2, s.height/2));
|
|
|
|
_tamara->setPosition( Vector2(s.width/4, s.height/2));
|
|
|
|
_kathia->setPosition( Vector2(3 * s.width/4, s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionsDemo::alignSpritesLeft(unsigned int numberOfSprites)
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if( numberOfSprites == 1 )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setVisible(false);
|
|
|
|
_kathia->setVisible(false);
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition(Vector2(60, s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if( numberOfSprites == 2 )
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition( Vector2(60, s.height/3));
|
|
|
|
_tamara->setPosition( Vector2(60, 2*s.height/3));
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->setVisible( false );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else if( numberOfSprites == 3 )
|
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition( Vector2(60, s.height/2));
|
|
|
|
_tamara->setPosition( Vector2(60, 2*s.height/3));
|
|
|
|
_kathia->setPosition( Vector2(60, s.height/3));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionManual
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionManual::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setScaleX( 2.5f);
|
|
|
|
_tamara->setScaleY( -1.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition( Vector2(100,70) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setOpacity( 128);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->setRotation( 120);
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition( Vector2(s.width/2, s.height/2));
|
2013-07-05 16:49:22 +08:00
|
|
|
_grossini->setColor( Color3B( 255,0,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition( Vector2(s.width-100, s.height/2));
|
2013-07-08 18:11:32 +08:00
|
|
|
_kathia->setColor( Color3B::BLUE);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionManual::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Manual Transformation";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionMove
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionMove::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto actionTo = MoveTo::create(2, Vector2(s.width-40, s.height-40));
|
|
|
|
auto actionBy = MoveBy::create(2, Vector2(80,80));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionByBack = actionBy->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction( actionTo);
|
2013-06-20 14:17:10 +08:00
|
|
|
_grossini->runAction( Sequence::create(actionBy, actionByBack, NULL));
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->runAction(MoveTo::create(1, Vector2(40,40)));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionMove::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "MoveTo / MoveBy";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionScale
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionScale::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionTo = ScaleTo::create(2.0f, 0.5f);
|
|
|
|
auto actionBy = ScaleBy::create(2.0f, 1.0f, 10.0f);
|
|
|
|
auto actionBy2 = ScaleBy::create(2.0f, 5.0f, 1.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction( actionTo);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( Sequence::create(actionBy, actionBy->reverse(), NULL));
|
|
|
|
_kathia->runAction( Sequence::create(actionBy2, actionBy2->reverse(), NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionScale::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "ScaleTo / ScaleBy";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionSkew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionSkew::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionTo = SkewTo::create(2, 37.2f, -37.2f);
|
|
|
|
auto actionToBack = SkewTo::create(2, 0, 0);
|
|
|
|
auto actionBy = SkewBy::create(2, 0.0f, -90.0f);
|
|
|
|
auto actionBy2 = SkewBy::create(2, 45.0f, 45.0f);
|
|
|
|
auto actionByBack = actionBy->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction(Sequence::create(actionTo, actionToBack, NULL));
|
|
|
|
_grossini->runAction(Sequence::create(actionBy, actionByBack, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_kathia->runAction(Sequence::create(actionBy2, actionBy2->reverse(), NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionSkew::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "SkewTo / SkewBy";
|
|
|
|
}
|
|
|
|
|
2013-02-28 14:42:45 +08:00
|
|
|
// ActionRotationalSkew
|
|
|
|
void ActionRotationalSkew::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
this->centerSprites(3);
|
|
|
|
|
2013-12-21 11:37:14 +08:00
|
|
|
auto actionTo = RotateTo::create(2, 180, 180);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionToBack = RotateTo::create(2, 0, 0);
|
2013-12-21 11:37:14 +08:00
|
|
|
auto actionBy = RotateBy::create(2, 0.0f, 360);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionByBack = actionBy->reverse();
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-12-21 11:37:14 +08:00
|
|
|
auto actionBy2 = RotateBy::create(2, 360, 0);
|
|
|
|
auto actionBy2Back = actionBy2->reverse();
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-12-21 11:37:14 +08:00
|
|
|
_tamara->runAction( Sequence::create(actionBy, actionByBack, NULL) );
|
|
|
|
_grossini->runAction( Sequence::create(actionTo, actionToBack, NULL) );
|
|
|
|
_kathia->runAction( Sequence::create(actionBy2, actionBy2Back, NULL) );
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRotationalSkew::subtitle() const
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
|
|
|
return "RotationalSkewTo / RotationalSkewBy";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//ActionRotationalSkewVSStandardSkew
|
|
|
|
void ActionRotationalSkewVSStandardSkew::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->removeFromParentAndCleanup(true);
|
|
|
|
_grossini->removeFromParentAndCleanup(true);
|
|
|
|
_kathia->removeFromParentAndCleanup(true);
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
Size boxSize(100.0f, 100.0f);
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
auto box = LayerColor::create(Color4B(255,255,0,255));
|
2014-04-15 18:23:40 +08:00
|
|
|
box->setAnchorPoint(Vector2(0.5,0.5));
|
2013-02-28 14:42:45 +08:00
|
|
|
box->setContentSize( boxSize );
|
|
|
|
box->ignoreAnchorPointForPosition(false);
|
2014-04-15 18:23:40 +08:00
|
|
|
box->setPosition(Vector2(s.width/2, s.height - 100 - box->getContentSize().height/2));
|
2013-02-28 14:42:45 +08:00
|
|
|
this->addChild(box);
|
2013-06-22 03:25:36 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("Standard cocos2d Skew", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2(s.width/2, s.height - 100 + label->getContentSize().height));
|
2013-02-28 14:42:45 +08:00
|
|
|
this->addChild(label);
|
2013-06-22 03:25:36 +08:00
|
|
|
|
|
|
|
auto actionTo = SkewBy::create(2, 360, 0);
|
|
|
|
auto actionToBack = SkewBy::create(2, -360, 0);
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
box->runAction(Sequence::create(actionTo, actionToBack, NULL));
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
box = LayerColor::create(Color4B(255,255,0,255));
|
2014-04-15 18:23:40 +08:00
|
|
|
box->setAnchorPoint(Vector2(0.5,0.5));
|
2013-02-28 14:42:45 +08:00
|
|
|
box->setContentSize(boxSize);
|
|
|
|
box->ignoreAnchorPointForPosition(false);
|
2014-04-15 18:23:40 +08:00
|
|
|
box->setPosition(Vector2(s.width/2, s.height - 250 - box->getContentSize().height/2));
|
2013-02-28 14:42:45 +08:00
|
|
|
this->addChild(box);
|
2013-06-22 03:25:36 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
label = Label::createWithTTF("Rotational Skew", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2(s.width/2, s.height - 250 + label->getContentSize().height/2));
|
2013-02-28 14:42:45 +08:00
|
|
|
this->addChild(label);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionTo2 = RotateBy::create(2, 360, 0);
|
|
|
|
auto actionToBack2 = RotateBy::create(2, -360, 0);
|
2013-06-20 14:17:10 +08:00
|
|
|
box->runAction(Sequence::create(actionTo2, actionToBack2, NULL));
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRotationalSkewVSStandardSkew::subtitle() const
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
|
|
|
return "Skew Comparison";
|
|
|
|
}
|
2012-11-19 17:15:16 +08:00
|
|
|
|
|
|
|
// ActionSkewRotateScale
|
2012-04-19 14:35:52 +08:00
|
|
|
void ActionSkewRotateScale::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->removeFromParentAndCleanup(true);
|
|
|
|
_grossini->removeFromParentAndCleanup(true);
|
|
|
|
_kathia->removeFromParentAndCleanup(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
Size boxSize(100.0f, 100.0f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
auto box = LayerColor::create(Color4B(255, 255, 0, 255));
|
2014-04-15 18:23:40 +08:00
|
|
|
box->setAnchorPoint(Vector2(0, 0));
|
|
|
|
box->setPosition(Vector2(190, 110));
|
2012-04-19 14:35:52 +08:00
|
|
|
box->setContentSize(boxSize);
|
|
|
|
|
|
|
|
static float markrside = 10.0f;
|
2013-07-05 16:49:22 +08:00
|
|
|
auto uL = LayerColor::create(Color4B(255, 0, 0, 255));
|
2012-04-19 14:35:52 +08:00
|
|
|
box->addChild(uL);
|
2013-07-12 14:30:26 +08:00
|
|
|
uL->setContentSize(Size(markrside, markrside));
|
2014-04-15 18:23:40 +08:00
|
|
|
uL->setPosition(Vector2(0.f, boxSize.height - markrside));
|
|
|
|
uL->setAnchorPoint(Vector2(0, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
auto uR = LayerColor::create(Color4B(0, 0, 255, 255));
|
2012-04-19 14:35:52 +08:00
|
|
|
box->addChild(uR);
|
2013-07-12 14:30:26 +08:00
|
|
|
uR->setContentSize(Size(markrside, markrside));
|
2014-04-15 18:23:40 +08:00
|
|
|
uR->setPosition(Vector2(boxSize.width - markrside, boxSize.height - markrside));
|
|
|
|
uR->setAnchorPoint(Vector2(0, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(box);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionTo = SkewTo::create(2, 0.f, 2.f);
|
|
|
|
auto rotateTo = RotateTo::create(2, 61.0f);
|
|
|
|
auto actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f);
|
|
|
|
auto rotateToBack = RotateTo::create(2, 0);
|
|
|
|
auto actionToBack = SkewTo::create(2, 0, 0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
box->runAction(Sequence::create(actionTo, actionToBack, NULL));
|
|
|
|
box->runAction(Sequence::create(rotateTo, rotateToBack, NULL));
|
|
|
|
box->runAction(Sequence::create(actionScaleTo, actionScaleToBack, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionSkewRotateScale::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Skew + Rotate + Scale";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRotate
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRotate::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionTo = RotateTo::create( 2, 45);
|
|
|
|
auto actionTo2 = RotateTo::create( 2, -45);
|
|
|
|
auto actionTo0 = RotateTo::create(2 , 0);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( Sequence::create(actionTo, actionTo0, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionBy = RotateBy::create(2 , 360);
|
|
|
|
auto actionByBack = actionBy->reverse();
|
2013-06-20 14:17:10 +08:00
|
|
|
_grossini->runAction( Sequence::create(actionBy, actionByBack, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_kathia->runAction( Sequence::create(actionTo2, actionTo0->clone(), NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRotate::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "RotateTo / RotateBy";
|
|
|
|
}
|
|
|
|
|
2014-02-23 11:16:42 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRotateBy3D
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRotateBy3D::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2014-04-02 15:25:19 +08:00
|
|
|
auto actionBy1 = RotateBy::create(4, Vector3(360, 0, 0));
|
|
|
|
auto actionBy2 = RotateBy::create(4, Vector3(0, 360, 0));
|
|
|
|
auto actionBy3 = RotateBy::create(4 ,Vector3(0, 0, 360));
|
2014-02-23 11:16:42 +08:00
|
|
|
|
2014-03-25 06:09:24 +08:00
|
|
|
_tamara->runAction( Sequence::create(actionBy1, actionBy1->reverse(), nullptr));
|
|
|
|
_grossini->runAction( Sequence::create(actionBy2, actionBy2->reverse(), nullptr));
|
|
|
|
_kathia->runAction( Sequence::create(actionBy3, actionBy3->reverse(), nullptr));
|
2014-02-23 11:16:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string ActionRotateBy3D::subtitle() const
|
|
|
|
{
|
|
|
|
return "RotateBy in 3D";
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionJump
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionJump::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto actionTo = JumpTo::create(2, Vector2(300,300), 50, 4);
|
|
|
|
auto actionBy = JumpBy::create(2, Vector2(300,0), 50, 4);
|
|
|
|
auto actionUp = JumpBy::create(2, Vector2(0,0), 80, 4);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actionByBack = actionBy->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction( actionTo);
|
2013-06-20 14:17:10 +08:00
|
|
|
_grossini->runAction( Sequence::create(actionBy, actionByBack, NULL));
|
|
|
|
_kathia->runAction( RepeatForever::create(actionUp));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionJump::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "JumpTo / JumpBy";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionBezier
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionBezier::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
2014-04-15 18:23:40 +08:00
|
|
|
bezier.controlPoint_1 = Vector2(0, s.height/2);
|
|
|
|
bezier.controlPoint_2 = Vector2(300, -s.height/2);
|
|
|
|
bezier.endPosition = Vector2(300,100);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto bezierForward = BezierBy::create(3, bezier);
|
|
|
|
auto bezierBack = bezierForward->reverse();
|
|
|
|
auto rep = RepeatForever::create(Sequence::create( bezierForward, bezierBack, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
// sprite 2
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition(Vector2(80,160));
|
2013-06-22 03:25:36 +08:00
|
|
|
ccBezierConfig bezier2;
|
2014-04-15 18:23:40 +08:00
|
|
|
bezier2.controlPoint_1 = Vector2(100, s.height/2);
|
|
|
|
bezier2.controlPoint_2 = Vector2(200, -s.height/2);
|
|
|
|
bezier2.endPosition = Vector2(240,160);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto bezierTo1 = BezierTo::create(2, bezier2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// sprite 3
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition(Vector2(400,160));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto bezierTo2 = BezierTo::create(2, bezier2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction( rep);
|
|
|
|
_tamara->runAction(bezierTo1);
|
|
|
|
_kathia->runAction(bezierTo2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionBezier::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "BezierBy / BezierTo";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionBlink
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionBlink::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(2);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action1 = Blink::create(2, 10);
|
|
|
|
auto action2 = Blink::create(2, 5);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction( action1);
|
|
|
|
_kathia->runAction(action2);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionBlink::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Blink";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionFade
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionFade::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(2);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setOpacity( 0 );
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action1 = FadeIn::create(1.0f);
|
|
|
|
auto action1Back = action1->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action2 = FadeOut::create(1.0f);
|
|
|
|
auto action2Back = action2->reverse();
|
2014-02-25 15:30:54 +08:00
|
|
|
auto action2BackReverse = action2Back->reverse();
|
|
|
|
auto action2BackReverseReverse = action2BackReverse->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-02-25 15:30:54 +08:00
|
|
|
_tamara->setOpacity(122);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( Sequence::create( action1, action1Back, NULL));
|
2014-02-25 15:30:54 +08:00
|
|
|
_kathia->setOpacity(122);
|
|
|
|
_kathia->runAction( Sequence::create( action2, action2Back,action2BackReverse,action2BackReverseReverse, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionFade::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "FadeIn / FadeOut";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionTint
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ActionTint::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(2);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action1 = TintTo::create(2, 255, 0, 255);
|
|
|
|
auto action2 = TintBy::create(2, -127, -255, -127);
|
|
|
|
auto action2Back = action2->reverse();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction( action1);
|
2013-06-20 14:17:10 +08:00
|
|
|
_kathia->runAction( Sequence::create( action2, action2Back, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionTint::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "TintTo / TintBy";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionAnimate
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionAnimate::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Manual animation
|
|
|
|
//
|
2013-08-16 16:05:27 +08:00
|
|
|
auto animation = Animation::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int i=1;i<15;i++)
|
|
|
|
{
|
|
|
|
char szName[100] = {0};
|
|
|
|
sprintf(szName, "Images/grossini_dance_%02d.png", i);
|
2013-09-16 20:38:03 +08:00
|
|
|
animation->addSpriteFrameWithFile(szName);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
// should last 2.8 seconds. And there are 14 frames.
|
|
|
|
animation->setDelayPerUnit(2.8f / 14.0f);
|
|
|
|
animation->setRestoreOriginalFrame(true);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = Animate::create(animation);
|
2013-06-20 14:17:10 +08:00
|
|
|
_grossini->runAction(Sequence::create(action, action->reverse(), NULL));
|
2012-07-23 22:49:11 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// File animation
|
|
|
|
//
|
|
|
|
// With 2 loops and reverse
|
2013-08-16 16:05:27 +08:00
|
|
|
auto cache = AnimationCache::getInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
cache->addAnimationsWithFile("animations/animations-2.plist");
|
2013-09-16 20:38:03 +08:00
|
|
|
auto animation2 = cache->getAnimation("dance_1");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action2 = Animate::create(animation2);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction(Sequence::create(action2, action2->reverse(), NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// TODO:
|
2013-06-20 14:17:10 +08:00
|
|
|
// observer_ = [[NSNotificationCenter defaultCenter] addObserverForName:AnimationFrameDisplayedNotification object:nil queue:nil usingBlock:^(NSNotification* notification) {
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
2013-08-16 16:05:27 +08:00
|
|
|
// auto userInfo = [notification userInfo);
|
2013-02-28 15:32:27 +08:00
|
|
|
// NSLog(@"object %@ with data %@", [notification object), userInfo );
|
2013-02-28 14:42:45 +08:00
|
|
|
// });
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// File animation
|
|
|
|
//
|
|
|
|
// with 4 loops
|
2013-08-16 16:05:27 +08:00
|
|
|
auto animation3 = animation2->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
animation3->setLoops(4);
|
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action3 = Animate::create(animation3);
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(action3);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionAnimate::onExit()
|
|
|
|
{
|
|
|
|
ActionsDemo::onExit();
|
2013-02-28 14:42:45 +08:00
|
|
|
//TODO:[[NSNotificationCenter defaultCenter] removeObserver:observer_);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionAnimate::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Animation";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionAnimate::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Center: Manual animation. Border: using file format animation";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionSequence
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionSequence::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create( 2, Vector2(240,0)),
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy::create( 2, 540),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionSequence::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Sequence: Move + Rotate";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionSequence2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionSequence2::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->setVisible(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
Place::create(Vector2(200,200)),
|
2013-06-20 14:17:10 +08:00
|
|
|
Show::create(),
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(1, Vector2(100,0)),
|
2013-06-20 14:17:10 +08:00
|
|
|
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback1,this)),
|
|
|
|
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback2,this,_grossini)),
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFunc::create( CC_CALLBACK_0(ActionSequence2::callback3,this,_grossini,0xbebabeba)),
|
2013-06-04 03:13:24 +08:00
|
|
|
NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionSequence2::callback1()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 1 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*1,s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(label);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionSequence2::callback2(Node* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 2 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*2,s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(label);
|
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
void ActionSequence2::callback3(Node* sender, long data)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 3 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*3,s.height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(label);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionSequence2::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Sequence of InstantActions";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2013-06-22 05:58:52 +08:00
|
|
|
// ActionCallFuncN
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2013-06-22 05:58:52 +08:00
|
|
|
void ActionCallFuncN::onEnter()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
centerSprites(1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(2.0f, Vector2(150,0)),
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFuncN::create( CC_CALLBACK_1(ActionCallFuncN::callback, this)),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncN::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
return "CallFuncN";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncN::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
return "Grossini should jump after moving";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
void ActionCallFuncN::callback(Node* sender )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
auto a = JumpBy::create(5, Vector2(0,0), 100, 5);
|
2013-06-22 05:58:52 +08:00
|
|
|
sender->runAction(a);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionCallFuncND
|
2013-06-22 05:58:52 +08:00
|
|
|
// CallFuncND is no longer needed. It can simulated with std::bind()
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionCallFuncND::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(1);
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(2.0f, Vector2(200,0)),
|
2013-07-17 16:25:13 +08:00
|
|
|
CallFuncN::create( CC_CALLBACK_1(ActionCallFuncND::doRemoveFromParentAndCleanup, this, true)),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncND::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "CallFuncND + auto remove";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncND::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
return "simulates CallFuncND with std::bind()";
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void ActionCallFuncND::doRemoveFromParentAndCleanup(Node* sender, bool cleanup)
|
2013-06-22 05:58:52 +08:00
|
|
|
{
|
|
|
|
_grossini->removeFromParentAndCleanup(cleanup);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionCallFuncO
|
|
|
|
// CallFuncO is no longer needed. It can simulated with std::bind()
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionCallFuncO::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(1);
|
|
|
|
|
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(2.0f, Vector2(200,0)),
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFunc::create( CC_CALLBACK_0(ActionCallFuncO::callback, this, _grossini, true)),
|
|
|
|
NULL);
|
|
|
|
_grossini->runAction(action);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncO::title() const
|
2013-06-22 05:58:52 +08:00
|
|
|
{
|
|
|
|
return "CallFuncO + autoremove";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFuncO::subtitle() const
|
2013-06-22 05:58:52 +08:00
|
|
|
{
|
|
|
|
return "simulates CallFuncO with std::bind()";
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
void ActionCallFuncO::callback(Node* node, bool cleanup)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 05:58:52 +08:00
|
|
|
node->removeFromParentAndCleanup(cleanup);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-04 03:13:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionCallFunction
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionCallFunction::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(3);
|
|
|
|
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action1 = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(2, Vector2(200,0)),
|
2013-06-22 03:25:36 +08:00
|
|
|
CallFunc::create( std::bind(&ActionCallFunction::callback1, this) ),
|
|
|
|
CallFunc::create(
|
|
|
|
// lambda
|
|
|
|
[&](){
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("called:lambda callback", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*1,s.height/2-40));
|
2013-06-22 03:25:36 +08:00
|
|
|
this->addChild(label);
|
|
|
|
} ),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
auto action2 = Sequence::create(
|
|
|
|
ScaleBy::create(2 , 2),
|
|
|
|
FadeOut::create(2),
|
|
|
|
CallFunc::create( std::bind(&ActionCallFunction::callback2, this, _tamara) ),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
auto action3 = Sequence::create(
|
|
|
|
RotateBy::create(3 , 360),
|
|
|
|
FadeOut::create(2),
|
2013-06-22 05:58:52 +08:00
|
|
|
CallFunc::create( std::bind(&ActionCallFunction::callback3, this, _kathia, 42) ),
|
2013-06-22 03:25:36 +08:00
|
|
|
NULL);
|
2013-06-04 03:13:24 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action1);
|
|
|
|
_tamara->runAction(action2);
|
|
|
|
_kathia->runAction(action3);
|
2013-06-04 03:13:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ActionCallFunction::callback1()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 1 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*1,s.height/2));
|
2013-06-04 03:13:24 +08:00
|
|
|
|
|
|
|
addChild(label);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionCallFunction::callback2(Node* sender)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 2 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*2,s.height/2));
|
2013-06-04 03:13:24 +08:00
|
|
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
CCLOG("sender is: %p", sender);
|
|
|
|
}
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
void ActionCallFunction::callback3(Node* sender, long data)
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF("callback 3 called", "fonts/Marker Felt.ttf", 16.0f);
|
2014-04-15 18:23:40 +08:00
|
|
|
label->setPosition(Vector2( s.width/4*3,s.height/2));
|
2013-06-04 03:13:24 +08:00
|
|
|
addChild(label);
|
|
|
|
|
2013-06-22 05:58:52 +08:00
|
|
|
CCLOG("target is: %p, data is: %ld", sender, data);
|
2013-06-04 03:13:24 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCallFunction::subtitle() const
|
2013-06-04 03:13:24 +08:00
|
|
|
{
|
|
|
|
return "Callbacks: CallFunc with std::function()";
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionSpawn
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ActionSpawn::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Spawn::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
JumpBy::create(2, Vector2(300,0), 50, 4),
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy::create( 2, 720),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionSpawn::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Spawn: Jump + Rotate";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRepeatForever
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRepeatForever::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(1);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create(
|
2013-06-20 14:17:10 +08:00
|
|
|
DelayTime::create(1),
|
|
|
|
CallFunc::create( std::bind( &ActionRepeatForever::repeatForever, this, _grossini) ),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void ActionRepeatForever::repeatForever(Node* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-22 03:25:36 +08:00
|
|
|
auto repeat = RepeatForever::create( RotateBy::create(1.0f, 360) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
sender->runAction(repeat);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRepeatForever::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "CallFuncN + RepeatForever";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRotateToRepeat
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRotateToRepeat::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(2);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act1 = RotateTo::create(1, 90);
|
|
|
|
auto act2 = RotateTo::create(1, 0);
|
|
|
|
auto seq = Sequence::create(act1, act2, NULL);
|
|
|
|
auto rep1 = RepeatForever::create(seq);
|
|
|
|
auto rep2 = Repeat::create( seq->clone(), 10);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(rep1);
|
|
|
|
_kathia->runAction(rep2);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRotateToRepeat ::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Repeat/RepeatForever + RotateTo";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRotateJerk
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRotateJerk::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(2);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateTo::create(0.5f, -20),
|
|
|
|
RotateTo::create(0.5f, 20),
|
2012-04-19 14:35:52 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto rep1 = Repeat::create(seq, 10);
|
|
|
|
auto rep2 = RepeatForever::create( seq->clone() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(rep1);
|
|
|
|
_kathia->runAction(rep2);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRotateJerk::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "RepeatForever / Repeat + Rotate";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionReverse
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionReverse::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto jump = JumpBy::create(2, Vector2(300,0), 50, 4);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create( jump, jump->reverse(), NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionReverse::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Reverse an action";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionDelayTime
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionDelayTime::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto move = MoveBy::create(1, Vector2(150,0));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create( move, DelayTime::create(2), move, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionDelayTime::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "DelayTime: m + delay + m";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionReverseSequence
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionReverseSequence::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto move1 = MoveBy::create(1, Vector2(250,0));
|
|
|
|
auto move2 = MoveBy::create(1, Vector2(0,50));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create( move1, move2, move1->reverse(), NULL);
|
|
|
|
auto action = Sequence::create( seq, seq->reverse(), NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionReverseSequence::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Reverse a sequence";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionReverseSequence2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionReverseSequence2::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(2);
|
|
|
|
|
|
|
|
|
|
|
|
// Test:
|
|
|
|
// Sequence should work both with IntervalAction and InstantActions
|
2014-04-15 18:23:40 +08:00
|
|
|
auto move1 = MoveBy::create(1, Vector2(250,0));
|
|
|
|
auto move2 = MoveBy::create(1, Vector2(0,50));
|
2013-06-20 14:17:10 +08:00
|
|
|
auto tog1 = ToggleVisibility::create();
|
|
|
|
auto tog2 = ToggleVisibility::create();
|
|
|
|
auto seq = Sequence::create( move1, tog1, move2, tog2, move1->reverse(), NULL);
|
|
|
|
auto action = Repeat::create(Sequence::create( seq, seq->reverse(), NULL), 3);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Test:
|
|
|
|
// Also test that the reverse of Hide is Show, and vice-versa
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto move_tamara = MoveBy::create(1, Vector2(100,0));
|
|
|
|
auto move_tamara2 = MoveBy::create(1, Vector2(50,0));
|
2013-06-20 14:17:10 +08:00
|
|
|
auto hide = Hide::create();
|
|
|
|
auto seq_tamara = Sequence::create( move_tamara, hide, move_tamara2, NULL);
|
2013-06-19 06:06:53 +08:00
|
|
|
auto seq_back = seq_tamara->reverse();
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( Sequence::create( seq_tamara, seq_back, NULL));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionReverseSequence2::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Reverse sequence 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRepeat
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRepeat::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(2);
|
|
|
|
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto a1 = MoveBy::create(1, Vector2(150,0));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action1 = Repeat::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
Sequence::create( Place::create(Vector2(60,60)), a1, NULL) ,
|
2012-04-19 14:35:52 +08:00
|
|
|
3);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action2 = RepeatForever::create(
|
|
|
|
Sequence::create(a1->clone(), a1->reverse(), NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(action1);
|
|
|
|
_tamara->runAction(action2);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRepeat::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Repeat / RepeatForever actions";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionOrbit
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionOrbit::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
2013-12-21 11:19:24 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2012-04-19 14:35:52 +08:00
|
|
|
centerSprites(3);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto orbit1 = OrbitCamera::create(2,1, 0, 0, 180, 0, 0);
|
2013-12-21 11:19:24 +08:00
|
|
|
auto action1 = Sequence::create(
|
2012-04-19 14:35:52 +08:00
|
|
|
orbit1,
|
|
|
|
orbit1->reverse(),
|
2014-03-25 06:09:24 +08:00
|
|
|
nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto orbit2 = OrbitCamera::create(2,1, 0, 0, 180, -45, 0);
|
2013-12-21 11:19:24 +08:00
|
|
|
auto action2 = Sequence::create(
|
2012-04-19 14:35:52 +08:00
|
|
|
orbit2,
|
|
|
|
orbit2->reverse(),
|
2014-03-25 06:09:24 +08:00
|
|
|
nullptr);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto orbit3 = OrbitCamera::create(2,1, 0, 0, 180, 90, 0);
|
2013-12-21 11:19:24 +08:00
|
|
|
auto action3 = Sequence::create(
|
2012-04-19 14:35:52 +08:00
|
|
|
orbit3,
|
|
|
|
orbit3->reverse(),
|
2014-03-25 06:09:24 +08:00
|
|
|
nullptr);
|
2013-12-21 08:33:31 +08:00
|
|
|
|
2013-12-21 11:19:24 +08:00
|
|
|
_kathia->runAction(RepeatForever::create(action1));
|
|
|
|
_tamara->runAction(RepeatForever::create(action2));
|
|
|
|
_grossini->runAction(RepeatForever::create(action3));
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto move = MoveBy::create(3, Vector2(100,-100));
|
2013-12-21 11:19:24 +08:00
|
|
|
auto move_back = move->reverse();
|
|
|
|
auto seq = Sequence::create(move, move_back, NULL);
|
|
|
|
auto rfe = RepeatForever::create(seq);
|
|
|
|
_kathia->runAction(rfe);
|
|
|
|
_tamara->runAction(rfe->clone() );
|
|
|
|
_grossini->runAction( rfe->clone() );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-02 17:12:09 +08:00
|
|
|
void ActionOrbit::onExit()
|
|
|
|
{
|
|
|
|
ActionsDemo::onExit();
|
|
|
|
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionOrbit::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "OrbitCamera action";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionFollow
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionFollow::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
centerSprites(1);
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_grossini->setPosition(Vector2(-200, s.height / 2));
|
|
|
|
auto move = MoveBy::create(2, Vector2(s.width * 3, 0));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto move_back = move->reverse();
|
2013-07-24 06:20:22 +08:00
|
|
|
auto seq = Sequence::create(move, move_back, NULL);
|
|
|
|
auto rep = RepeatForever::create(seq);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(rep);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
this->runAction(Follow::create(_grossini, Rect(0, 0, s.width * 2 - 100, s.height)));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ActionFollow::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2013-12-25 09:51:55 +08:00
|
|
|
{
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ActionFollow::onDraw, this, transform, transformUpdated);
|
2013-12-25 09:51:55 +08:00
|
|
|
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 09:51:55 +08:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ActionFollow::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-03-01 11:12:23 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);
|
2014-03-06 07:49:08 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2013-03-01 11:12:23 +08:00
|
|
|
|
2013-12-25 09:51:55 +08:00
|
|
|
float x = winSize.width*2 - 100;
|
|
|
|
float y = winSize.height;
|
2013-03-01 11:12:23 +08:00
|
|
|
|
2014-04-15 17:29:23 +08:00
|
|
|
Vector2 vertices[] = { Vector2(5,5), Vector2(x-5,5), Vector2(x-5,y-5), Vector2(5,y-5) };
|
2013-12-25 09:51:55 +08:00
|
|
|
DrawPrimitives::drawPoly(vertices, 4, true);
|
2014-03-06 07:49:08 +08:00
|
|
|
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-03-01 11:12:23 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionFollow::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Follow action";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ActionTargeted::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(2);
|
|
|
|
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto jump1 = JumpBy::create(2,Vector2::ZERO,100,3);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto jump2 = jump1->clone();
|
2013-07-24 06:20:22 +08:00
|
|
|
auto rot1 = RotateBy::create(1, 360);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto rot2 = rot1->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto t1 = TargetedAction::create(_kathia, jump2);
|
|
|
|
auto t2 = TargetedAction::create(_kathia, rot2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(jump1, t1, rot1, t2, NULL);
|
|
|
|
auto always = RepeatForever::create(seq);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(always);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionTargeted::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "ActionTargeted";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionTargeted::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Action that runs on another target. Useful for sequences";
|
|
|
|
}
|
|
|
|
|
2013-08-01 10:28:18 +08:00
|
|
|
|
|
|
|
void ActionTargetedReverse::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(2);
|
|
|
|
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto jump1 = JumpBy::create(2,Vector2::ZERO,100,3);
|
2013-08-01 10:28:18 +08:00
|
|
|
auto jump2 = jump1->clone();
|
|
|
|
auto rot1 = RotateBy::create(1, 360);
|
|
|
|
auto rot2 = rot1->clone();
|
|
|
|
|
|
|
|
auto t1 = TargetedAction::create(_kathia, jump2);
|
|
|
|
auto t2 = TargetedAction::create(_kathia, rot2);
|
|
|
|
|
|
|
|
auto seq = Sequence::create(jump1, t1->reverse(), rot1, t2->reverse(), NULL);
|
|
|
|
auto always = RepeatForever::create(seq);
|
|
|
|
|
|
|
|
_tamara->runAction(always);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionTargetedReverse::title() const
|
2013-08-01 10:28:18 +08:00
|
|
|
{
|
|
|
|
return "ActionTargetedReverse";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionTargetedReverse::subtitle() const
|
2013-08-01 10:28:18 +08:00
|
|
|
{
|
|
|
|
return "Action that runs reversely on another target. Useful for sequences";
|
|
|
|
}
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionStacked
|
2013-02-28 14:42:45 +08:00
|
|
|
|
|
|
|
void ActionStacked::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-02-28 14:42:45 +08:00
|
|
|
this->centerSprites(0);
|
|
|
|
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesEnded = CC_CALLBACK_2(ActionStacked::onTouchesEnded, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-04-15 18:23:40 +08:00
|
|
|
this->addNewSpriteWithCoords(Vector2(s.width/2, s.height/2));
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
void ActionStacked::addNewSpriteWithCoords(Vector2 p)
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
2013-02-28 15:32:27 +08:00
|
|
|
int idx = CCRANDOM_0_1() * 1400 / 100;
|
|
|
|
int x = (idx%5) * 85;
|
|
|
|
int y = (idx/5) * 121;
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = Sprite::create("Images/grossini_dance_atlas.png", Rect(x,y,85,121));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
sprite->setPosition(p);
|
|
|
|
this->addChild(sprite);
|
|
|
|
|
|
|
|
this->runActionsInSprite(sprite);
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionStacked::runActionsInSprite(Sprite *sprite)
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
2013-02-28 15:32:27 +08:00
|
|
|
// override me
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void ActionStacked::onTouchesEnded(const std::vector<Touch*>& touches, Event* event)
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
for ( auto &touch: touches ) {
|
2013-08-16 16:05:27 +08:00
|
|
|
auto location = touch->getLocation();
|
2013-02-28 14:42:45 +08:00
|
|
|
addNewSpriteWithCoords( location );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionStacked::title() const
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
|
|
|
return "Override me";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionStacked::subtitle() const
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
|
|
|
return "Tap screen";
|
|
|
|
}
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionMoveStacked
|
|
|
|
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionMoveStacked::runActionsInSprite(Sprite *sprite)
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
2013-02-28 15:32:27 +08:00
|
|
|
sprite->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,10)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,-10)),
|
2013-02-28 15:32:27 +08:00
|
|
|
NULL)));
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto action = MoveBy::create(2.0f, Vector2(400,0));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action_back = action->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
sprite->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(action, action_back, NULL)
|
2013-02-28 15:32:27 +08:00
|
|
|
));
|
2013-02-28 14:42:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionMoveStacked::title() const
|
2013-02-28 14:42:45 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "Stacked MoveBy/To actions";
|
2013-02-28 15:32:27 +08:00
|
|
|
}
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionMoveJumpStacked
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionMoveJumpStacked::runActionsInSprite(Sprite *sprite)
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
sprite->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,2)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,-2)),
|
2013-02-28 15:32:27 +08:00
|
|
|
NULL)));
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto jump = JumpBy::create(2.0f, Vector2(400,0), 100, 5);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto jump_back = jump->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
sprite->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(jump, jump_back, NULL)
|
2013-02-28 15:32:27 +08:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionMoveJumpStacked::title() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
return "tacked Move + Jump actions";
|
|
|
|
}
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionMoveBezierStacked
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void ActionMoveBezierStacked::runActionsInSprite(Sprite *sprite)
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
// sprite 1
|
|
|
|
ccBezierConfig bezier;
|
2014-04-15 18:23:40 +08:00
|
|
|
bezier.controlPoint_1 = Vector2(0, s.height/2);
|
|
|
|
bezier.controlPoint_2 = Vector2(300, -s.height/2);
|
|
|
|
bezier.endPosition = Vector2(300,100);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto bezierForward = BezierBy::create(3, bezier);
|
|
|
|
auto bezierBack = bezierForward->reverse();
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(bezierForward, bezierBack, NULL);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto rep = RepeatForever::create(seq);
|
2013-02-28 15:32:27 +08:00
|
|
|
sprite->runAction(rep);
|
|
|
|
|
|
|
|
sprite->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,0)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,0)),
|
2013-02-28 15:32:27 +08:00
|
|
|
NULL)));
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionMoveBezierStacked::title() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
return "Stacked Move + Bezier actions";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionCatmullRomStacked
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
void ActionCatmullRomStacked::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
this->centerSprites(2);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 1 (By)
|
|
|
|
//
|
|
|
|
// startPosition can be any coordinate, but since the movement
|
|
|
|
// is relative to the Catmull Rom curve, it is better to start with (0,0).
|
|
|
|
//
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition(Vector2(50,50));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array = PointArray::create(20);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array->addControlPoint(Vector2(0,0));
|
|
|
|
array->addControlPoint(Vector2(80,80));
|
|
|
|
array->addControlPoint(Vector2(s.width-80,80));
|
|
|
|
array->addControlPoint(Vector2(s.width-80,s.height-80));
|
|
|
|
array->addControlPoint(Vector2(80,s.height-80));
|
|
|
|
array->addControlPoint(Vector2(80,80));
|
|
|
|
array->addControlPoint(Vector2(s.width/2, s.height/2));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = CatmullRomBy::create(3, array);
|
|
|
|
auto reverse = action->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(action, reverse, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(seq);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(
|
2013-06-22 03:25:36 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,0)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,0)),
|
2013-06-22 03:25:36 +08:00
|
|
|
NULL)));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 2 (To)
|
|
|
|
//
|
|
|
|
// The startPosition is not important here, because it uses a "To" action.
|
|
|
|
// The initial position will be the 1st point of the Catmull Rom path
|
|
|
|
//
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array2 = PointArray::create(20);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array2->addControlPoint(Vector2(s.width/2, 30));
|
|
|
|
array2->addControlPoint(Vector2(s.width-80,30));
|
|
|
|
array2->addControlPoint(Vector2(s.width-80,s.height-80));
|
|
|
|
array2->addControlPoint(Vector2(s.width/2,s.height-80));
|
|
|
|
array2->addControlPoint(Vector2(s.width/2, 30));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action2 = CatmullRomTo::create(3, array2);
|
|
|
|
auto reverse2 = action2->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq2 = Sequence::create(action2, reverse2, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(seq2);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(
|
2013-06-22 03:25:36 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,0)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,0)),
|
2013-06-22 03:25:36 +08:00
|
|
|
NULL)));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
array->retain();
|
|
|
|
_array1 = array;
|
|
|
|
array2->retain();
|
|
|
|
_array2 = array2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionCatmullRomStacked::~ActionCatmullRomStacked()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_array1);
|
|
|
|
CC_SAFE_RELEASE(_array2);
|
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ActionCatmullRomStacked::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
2014-03-01 08:10:48 +08:00
|
|
|
ActionsDemo::draw(renderer, transform, transformUpdated);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
// move to 50,50 since the "by" path will start at 50,50
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix translation;
|
2014-04-03 15:59:55 +08:00
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(50, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
|
|
|
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ActionCatmullRomStacked::onDraw, this, transform, transformUpdated);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 09:51:55 +08:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ActionCatmullRomStacked::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-12-25 09:51:55 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix oldMat;
|
2014-04-04 18:13:10 +08:00
|
|
|
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
|
2013-12-25 09:51:55 +08:00
|
|
|
DrawPrimitives::drawCatmullRom(_array1,50);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawCatmullRom(_array2,50);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
|
2013-02-28 15:32:27 +08:00
|
|
|
}
|
2013-02-28 14:42:45 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCatmullRomStacked::title() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
return "Stacked MoveBy + CatmullRom actions";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCatmullRomStacked::subtitle() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
return "MoveBy + CatmullRom at the same time in the same sprite";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-26 14:54:50 +08:00
|
|
|
// ActionCardinalSplineStacked
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
void ActionCardinalSplineStacked::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
this->centerSprites(2);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array = PointArray::create(20);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array->addControlPoint(Vector2(0, 0));
|
|
|
|
array->addControlPoint(Vector2(s.width/2-30,0));
|
|
|
|
array->addControlPoint(Vector2(s.width/2-30,s.height-80));
|
|
|
|
array->addControlPoint(Vector2(0, s.height-80));
|
|
|
|
array->addControlPoint(Vector2(0, 0));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 1 (By)
|
|
|
|
//
|
|
|
|
// Spline with no tension (tension==0)
|
|
|
|
//
|
2013-06-22 03:25:36 +08:00
|
|
|
|
|
|
|
auto action = CardinalSplineBy::create(3, array, 0);
|
|
|
|
auto reverse = action->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(action, reverse, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition(Vector2(50,50));
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(seq);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(
|
2013-06-22 03:25:36 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,0)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,0)),
|
2013-06-22 03:25:36 +08:00
|
|
|
NULL)));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 2 (By)
|
|
|
|
//
|
|
|
|
// Spline with high tension (tension==1)
|
|
|
|
//
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto *action2 = CardinalSplineBy::create(3, array, 1);
|
|
|
|
auto reverse2 = action2->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq2 = Sequence::create(action2, reverse2, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition(Vector2(s.width/2,50));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(seq2);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(
|
2013-06-22 03:25:36 +08:00
|
|
|
RepeatForever::create(
|
|
|
|
Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create(0.05f, Vector2(10,0)),
|
|
|
|
MoveBy::create(0.05f, Vector2(-10,0)),
|
2013-06-22 03:25:36 +08:00
|
|
|
NULL)));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
array->retain();
|
|
|
|
_array = array;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionCardinalSplineStacked::~ActionCardinalSplineStacked()
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(_array);
|
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ActionCardinalSplineStacked::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
2014-03-01 08:10:48 +08:00
|
|
|
ActionsDemo::draw(renderer, transform, transformUpdated);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
// move to 50,50 since the "by" path will start at 50,50
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix translation;
|
2014-04-03 15:59:55 +08:00
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(50, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
|
|
|
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-03 15:59:55 +08:00
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(s.width/2, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
|
|
|
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-12-25 09:58:35 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ActionCardinalSplineStacked::onDraw, this, transform, transformUpdated);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 09:58:35 +08:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ActionCardinalSplineStacked::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-12-25 09:58:35 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix oldMat;
|
2014-04-04 18:13:10 +08:00
|
|
|
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
|
2013-12-25 09:58:35 +08:00
|
|
|
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
|
2013-12-25 09:58:35 +08:00
|
|
|
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
|
2013-02-28 15:32:27 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCardinalSplineStacked::title() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
|
|
|
return "Stacked MoveBy + CardinalSpline actions";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCardinalSplineStacked::subtitle() const
|
2013-02-28 15:32:27 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
return "CCMoveBy + CardinalSplineBy/To at the same time";
|
2013-02-28 15:32:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Issue1305
|
2012-04-19 14:35:52 +08:00
|
|
|
void Issue1305::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(0);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_spriteTmp = Sprite::create("Images/grossini.png");
|
|
|
|
/* c++ can't support block, so we use CallFuncN instead.
|
|
|
|
[spriteTmp_ runAction:[CallBlockN actionWithBlock:^(Node* node) {
|
2012-04-19 14:35:52 +08:00
|
|
|
NSLog(@"This message SHALL ONLY appear when the sprite is added to the scene, NOT BEFORE");
|
2013-02-28 14:42:45 +08:00
|
|
|
}] );
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_spriteTmp->runAction(CallFunc::create(std::bind(&Issue1305::log, this, _spriteTmp)));
|
2013-06-15 14:03:30 +08:00
|
|
|
_spriteTmp->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
scheduleOnce(schedule_selector(Issue1305::addSprite), 2);
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void Issue1305::log(Node* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
cocos2d::log("This message SHALL ONLY appear when the sprite is added to the scene, NOT BEFORE");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1305::onExit()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_spriteTmp->stopAllActions();
|
|
|
|
_spriteTmp->release();
|
2012-05-30 16:09:19 +08:00
|
|
|
ActionsDemo::onExit();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void Issue1305::addSprite(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-04-15 18:23:40 +08:00
|
|
|
_spriteTmp->setPosition(Vector2(250,250));
|
2013-06-15 14:03:30 +08:00
|
|
|
addChild(_spriteTmp);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1305::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Issue 1305";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1305::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "In two seconds you should see a message on the console. NOT BEFORE.";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1305_2::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(0);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto spr = Sprite::create("Images/grossini.png");
|
2014-04-15 18:23:40 +08:00
|
|
|
spr->setPosition(Vector2(200,200));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(spr);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act1 = MoveBy::create(2 ,Vector2(0, 100));
|
2013-06-20 14:17:10 +08:00
|
|
|
/* c++ can't support block, so we use CallFuncN instead.
|
|
|
|
id act2 = [CallBlock actionWithBlock:^{
|
2012-04-19 14:35:52 +08:00
|
|
|
NSLog(@"1st block");
|
2013-02-28 14:42:45 +08:00
|
|
|
});
|
2014-04-15 18:23:40 +08:00
|
|
|
id act3 = [MoveBy create:2, Vector2(0, -100));
|
2013-06-20 14:17:10 +08:00
|
|
|
id act4 = [CallBlock actionWithBlock:^{
|
2012-04-19 14:35:52 +08:00
|
|
|
NSLog(@"2nd block");
|
2013-02-28 14:42:45 +08:00
|
|
|
});
|
2014-04-15 18:23:40 +08:00
|
|
|
id act5 = [MoveBy create:2, Vector2(100, -100));
|
2013-06-20 14:17:10 +08:00
|
|
|
id act6 = [CallBlock actionWithBlock:^{
|
2012-04-19 14:35:52 +08:00
|
|
|
NSLog(@"3rd block");
|
2013-02-28 14:42:45 +08:00
|
|
|
});
|
2014-04-15 18:23:40 +08:00
|
|
|
id act7 = [MoveBy create:2, Vector2(-100, 0));
|
2013-06-20 14:17:10 +08:00
|
|
|
id act8 = [CallBlock actionWithBlock:^{
|
2012-04-19 14:35:52 +08:00
|
|
|
NSLog(@"4th block");
|
2013-02-28 14:42:45 +08:00
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
*/
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act2 = CallFunc::create( std::bind( &Issue1305_2::printLog1, this));
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act3 = MoveBy::create(2, Vector2(0, -100));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act4 = CallFunc::create( std::bind( &Issue1305_2::printLog2, this));
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act5 = MoveBy::create(2, Vector2(100, -100));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act6 = CallFunc::create( std::bind( &Issue1305_2::printLog3, this));
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act7 = MoveBy::create(2, Vector2(-100, 0));
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act8 = CallFunc::create( std::bind( &Issue1305_2::printLog4, this));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto actF = Sequence::create(act1, act2, act3, act4, act5, act6, act7, act8, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-02-28 14:42:45 +08:00
|
|
|
// [spr runAction:actF);
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->getActionManager()->addAction(actF ,spr, false);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-26 04:40:37 +08:00
|
|
|
void Issue1305_2::printLog1()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("1st block");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-10-26 04:40:37 +08:00
|
|
|
void Issue1305_2::printLog2()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("2nd block");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-10-26 04:40:37 +08:00
|
|
|
void Issue1305_2::printLog3()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("3rd block");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-10-26 04:40:37 +08:00
|
|
|
void Issue1305_2::printLog4()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("4th block");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1305_2::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Issue 1305 #2";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1305_2::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "See console. You should only see one message for each block";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1288::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(0);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto spr = Sprite::create("Images/grossini.png");
|
2014-04-15 18:23:40 +08:00
|
|
|
spr->setPosition(Vector2(100, 100));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(spr);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act1 = MoveBy::create(0.5, Vector2(100, 0));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto act2 = act1->reverse();
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act3 = Sequence::create(act1, act2, NULL);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto act4 = Repeat::create(act3, 2);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
spr->runAction(act4);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1288::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Issue 1288";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1288::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Sprite should end at the position where it started.";
|
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1288_2::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(0);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto spr = Sprite::create("Images/grossini.png");
|
2014-04-15 18:23:40 +08:00
|
|
|
spr->setPosition(Vector2(100, 100));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(spr);
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
auto act1 = MoveBy::create(0.5, Vector2(100, 0));
|
2013-06-20 14:17:10 +08:00
|
|
|
spr->runAction(Repeat::create(act1, 1));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1288_2::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Issue 1288 #2";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1288_2::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Sprite should move 100 pixels, and stay there";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Issue1327::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
centerSprites(0);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto spr = Sprite::create("Images/grossini.png");
|
2014-04-15 18:23:40 +08:00
|
|
|
spr->setPosition(Vector2(100, 100));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(spr);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto act1 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
|
|
|
|
auto act2 = RotateBy::create(0.25, 45);
|
|
|
|
auto act3 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
|
|
|
|
auto act4 = RotateBy::create(0.25, 45);
|
|
|
|
auto act5 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
|
|
|
|
auto act6 = RotateBy::create(0.25, 45);
|
|
|
|
auto act7 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
|
|
|
|
auto act8 = RotateBy::create(0.25, 45);
|
|
|
|
auto act9 = CallFunc::create( std::bind(&Issue1327::logSprRotation, this, spr));
|
|
|
|
|
|
|
|
auto actF = Sequence::create(act1, act2, act3, act4, act5, act6, act7, act8, act9, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
spr->runAction(actF);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1327::title() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "Issue 1327";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1327::subtitle() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
return "See console: You should see: 0, 45, 90, 135, 180";
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void Issue1327::logSprRotation(Sprite* sender)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-26 06:53:24 +08:00
|
|
|
log("%f", sender->getRotation());
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-11-19 17:15:16 +08:00
|
|
|
//Issue1398
|
2013-02-28 14:42:45 +08:00
|
|
|
void Issue1398::incrementInteger()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_testInteger++;
|
2013-07-24 06:20:22 +08:00
|
|
|
log("incremented to %d", _testInteger);
|
2012-11-19 17:15:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Issue1398::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
this->centerSprites(0);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_testInteger = 0;
|
2013-07-24 06:20:22 +08:00
|
|
|
log("testInt = %d", _testInteger);
|
2012-11-19 17:15:16 +08:00
|
|
|
|
|
|
|
this->runAction(
|
2013-06-20 14:17:10 +08:00
|
|
|
Sequence::create(
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"1")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"2")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"3")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"4")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"5")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"6")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"7")),
|
|
|
|
CallFunc::create( std::bind(&Issue1398::incrementIntegerCallback, this, (void*)"8")),
|
2012-11-19 17:15:16 +08:00
|
|
|
NULL));
|
|
|
|
}
|
|
|
|
|
2013-06-04 03:13:24 +08:00
|
|
|
void Issue1398::incrementIntegerCallback(void* data)
|
2012-11-19 17:15:16 +08:00
|
|
|
{
|
|
|
|
this->incrementInteger();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("%s", (char*)data);
|
2012-11-19 17:15:16 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1398::subtitle() const
|
2012-11-19 17:15:16 +08:00
|
|
|
{
|
|
|
|
return "See console: You should see an 8";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string Issue1398::title() const
|
2012-11-19 17:15:16 +08:00
|
|
|
{
|
|
|
|
return "Issue 1398";
|
|
|
|
}
|
|
|
|
|
2012-06-11 18:25:57 +08:00
|
|
|
/** ActionCatmullRom
|
|
|
|
*/
|
|
|
|
void ActionCatmullRom::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
this->centerSprites(2);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-02-28 15:32:27 +08:00
|
|
|
//
|
|
|
|
// sprite 1 (By)
|
|
|
|
//
|
|
|
|
// startPosition can be any coordinate, but since the movement
|
|
|
|
// is relative to the Catmull Rom curve, it is better to start with (0,0).
|
|
|
|
//
|
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition(Vector2(50, 50));
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array = PointArray::create(20);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array->addControlPoint(Vector2(0, 0));
|
|
|
|
array->addControlPoint(Vector2(80, 80));
|
|
|
|
array->addControlPoint(Vector2(s.width - 80, 80));
|
|
|
|
array->addControlPoint(Vector2(s.width - 80, s.height - 80));
|
|
|
|
array->addControlPoint(Vector2(80, s.height - 80));
|
|
|
|
array->addControlPoint(Vector2(80, 80));
|
|
|
|
array->addControlPoint(Vector2(s.width / 2, s.height / 2));
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = CatmullRomBy::create(3, array);
|
|
|
|
auto reverse = action->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(action, reverse, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(seq);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 2 (To)
|
|
|
|
//
|
|
|
|
// The startPosition is not important here, because it uses a "To" action.
|
|
|
|
// The initial position will be the 1st point of the Catmull Rom path
|
|
|
|
//
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array2 = PointArray::create(20);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array2->addControlPoint(Vector2(s.width / 2, 30));
|
|
|
|
array2->addControlPoint(Vector2(s.width -80, 30));
|
|
|
|
array2->addControlPoint(Vector2(s.width - 80, s.height - 80));
|
|
|
|
array2->addControlPoint(Vector2(s.width / 2, s.height - 80));
|
|
|
|
array2->addControlPoint(Vector2(s.width / 2, 30));
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action2 = CatmullRomTo::create(3, array2);
|
|
|
|
auto reverse2 = action2->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq2 = Sequence::create(action2, reverse2, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(seq2);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_array1 = array;
|
|
|
|
_array1->retain();
|
|
|
|
_array2 = array2;
|
|
|
|
_array2->retain();
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionCatmullRom::~ActionCatmullRom()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_array1->release();
|
|
|
|
_array2->release();
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ActionCatmullRom::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
2014-03-01 08:10:48 +08:00
|
|
|
ActionsDemo::draw(renderer, transform, transformUpdated);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-02-28 15:32:27 +08:00
|
|
|
// move to 50,50 since the "by" path will start at 50,50
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix translation;
|
2014-04-03 15:59:55 +08:00
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(50, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-12-25 10:20:29 +08:00
|
|
|
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-12-25 10:20:29 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ActionCatmullRom::onDraw, this, transform, transformUpdated);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 10:20:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ActionCatmullRom::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-12-25 10:20:29 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix oldMat;
|
2014-04-04 18:13:10 +08:00
|
|
|
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
|
2013-12-25 10:20:29 +08:00
|
|
|
DrawPrimitives::drawCatmullRom(_array1, 50);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
|
2013-07-26 05:49:43 +08:00
|
|
|
DrawPrimitives::drawCatmullRom(_array2,50);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-25 10:20:29 +08:00
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCatmullRom::title() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
|
|
|
return "CatmullRomBy / CatmullRomTo";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCatmullRom::subtitle() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
|
|
|
return "Catmull Rom spline paths. Testing reverse too";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ActionCardinalSpline
|
|
|
|
*/
|
|
|
|
void ActionCardinalSpline::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2012-06-11 18:25:57 +08:00
|
|
|
this->centerSprites(2);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto array = PointArray::create(20);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
array->addControlPoint(Vector2(0, 0));
|
|
|
|
array->addControlPoint(Vector2(s.width/2-30, 0));
|
|
|
|
array->addControlPoint(Vector2(s.width/2-30, s.height-80));
|
|
|
|
array->addControlPoint(Vector2(0, s.height-80));
|
|
|
|
array->addControlPoint(Vector2(0, 0));
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-02-28 15:32:27 +08:00
|
|
|
//
|
|
|
|
// sprite 1 (By)
|
|
|
|
//
|
|
|
|
// Spline with no tension (tension==0)
|
|
|
|
//
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = CardinalSplineBy::create(3, array, 0);
|
|
|
|
auto reverse = action->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq = Sequence::create(action, reverse, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_tamara->setPosition(Vector2(50, 50));
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->runAction(seq);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// sprite 2 (By)
|
|
|
|
//
|
|
|
|
// Spline with high tension (tension==1)
|
|
|
|
//
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action2 = CardinalSplineBy::create(3, array, 1);
|
2013-06-22 03:25:36 +08:00
|
|
|
auto reverse2 = action2->reverse();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto seq2 = Sequence::create(action2, reverse2, NULL);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
_kathia->setPosition(Vector2(s.width/2, 50));
|
2013-06-15 14:03:30 +08:00
|
|
|
_kathia->runAction(seq2);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_array = array;
|
2012-06-11 18:25:57 +08:00
|
|
|
array->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionCardinalSpline::~ActionCardinalSpline()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_array->release();
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
2014-04-08 22:07:35 +08:00
|
|
|
void ActionCardinalSpline::draw(Renderer *renderer, const Matrix &transform, bool transformUpdated)
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
2014-03-01 08:10:48 +08:00
|
|
|
ActionsDemo::draw(renderer, transform, transformUpdated);
|
2013-02-28 15:32:27 +08:00
|
|
|
|
|
|
|
// move to 50,50 since the "by" path will start at 50,50
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix translation;
|
2014-04-03 15:59:55 +08:00
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(50, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV1 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2014-04-03 15:59:55 +08:00
|
|
|
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
|
|
|
|
|
|
|
//Create a rotation matrix using the axis and the angle
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix::createTranslation(s.width/2, 50, 0, &translation);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, translation);
|
2014-04-04 18:13:10 +08:00
|
|
|
_modelViewMV2 = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2013-12-25 10:20:29 +08:00
|
|
|
|
2014-01-19 03:35:27 +08:00
|
|
|
_customCommand.init(_globalZOrder);
|
2014-03-06 07:49:08 +08:00
|
|
|
_customCommand.func = CC_CALLBACK_0(ActionCardinalSpline::onDraw, this, transform, transformUpdated);
|
2014-03-01 08:10:48 +08:00
|
|
|
renderer->addCommand(&_customCommand);
|
2013-12-25 10:20:29 +08:00
|
|
|
}
|
|
|
|
|
2014-04-10 10:16:16 +08:00
|
|
|
void ActionCardinalSpline::onDraw(const Matrix &transform, bool transformUpdated)
|
2013-12-25 10:20:29 +08:00
|
|
|
{
|
2014-04-03 15:59:55 +08:00
|
|
|
Director* director = Director::getInstance();
|
|
|
|
CCASSERT(nullptr != director, "Director is null when seting matrix stack");
|
|
|
|
|
2014-04-11 18:03:07 +08:00
|
|
|
Matrix oldMat;
|
2014-04-04 18:13:10 +08:00
|
|
|
oldMat = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV1);
|
2013-12-25 10:20:29 +08:00
|
|
|
DrawPrimitives::drawCardinalSpline(_array, 0, 100);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV2);
|
2013-12-25 10:20:29 +08:00
|
|
|
DrawPrimitives::drawCardinalSpline(_array, 1, 100);
|
2014-04-03 15:59:55 +08:00
|
|
|
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMat);
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCardinalSpline::title() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
2013-02-28 14:42:45 +08:00
|
|
|
return "CardinalSplineBy / CardinalSplineTo";
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionCardinalSpline::subtitle() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
|
|
|
return "Cardinal Spline paths. Testing different tensions for one array";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** PauseResumeActions
|
|
|
|
*/
|
2012-07-24 11:21:08 +08:00
|
|
|
|
|
|
|
PauseResumeActions::PauseResumeActions()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PauseResumeActions::~PauseResumeActions()
|
|
|
|
{
|
2013-12-07 14:28:37 +08:00
|
|
|
|
2012-07-24 11:21:08 +08:00
|
|
|
}
|
|
|
|
|
2012-06-11 18:25:57 +08:00
|
|
|
void PauseResumeActions::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
2013-02-28 15:32:27 +08:00
|
|
|
|
2013-03-01 11:25:40 +08:00
|
|
|
this->centerSprites(3);
|
2012-06-11 18:25:57 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction(RepeatForever::create(RotateBy::create(3, 360)));
|
|
|
|
_grossini->runAction(RepeatForever::create(RotateBy::create(3, -360)));
|
|
|
|
_kathia->runAction(RepeatForever::create(RotateBy::create(3, 360)));
|
2012-06-11 18:25:57 +08:00
|
|
|
|
|
|
|
this->schedule(schedule_selector(PauseResumeActions::pause), 3, false, 0);
|
|
|
|
this->schedule(schedule_selector(PauseResumeActions::resume), 5, false, 0);
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PauseResumeActions::title() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
|
|
|
return "PauseResumeActions";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PauseResumeActions::subtitle() const
|
2012-06-11 18:25:57 +08:00
|
|
|
{
|
|
|
|
return "All actions pause at 3s and resume at 5s";
|
|
|
|
}
|
|
|
|
|
|
|
|
void PauseResumeActions::pause(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Pausing");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2012-07-24 11:21:08 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_pausedTargets = director->getActionManager()->pauseAllRunningActions();
|
2012-06-11 18:25:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void PauseResumeActions::resume(float dt)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Resuming");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-06-15 14:03:30 +08:00
|
|
|
director->getActionManager()->resumeTargets(_pausedTargets);
|
2013-12-07 14:28:37 +08:00
|
|
|
_pausedTargets.clear();
|
2012-06-12 02:50:32 +08:00
|
|
|
}
|
2013-04-01 10:18:26 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// ActionRemoveSelf
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void ActionRemoveSelf::onEnter()
|
|
|
|
{
|
|
|
|
ActionsDemo::onEnter();
|
|
|
|
|
|
|
|
alignSpritesLeft(1);
|
|
|
|
|
2013-06-22 03:25:36 +08:00
|
|
|
auto action = Sequence::create(
|
2014-04-15 18:23:40 +08:00
|
|
|
MoveBy::create( 2, Vector2(240,0)),
|
2013-06-20 14:17:10 +08:00
|
|
|
RotateBy::create( 2, 540),
|
|
|
|
ScaleTo::create(1,0.1f),
|
|
|
|
RemoveSelf::create(),
|
2013-04-01 10:18:26 +08:00
|
|
|
NULL);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_grossini->runAction(action);
|
2013-04-01 10:18:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string ActionRemoveSelf::subtitle() const
|
2013-04-01 10:18:26 +08:00
|
|
|
{
|
|
|
|
return "Sequence: Move + Rotate + Scale + RemoveSelf";
|
2014-03-26 16:00:55 +08:00
|
|
|
}
|