Magic_Game/core/Transition/MoveTransition.cpp

69 lines
1.3 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
2017-10-21 19:09:31 +08:00
2018-07-28 20:06:27 +08:00
e2d::MoveTransition::MoveTransition(float duration, Direction direction)
: Transition(duration)
, _direction(direction)
2017-10-21 19:09:31 +08:00
{
}
2018-08-02 00:27:45 +08:00
bool e2d::MoveTransition::init(Scene * prev, Scene * next)
2017-10-21 19:09:31 +08:00
{
2018-08-02 00:27:45 +08:00
if (Transition::init(prev, next))
2017-10-21 19:09:31 +08:00
{
2018-08-02 00:27:45 +08:00
float width = _windowSize.width;
float height = _windowSize.height;
if (_direction == Direction::Up)
{
_posDelta = Vector2(0, -height);
_startPos = Point(0, height);
}
else if (_direction == Direction::Down)
{
_posDelta = Vector2(0, height);
_startPos = Point(0, -height);
}
else if (_direction == Direction::Left)
{
_posDelta = Vector2(-width, 0);
_startPos = Point(width, 0);
}
else if (_direction == Direction::Right)
{
_posDelta = Vector2(width, 0);
_startPos = Point(-width, 0);
}
2017-10-21 19:09:31 +08:00
2018-08-02 00:27:45 +08:00
if (_outScene) _outScene->getRoot()->setPos(0, 0);
_inScene->getRoot()->setPos(_startPos);
return true;
}
return false;
}
2017-10-21 19:09:31 +08:00
2018-08-02 00:27:45 +08:00
void e2d::MoveTransition::update()
2018-04-17 11:41:33 +08:00
{
2018-08-02 00:27:45 +08:00
Transition::update();
if (_outScene)
2018-04-17 11:41:33 +08:00
{
_outScene->getRoot()->setPos(_posDelta * _delta);
2018-04-17 11:41:33 +08:00
}
if (_inScene)
2018-04-17 11:41:33 +08:00
{
_inScene->getRoot()->setPos(_startPos + _posDelta * _delta);
2018-04-17 11:41:33 +08:00
}
if (_delta >= 1)
2018-04-17 11:41:33 +08:00
{
2018-08-02 00:27:45 +08:00
this->stop();
2018-04-17 11:41:33 +08:00
}
}
2018-08-02 00:27:45 +08:00
void e2d::MoveTransition::reset()
{
if (_outScene) _outScene->getRoot()->setPos(0, 0);
_inScene->getRoot()->setPos(0, 0);
2017-10-21 19:09:31 +08:00
}