Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count run action finish to call final finish when two run actions are… #1946

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 71 additions & 30 deletions core/2d/Transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,33 @@ void TransitionScene::draw(Renderer* renderer, const Mat4& transform, uint32_t f
}
}

void TransitionScene::finish()
void TransitionScene::setWaitForFinishCount(int count)
{
// clean up
_inScene->setVisible(true);
_inScene->setPosition(0, 0);
_inScene->setScale(1.0f);
_inScene->setRotation(0.0f);
_inScene->setAdditionalTransform(nullptr);

_outScene->setVisible(false);
_outScene->setPosition(0, 0);
_outScene->setScale(1.0f);
_outScene->setRotation(0.0f);
_outScene->setAdditionalTransform(nullptr);
_waitForFinishCount = count;
}

//[self schedule:@selector(setNewScene:) interval:0];
this->schedule(AX_SCHEDULE_SELECTOR(TransitionScene::setNewScene), 0);
void TransitionScene::finish()
{
_waitForFinishCount--;

if(_waitForFinishCount == 0)
{
// clean up
_inScene->setVisible(true);
_inScene->setPosition(0, 0);
_inScene->setScale(1.0f);
_inScene->setRotation(0.0f);
_inScene->setAdditionalTransform(nullptr);

_outScene->setVisible(false);
_outScene->setPosition(0, 0);
_outScene->setScale(1.0f);
_outScene->setRotation(0.0f);
_outScene->setAdditionalTransform(nullptr);

//[self schedule:@selector(setNewScene:) interval:0];
this->schedule(AX_SCHEDULE_SELECTOR(TransitionScene::setNewScene), 0);
}
}

void TransitionScene::setNewScene(float /*dt*/)
Expand Down Expand Up @@ -176,7 +186,7 @@ void TransitionScene::hideOutShowIn()
void TransitionScene::onEnter()
{
Scene::onEnter();

// disable events while transitions
_eventDispatcher->setEnabled(false);

Expand Down Expand Up @@ -268,12 +278,15 @@ void TransitionRotoZoom::onEnter()

_inScene->setAnchorPoint(Vec2(0.5f, 0.5f));
_outScene->setAnchorPoint(Vec2(0.5f, 0.5f));


setWaitForFinishCount(2);

auto rotozoom = Sequence::create(
Spawn::create(ScaleBy::create(_duration / 2, 0.001f), RotateBy::create(_duration / 2, 360 * 2), nullptr),
DelayTime::create(_duration / 2), nullptr);

_outScene->runAction(rotozoom);
_outScene->runAction(
Sequence::create(rotozoom, CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
_inScene->runAction(
Sequence::create(rotozoom->reverse(), CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
}
Expand Down Expand Up @@ -306,6 +319,8 @@ void TransitionJumpZoom::onEnter()
_inScene->setAnchorPoint(Vec2(0.5f, 0.5f));
_outScene->setAnchorPoint(Vec2(0.5f, 0.5f));

setWaitForFinishCount(2);

ActionInterval* jump = JumpBy::create(_duration / 4, Vec2(-s.width, 0.0f), s.width / 4, 2);
ActionInterval* scaleIn = ScaleTo::create(_duration / 4, 1.0f);
ActionInterval* scaleOut = ScaleTo::create(_duration / 4, 0.5f);
Expand All @@ -314,8 +329,9 @@ void TransitionJumpZoom::onEnter()
auto jumpZoomIn = Sequence::create(jump, scaleIn, nullptr);

ActionInterval* delay = DelayTime::create(_duration / 2);

_outScene->runAction(jumpZoomOut);

_outScene->runAction(
Sequence::create(jumpZoomOut, CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
_inScene->runAction(
Sequence::create(delay, jumpZoomIn, CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
}
Expand Down Expand Up @@ -457,12 +473,16 @@ void TransitionSlideInL::onEnter()
TransitionScene::onEnter();
this->initScenes();

setWaitForFinishCount(2);

ActionInterval* in = this->action();
ActionInterval* out = this->action();

ActionInterval* inAction = Sequence::create(easeActionWithAction(in), CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

ActionInterval* inAction = easeActionWithAction(in);
ActionInterval* outAction = Sequence::create(
easeActionWithAction(out), CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->runAction(inAction);
_outScene->runAction(outAction);
}
Expand Down Expand Up @@ -634,10 +654,13 @@ void TransitionShrinkGrow::onEnter()
_inScene->setAnchorPoint(Vec2(2 / 3.0f, 0.5f));
_outScene->setAnchorPoint(Vec2(1 / 3.0f, 0.5f));

setWaitForFinishCount(2);

ActionInterval* scaleOut = ScaleTo::create(_duration, 0.01f);
ActionInterval* scaleIn = ScaleTo::create(_duration, 1.0f);

_inScene->runAction(this->easeActionWithAction(scaleIn));

_inScene->runAction(Sequence::create(this->easeActionWithAction(scaleIn),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
_outScene->runAction(Sequence::create(this->easeActionWithAction(scaleOut),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr));
}
Expand All @@ -659,6 +682,8 @@ void TransitionFlipX::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -676,13 +701,14 @@ void TransitionFlipX::onEnter()
outDeltaZ = -90;
outAngleZ = 0;
}

auto inA = Sequence::create(DelayTime::create(_duration / 2), Show::create(),
OrbitCamera::create(_duration / 2, 1, 0, inAngleZ, inDeltaZ, 0, 0),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

auto outA = Sequence::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 0, 0), Hide::create(),
DelayTime::create(_duration / 2), nullptr);
DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->runAction(inA);
_outScene->runAction(outA);
Expand Down Expand Up @@ -714,6 +740,8 @@ void TransitionFlipY::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -736,7 +764,8 @@ void TransitionFlipY::onEnter()
OrbitCamera::create(_duration / 2, 1, 0, inAngleZ, inDeltaZ, 90, 0),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);
auto outA = Sequence::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 90, 0), Hide::create(),
DelayTime::create(_duration / 2), nullptr);
DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->runAction(inA);
_outScene->runAction(outA);
Expand Down Expand Up @@ -769,6 +798,8 @@ void TransitionFlipAngular::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -791,7 +822,8 @@ void TransitionFlipAngular::onEnter()
OrbitCamera::create(_duration / 2, 1, 0, inAngleZ, inDeltaZ, -45, 0),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);
auto outA = Sequence::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 45, 0), Hide::create(),
DelayTime::create(_duration / 2), nullptr);
DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->runAction(inA);
_outScene->runAction(outA);
Expand Down Expand Up @@ -823,6 +855,8 @@ void TransitionZoomFlipX::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -846,7 +880,8 @@ void TransitionZoomFlipX::onEnter()
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);
auto outA = Sequence::create(Spawn::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 0, 0),
ScaleTo::create(_duration / 2, 0.5f), nullptr),
Hide::create(), DelayTime::create(_duration / 2), nullptr);
Hide::create(), DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->setScale(0.5f);
_inScene->runAction(inA);
Expand Down Expand Up @@ -880,6 +915,8 @@ void TransitionZoomFlipY::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -905,7 +942,8 @@ void TransitionZoomFlipY::onEnter()

auto outA = Sequence::create(Spawn::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 90, 0),
ScaleTo::create(_duration / 2, 0.5f), nullptr),
Hide::create(), DelayTime::create(_duration / 2), nullptr);
Hide::create(), DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->setScale(0.5f);
_inScene->runAction(inA);
Expand Down Expand Up @@ -938,6 +976,8 @@ void TransitionZoomFlipAngular::onEnter()

_inScene->setVisible(false);

setWaitForFinishCount(2);

float inDeltaZ, inAngleZ;
float outDeltaZ, outAngleZ;

Expand All @@ -963,7 +1003,8 @@ void TransitionZoomFlipAngular::onEnter()
Show::create(), CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);
auto outA = Sequence::create(Spawn::create(OrbitCamera::create(_duration / 2, 1, 0, outAngleZ, outDeltaZ, 45, 0),
ScaleTo::create(_duration / 2, 0.5f), nullptr),
Hide::create(), DelayTime::create(_duration / 2), nullptr);
Hide::create(), DelayTime::create(_duration / 2),
CallFunc::create(AX_CALLBACK_0(TransitionScene::finish, this)), nullptr);

_inScene->setScale(0.5f);
_inScene->runAction(inA);
Expand Down
11 changes: 9 additions & 2 deletions core/2d/Transition.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AX_DLL TransitionScene : public Scene
*/
static TransitionScene* create(float t, Scene* scene);

/** Called after the transition finishes.
/** Called after a transition finishes.
*/
void finish();

Expand All @@ -122,15 +122,22 @@ class AX_DLL TransitionScene : public Scene
protected:
virtual void sceneOrder();
void setNewScene(float dt);

/** Set the number of actions to be done to finish
*/
void setWaitForFinishCount(int count);

Scene* _inScene;
Scene* _outScene;
float _duration;
bool _isInSceneOnTop;
bool _isSendCleanupToScene;



private:
AX_DISALLOW_COPY_AND_ASSIGN(TransitionScene);

int _waitForFinishCount = 1;
};

/** @class TransitionSceneOriented
Expand Down