2018-04-21 21:24:46 +08:00
|
|
|
#include "..\e2dtransition.h"
|
|
|
|
|
#include "..\e2dnode.h"
|
2017-10-21 19:09:31 +08:00
|
|
|
|
2018-08-14 00:26:20 +08:00
|
|
|
e2d::MoveTransition::MoveTransition(Scene* scene, float duration, Direction direction)
|
|
|
|
|
: Transition(scene, duration)
|
2018-05-09 00:34:15 +08:00
|
|
|
, _direction(direction)
|
2017-10-21 19:09:31 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-19 15:11:20 +08:00
|
|
|
bool e2d::MoveTransition::_init(Game * game, Scene * prev)
|
2017-10-21 19:09:31 +08:00
|
|
|
{
|
2018-08-19 15:11:20 +08:00
|
|
|
if (Transition::_init(game, prev))
|
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-13 23:47:10 +08:00
|
|
|
if (_outScene) _outScene->setPos(0, 0);
|
|
|
|
|
_inScene->setPos(_startPos);
|
2018-08-02 00:27:45 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2017-12-09 15:27:11 +08:00
|
|
|
}
|
2017-10-21 19:09:31 +08:00
|
|
|
|
2018-08-14 00:26:20 +08:00
|
|
|
void e2d::MoveTransition::_update()
|
2018-04-17 11:41:33 +08:00
|
|
|
{
|
2018-08-14 00:26:20 +08:00
|
|
|
Transition::_update();
|
2018-08-02 00:27:45 +08:00
|
|
|
|
2018-05-09 00:34:15 +08:00
|
|
|
if (_outScene)
|
2018-04-17 11:41:33 +08:00
|
|
|
{
|
2018-08-13 23:47:10 +08:00
|
|
|
_outScene->setPos(_posDelta * _delta);
|
2018-04-17 11:41:33 +08:00
|
|
|
}
|
2018-05-09 00:34:15 +08:00
|
|
|
if (_inScene)
|
2018-04-17 11:41:33 +08:00
|
|
|
{
|
2018-08-13 23:47:10 +08:00
|
|
|
_inScene->setPos(_startPos + _posDelta * _delta);
|
2018-04-17 11:41:33 +08:00
|
|
|
}
|
|
|
|
|
|
2018-05-08 20:03:29 +08:00
|
|
|
if (_delta >= 1)
|
2018-04-17 11:41:33 +08:00
|
|
|
{
|
2018-08-14 00:26:20 +08:00
|
|
|
this->_stop();
|
2018-04-17 11:41:33 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-14 00:26:20 +08:00
|
|
|
void e2d::MoveTransition::_reset()
|
2017-12-09 15:27:11 +08:00
|
|
|
{
|
2018-08-13 23:47:10 +08:00
|
|
|
if (_outScene) _outScene->setPos(0, 0);
|
|
|
|
|
_inScene->setPos(0, 0);
|
2017-10-21 19:09:31 +08:00
|
|
|
}
|