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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-05-12 10:52:10 +08:00
|
|
|
#include "TransitionsTest.h"
|
|
|
|
#include "../testResource.h"
|
2011-06-08 10:02:07 +08:00
|
|
|
#include "CCConfiguration.h"
|
2011-05-12 10:52:10 +08:00
|
|
|
|
|
|
|
#define TRANSITION_DURATION (1.2f)
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FadeWhiteTransition : public TransitionFade
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-08 18:11:32 +08:00
|
|
|
return TransitionFade::create(t, s, Color3B::WHITE);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipXLeftOver : public TransitionFlipX
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipX::create(t, s, TransitionScene::Orientation::LEFT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipXRightOver : public TransitionFlipX
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipX::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipYUpOver : public TransitionFlipY
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipY::create(t, s, TransitionScene::Orientation::UP_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipYDownOver : public TransitionFlipY
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipY::create(t, s, TransitionScene::Orientation::DOWN_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipAngularLeftOver : public TransitionFlipAngular
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipAngular::create(t, s, TransitionScene::Orientation::LEFT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class FlipAngularRightOver : public TransitionFlipAngular
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionFlipAngular::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipXLeftOver : public TransitionZoomFlipX
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipX::create(t, s, TransitionScene::Orientation::LEFT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipXRightOver : public TransitionZoomFlipX
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipX::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipYUpOver : public TransitionZoomFlipY
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipY::create(t, s, TransitionScene::Orientation::UP_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipYDownOver : public TransitionZoomFlipY
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipY::create(t, s, TransitionScene::Orientation::DOWN_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipAngularLeftOver : public TransitionZoomFlipAngular
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipAngular::create(t, s, TransitionScene::Orientation::LEFT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class ZoomFlipAngularRightOver : public TransitionZoomFlipAngular
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-26 05:49:43 +08:00
|
|
|
return TransitionZoomFlipAngular::create(t, s, TransitionScene::Orientation::RIGHT_OVER);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class PageTransitionForward : public TransitionPageTurn
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->setDepthTest(true);
|
2013-06-20 14:17:10 +08:00
|
|
|
return TransitionPageTurn::create(t, s, false);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
class PageTransitionBackward : public TransitionPageTurn
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-06-20 14:17:10 +08:00
|
|
|
static TransitionScene* create(float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->setDepthTest(true);
|
2013-06-20 14:17:10 +08:00
|
|
|
return TransitionPageTurn::create(t, s, true);
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
2011-05-12 10:52:10 +08:00
|
|
|
};
|
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
#define STRINGIFY(x) #x
|
2012-03-26 16:46:23 +08:00
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
#define TRANS(__className__) { \
|
2014-01-03 16:13:13 +08:00
|
|
|
[](float t, Scene* s){ return __className__::create(t,s);}, \
|
2014-01-03 06:25:28 +08:00
|
|
|
STRINGIFY(__className__), \
|
|
|
|
}
|
|
|
|
struct _transitions {
|
|
|
|
std::function<TransitionScene*(float t, Scene* s)> function;
|
|
|
|
const char * name;
|
2014-01-03 16:13:13 +08:00
|
|
|
} transitions[] = {
|
2014-01-03 06:25:28 +08:00
|
|
|
TRANS(TransitionJumpZoom),
|
|
|
|
TRANS(TransitionProgressRadialCCW),
|
|
|
|
TRANS(TransitionProgressRadialCW),
|
|
|
|
TRANS(TransitionProgressHorizontal),
|
|
|
|
TRANS(TransitionProgressVertical),
|
|
|
|
TRANS(TransitionProgressInOut),
|
|
|
|
TRANS(TransitionProgressOutIn),
|
|
|
|
|
|
|
|
TRANS(TransitionCrossFade),
|
|
|
|
|
|
|
|
TRANS(PageTransitionForward),
|
|
|
|
TRANS(PageTransitionBackward),
|
|
|
|
TRANS(TransitionFadeTR),
|
|
|
|
TRANS(TransitionFadeBL),
|
|
|
|
TRANS(TransitionFadeUp),
|
|
|
|
TRANS(TransitionFadeDown),
|
|
|
|
|
|
|
|
TRANS(TransitionTurnOffTiles),
|
|
|
|
|
|
|
|
TRANS(TransitionSplitRows),
|
|
|
|
TRANS(TransitionSplitCols),
|
|
|
|
|
|
|
|
TRANS(TransitionFade),
|
|
|
|
TRANS(FadeWhiteTransition),
|
|
|
|
|
|
|
|
TRANS(FlipXLeftOver),
|
|
|
|
TRANS(FlipXRightOver),
|
|
|
|
TRANS(FlipYUpOver),
|
|
|
|
TRANS(FlipYDownOver),
|
|
|
|
TRANS(FlipAngularLeftOver),
|
|
|
|
TRANS(FlipAngularRightOver),
|
|
|
|
|
|
|
|
TRANS(ZoomFlipXLeftOver),
|
|
|
|
TRANS(ZoomFlipXRightOver),
|
|
|
|
TRANS(ZoomFlipYUpOver),
|
|
|
|
TRANS(ZoomFlipYDownOver),
|
|
|
|
TRANS(ZoomFlipAngularLeftOver),
|
|
|
|
TRANS(ZoomFlipAngularRightOver),
|
|
|
|
|
|
|
|
TRANS(TransitionShrinkGrow),
|
|
|
|
TRANS(TransitionRotoZoom),
|
|
|
|
|
|
|
|
TRANS(TransitionMoveInL),
|
|
|
|
TRANS(TransitionMoveInR),
|
|
|
|
TRANS(TransitionMoveInT),
|
|
|
|
TRANS(TransitionMoveInB),
|
|
|
|
|
|
|
|
TRANS(TransitionSlideInL),
|
|
|
|
TRANS(TransitionSlideInR),
|
|
|
|
TRANS(TransitionSlideInT),
|
|
|
|
TRANS(TransitionSlideInB),
|
2011-05-12 10:52:10 +08:00
|
|
|
};
|
2014-01-03 06:25:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define MAX_LAYER (sizeof(transitions) / sizeof(transitions[0]))
|
|
|
|
|
|
|
|
|
2011-05-12 10:52:10 +08:00
|
|
|
static int s_nSceneIdx = 0;
|
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
TransitionScene* createTransition(int index, float t, Scene* s)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2011-07-12 17:35:15 +08:00
|
|
|
// fix bug #486, without setDepthTest(false), FlipX,Y will flickers
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->setDepthTest(false);
|
2011-07-12 17:35:15 +08:00
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
return transitions[index].function(t,s);
|
|
|
|
}
|
2011-05-12 10:52:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
void TransitionsTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer1();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
|
|
|
layer->release();
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2011-05-12 10:52:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestLayer1::TestLayer1(void)
|
|
|
|
{
|
2010-08-20 14:35:37 +08:00
|
|
|
float x,y;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2010-08-20 14:35:37 +08:00
|
|
|
x = size.width;
|
|
|
|
y = size.height;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto bg1 = Sprite::create(s_back1);
|
2013-07-12 14:11:55 +08:00
|
|
|
bg1->setPosition( Point(size.width/2, size.height/2) );
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild(bg1, -1);
|
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
auto title = LabelTTF::create( (transitions[s_nSceneIdx]).name, "Thonburi", 32 );
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild(title);
|
2013-07-05 16:49:22 +08:00
|
|
|
title->setColor( Color3B(255,32,32) );
|
2013-07-12 14:11:55 +08:00
|
|
|
title->setPosition( Point(x/2, y-100) );
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create("SCENE 1", "Marker Felt", 38);
|
2013-07-05 16:49:22 +08:00
|
|
|
label->setColor( Color3B(16,16,255));
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition( Point(x/2,y/2));
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild( label);
|
|
|
|
|
|
|
|
// menu
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(TestLayer1::backCallback, this) );
|
|
|
|
auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(TestLayer1::restartCallback, this) );
|
|
|
|
auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(TestLayer1::nextCallback, this) );
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(item1, item2, item3, NULL);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
menu->setPosition( Point::ZERO );
|
2013-07-12 14:11:55 +08:00
|
|
|
item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu, 1);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TestLayer1::step), 1.0f);
|
2011-05-12 10:52:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TestLayer1::~TestLayer1(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer1::restartCallback(Object* sender)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer2();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2010-08-20 17:08:30 +08:00
|
|
|
}
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer1::nextCallback(Object* sender)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2010-08-25 17:56:30 +08:00
|
|
|
s_nSceneIdx++;
|
|
|
|
s_nSceneIdx = s_nSceneIdx % MAX_LAYER;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer2();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2010-08-20 17:08:30 +08:00
|
|
|
}
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer1::backCallback(Object* sender)
|
2011-05-12 10:52:10 +08:00
|
|
|
{
|
2010-08-25 17:56:30 +08:00
|
|
|
s_nSceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( s_nSceneIdx < 0 )
|
2012-04-19 14:35:52 +08:00
|
|
|
s_nSceneIdx += total;
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer2();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2011-05-12 10:52:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TestLayer1::step(float dt)
|
2011-05-12 10:52:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void TestLayer1::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 1 onEnter");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer1::onEnterTransitionDidFinish()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnterTransitionDidFinish();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 1: onEnterTransitionDidFinish");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer1::onExitTransitionDidStart()
|
2012-03-26 16:46:23 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExitTransitionDidStart();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 1: onExitTransitionDidStart");
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer1::onExit()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExit();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 1 onExit");
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:52:10 +08:00
|
|
|
TestLayer2::TestLayer2()
|
|
|
|
{
|
2010-08-20 14:35:37 +08:00
|
|
|
float x,y;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2010-08-20 14:35:37 +08:00
|
|
|
x = size.width;
|
|
|
|
y = size.height;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto bg1 = Sprite::create(s_back2);
|
2013-07-12 14:11:55 +08:00
|
|
|
bg1->setPosition( Point(size.width/2, size.height/2) );
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild(bg1, -1);
|
|
|
|
|
2014-01-03 06:25:28 +08:00
|
|
|
auto title = LabelTTF::create((transitions[s_nSceneIdx]).name, "Thonburi", 32 );
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild(title);
|
2013-07-05 16:49:22 +08:00
|
|
|
title->setColor( Color3B(255,32,32) );
|
2013-07-12 14:11:55 +08:00
|
|
|
title->setPosition( Point(x/2, y-100) );
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto label = LabelTTF::create("SCENE 2", "Marker Felt", 38);
|
2013-07-05 16:49:22 +08:00
|
|
|
label->setColor( Color3B(16,16,255));
|
2013-07-12 14:11:55 +08:00
|
|
|
label->setPosition( Point(x/2,y/2));
|
2010-08-20 14:35:37 +08:00
|
|
|
addChild( label);
|
|
|
|
|
|
|
|
// menu
|
2013-08-16 16:05:27 +08:00
|
|
|
auto item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(TestLayer2::backCallback, this) );
|
|
|
|
auto item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(TestLayer2::restartCallback, this) );
|
|
|
|
auto item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(TestLayer2::nextCallback, this) );
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto menu = Menu::create(item1, item2, item3, NULL);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-07-12 14:47:36 +08:00
|
|
|
menu->setPosition( Point::ZERO );
|
2013-07-12 14:11:55 +08:00
|
|
|
item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu, 1);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2011-05-12 10:52:10 +08:00
|
|
|
schedule(schedule_selector(TestLayer2::step), 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TestLayer2::~TestLayer2()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer2::restartCallback(Object* sender)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer1();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2010-08-20 17:08:30 +08:00
|
|
|
}
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer2::nextCallback(Object* sender)
|
2010-08-20 14:35:37 +08:00
|
|
|
{
|
2010-08-25 17:56:30 +08:00
|
|
|
s_nSceneIdx++;
|
|
|
|
s_nSceneIdx = s_nSceneIdx % MAX_LAYER;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer1();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2010-08-20 17:08:30 +08:00
|
|
|
}
|
2010-08-20 14:35:37 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TestLayer2::backCallback(Object* sender)
|
2011-05-12 10:52:10 +08:00
|
|
|
{
|
2010-08-25 17:56:30 +08:00
|
|
|
s_nSceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( s_nSceneIdx < 0 )
|
2012-04-19 14:35:52 +08:00
|
|
|
s_nSceneIdx += total;
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TransitionsTestScene();
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new TestLayer1();
|
2013-07-23 08:25:44 +08:00
|
|
|
s->addChild(layer);
|
2010-08-20 14:35:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
|
2010-09-16 16:32:14 +08:00
|
|
|
s->release();
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->release();
|
|
|
|
if (scene)
|
2010-08-20 17:08:30 +08:00
|
|
|
{
|
2013-07-23 08:25:44 +08:00
|
|
|
Director::getInstance()->replaceScene(scene);
|
2011-05-12 10:52:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TestLayer2::step(float dt)
|
2011-05-12 10:52:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2012-03-26 16:46:23 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void TestLayer2::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 2 onEnter");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer2::onEnterTransitionDidFinish()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnterTransitionDidFinish();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 2: onEnterTransitionDidFinish");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer2::onExitTransitionDidStart()
|
2012-03-26 16:46:23 +08:00
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExitTransitionDidStart();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 2: onExitTransitionDidStart");
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLayer2::onExit()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onExit();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("Scene 2 onExit");
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|