2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-01 10:09:13 +08:00
|
|
|
#include "2d/CCTransitionPageTurn.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionPageTurn3D.h"
|
2014-05-01 10:09:13 +08:00
|
|
|
#include "2d/CCNodeGrid.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "renderer/CCRenderer.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn::TransitionPageTurn()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-12-19 22:01:32 +08:00
|
|
|
_inSceneProxy = NodeGrid::create();
|
|
|
|
_outSceneProxy = NodeGrid::create();
|
|
|
|
|
|
|
|
_inSceneProxy->retain();
|
|
|
|
_outSceneProxy->retain();
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn::~TransitionPageTurn()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-12-12 13:44:29 +08:00
|
|
|
CC_SAFE_RELEASE(_inSceneProxy);
|
|
|
|
CC_SAFE_RELEASE(_outSceneProxy);
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** creates a base transition with duration and incoming scene */
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn * TransitionPageTurn::create(float t, Scene *scene, bool backwards)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
TransitionPageTurn * transition = new (std::nothrow) TransitionPageTurn();
|
2013-12-18 17:47:20 +08:00
|
|
|
transition->initWithDuration(t,scene,backwards);
|
|
|
|
transition->autorelease();
|
|
|
|
return transition;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** initializes a transition with duration and incoming scene */
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TransitionPageTurn::initWithDuration(float t, Scene *scene, bool backwards)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME:: needed before [super init]
|
2013-06-15 14:03:30 +08:00
|
|
|
_back = backwards;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TransitionScene::initWithDuration(t, scene))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// do something
|
|
|
|
}
|
|
|
|
return true;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TransitionPageTurn::sceneOrder()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isInSceneOnTop = _back;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void TransitionPageTurn::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2013-11-14 09:44:35 +08:00
|
|
|
{
|
2014-05-31 07:42:05 +08:00
|
|
|
Scene::draw(renderer, transform, flags);
|
2013-11-14 09:44:35 +08:00
|
|
|
|
|
|
|
if( _isInSceneOnTop ) {
|
2014-05-31 07:42:05 +08:00
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
2013-11-14 09:44:35 +08:00
|
|
|
} else {
|
2014-05-31 07:42:05 +08:00
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
2013-12-30 14:43:18 +08:00
|
|
|
|
2013-11-14 09:44:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TransitionPageTurn::onEnter()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionScene::onEnter();
|
2013-12-12 13:44:29 +08:00
|
|
|
|
2013-12-16 14:21:05 +08:00
|
|
|
_inSceneProxy->setTarget(_inScene);
|
|
|
|
_outSceneProxy->setTarget(_outScene);
|
2013-12-12 13:44:29 +08:00
|
|
|
|
|
|
|
_inSceneProxy->onEnter();
|
|
|
|
_outSceneProxy->onEnter();
|
|
|
|
|
2021-02-05 23:09:14 +08:00
|
|
|
Size s = _director->getWinSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
int x,y;
|
2013-02-26 17:03:29 +08:00
|
|
|
if (s.width > s.height)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
x=16;
|
2010-12-27 09:40:45 +08:00
|
|
|
y=12;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x=12;
|
2010-12-27 09:40:45 +08:00
|
|
|
y=16;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
ActionInterval *action = this->actionWithSize(Size(x,y));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _back )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->runAction
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
|
|
|
action,
|
2013-07-16 03:43:22 +08:00
|
|
|
CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid::create(),
|
2013-12-18 17:47:20 +08:00
|
|
|
nullptr
|
2012-04-19 14:35:52 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// to prevent initial flicker
|
2013-12-12 13:44:29 +08:00
|
|
|
_inSceneProxy->setVisible(false);
|
|
|
|
_inSceneProxy->runAction
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Sequence::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
Show::create(),
|
2012-04-19 14:35:52 +08:00
|
|
|
action,
|
2013-07-16 03:43:22 +08:00
|
|
|
CallFunc::create(CC_CALLBACK_0(TransitionScene::finish,this)),
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid::create(),
|
2013-12-18 17:47:20 +08:00
|
|
|
nullptr
|
2012-04-19 14:35:52 +08:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
2013-12-12 13:44:29 +08:00
|
|
|
void TransitionPageTurn::onExit()
|
|
|
|
{
|
2013-12-19 22:01:32 +08:00
|
|
|
_outSceneProxy->setTarget(nullptr);
|
|
|
|
_outSceneProxy->setTarget(nullptr);
|
2013-12-12 13:44:29 +08:00
|
|
|
_outSceneProxy->onExit();
|
|
|
|
_inSceneProxy->onExit();
|
|
|
|
|
|
|
|
TransitionScene::onExit();
|
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ActionInterval* TransitionPageTurn:: actionWithSize(const Size& vector)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_back)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
2013-06-20 14:13:12 +08:00
|
|
|
return ReverseTime::create
|
2012-04-19 14:35:52 +08:00
|
|
|
(
|
2013-06-20 14:13:12 +08:00
|
|
|
PageTurn3D::create(_duration, vector)
|
2012-04-19 14:35:52 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Get hold of the PageTurn3DAction
|
2013-06-20 14:13:12 +08:00
|
|
|
return PageTurn3D::create(_duration, vector);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|