mirror of https://github.com/axmolengine/axmol.git
Improve ActionCoroutine callback style (#1481)
This commit is contained in:
parent
e77b54b785
commit
0f114baf8c
|
@ -80,10 +80,10 @@ bool Coroutine::moveNext() const
|
|||
//
|
||||
// ActionCoroutine
|
||||
//
|
||||
ActionCoroutine* ActionCoroutine::create(Coroutine&& coroutine)
|
||||
ActionCoroutine* ActionCoroutine::create(const std::function<Coroutine()>& function)
|
||||
{
|
||||
auto ret = new (std::nothrow) ActionCoroutine();
|
||||
if (ret && ret->initWithCoroutine(std::forward<Coroutine>(coroutine)))
|
||||
if (ret && ret->initWithCoroutine(function))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
|
@ -92,6 +92,12 @@ ActionCoroutine* ActionCoroutine::create(Coroutine&& coroutine)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool ActionCoroutine::initWithCoroutine(const std::function<Coroutine()>& function) noexcept
|
||||
{
|
||||
_coroutine = std::forward<Coroutine>(function());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ActionCoroutine::isDone() const
|
||||
{
|
||||
auto action = _coroutine.currentAction();
|
||||
|
@ -112,10 +118,4 @@ void ActionCoroutine::step(float dt)
|
|||
_coroutine.moveNext();
|
||||
}
|
||||
|
||||
bool ActionCoroutine::initWithCoroutine(Coroutine&& coroutine) noexcept
|
||||
{
|
||||
_coroutine = std::forward<Coroutine>(coroutine);
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_AX_END
|
||||
|
|
|
@ -128,7 +128,7 @@ public:
|
|||
* @return A pointer of ActionCoroutine. If creation failed, return nil.
|
||||
* @lua NA
|
||||
*/
|
||||
static ActionCoroutine* create(Coroutine&& coroutine);
|
||||
static ActionCoroutine* create(const std::function<Coroutine()>& function);
|
||||
|
||||
//
|
||||
// Overrides
|
||||
|
@ -143,7 +143,7 @@ public:
|
|||
/** initializes the action with the Coroutine
|
||||
* @lua NA
|
||||
*/
|
||||
bool initWithCoroutine(Coroutine&& coroutine) noexcept;
|
||||
bool initWithCoroutine(const std::function<Coroutine()>& function) noexcept;
|
||||
|
||||
protected:
|
||||
/** Coroutine */
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
build-*/
|
||||
build-*/
|
||||
build_*/
|
|
@ -2428,7 +2428,7 @@ void ActionCoroutineTest::onEnter()
|
|||
_frameCount = 1;
|
||||
centerSprites(0);
|
||||
|
||||
auto action = ActionCoroutine::create(coroutineCallback());
|
||||
auto action = ActionCoroutine::create(AX_CALLBACK_0(ActionCoroutineTest::coroutineCallback, this));
|
||||
this->runAction(action);
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
@ -2443,7 +2443,7 @@ void ActionCoroutineTest::onEnter()
|
|||
void ActionCoroutineTest::update(float delta)
|
||||
{
|
||||
_frameCount++;
|
||||
_label->setString(StringUtils::format("frame count : %" PRIu64 ")", _frameCount));
|
||||
_label->setString(StringUtils::format("frame count : %" PRIu64 "", _frameCount));
|
||||
}
|
||||
|
||||
std::string ActionCoroutineTest::title() const
|
||||
|
|
Loading…
Reference in New Issue