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
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TransitionPageTurn::TransitionPageTurn()
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_inSceneProxy = NodeGrid::create();
|
2013-12-19 22:01:32 +08:00
|
|
|
_outSceneProxy = NodeGrid::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-19 22:01:32 +08:00
|
|
|
_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
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE(_inSceneProxy);
|
|
|
|
AX_SAFE_RELEASE(_outSceneProxy);
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** creates a base transition with duration and incoming scene */
|
2021-12-25 10:04:45 +08:00
|
|
|
TransitionPageTurn* TransitionPageTurn::create(float t, Scene* scene, bool backwards)
|
2010-07-13 09:48:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TransitionPageTurn* transition = new TransitionPageTurn();
|
|
|
|
transition->initWithDuration(t, scene, backwards);
|
2013-12-18 17:47:20 +08:00
|
|
|
transition->autorelease();
|
|
|
|
return transition;
|
2010-07-13 09:48:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** initializes a transition with duration and incoming scene */
|
2021-12-25 10:04:45 +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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (_isInSceneOnTop)
|
|
|
|
{
|
2014-05-31 07:42:05 +08:00
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-31 07:42:05 +08:00
|
|
|
_inSceneProxy->visit(renderer, transform, flags);
|
|
|
|
_outSceneProxy->visit(renderer, transform, flags);
|
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-12-25 10:04:45 +08:00
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
Vec2 s = _director->getWinSize();
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = 16;
|
|
|
|
y = 12;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = 12;
|
|
|
|
y = 16;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* action = this->actionWithSize(Vec2(x, y));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_back)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_outSceneProxy->runAction(Sequence::create(
|
2022-07-15 19:17:01 +08:00
|
|
|
action, CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), StopGrid::create(), 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);
|
2021-12-25 10:04:45 +08:00
|
|
|
_inSceneProxy->runAction(Sequence::create(Show::create(), action,
|
2022-07-15 19:17:01 +08:00
|
|
|
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)),
|
2021-12-25 10:04:45 +08:00
|
|
|
StopGrid::create(), 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();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2013-12-12 13:44:29 +08:00
|
|
|
TransitionScene::onExit();
|
|
|
|
}
|
2010-07-13 09:48:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionInterval* TransitionPageTurn::actionWithSize(const Vec2& 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
|
2021-12-25 10:04:45 +08:00
|
|
|
return ReverseTime::create(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
|
|
|
}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|