I’m writing my first project and I’m in trouble with things that someone more skilled surely knows 
In my simplified scenario I have defined the layer GameLayer like this
bool GameLayer::init() {
...
auto eventListener = EventListenerKeyboard::create();
eventListener->onKeyPressed = [&](EventKeyboard::KeyCode keyCode, Event* event) {
DoAction();
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, this);
return true;
}
For my example purposes GameLayer has 2 members:
MySprite* m_pMySprite;
and
bool m_bActionRunning;
Now the problems 
I have defined GameLayer::DoAction this way
void GameLayer::ParseInput(Direction direction) {
if (m_bActionRunning) return;
m_bActionRunning = true;
CallFunc* restoreCallback = CallFunc::create([&]() { m_bActionRunning = false; });
runAction(Sequence::create(
mySprite->DoAction(),
restoreCallback
));
and MySprite::DoAction() this way
Sequence* MySprite::DoAction() {
// update MySprite internal state
CallFunc* updateMySpriteInternalState = CallFunc::create([&]() {
m_PositionX = m_PositionX + 100;
}
// update MySprite graphical state (using m_PositionX)
TargetedAction* updateMySpritePosition = TargetedAction::create(this, MoveTo::create(5.0f, Vec2(0, m_PositionX)));
// returns the sequence
return Sequence::create(
updateMySpriteInternalState ,
updateMySpritePosition,
nullptr
);
}
Since I want to keep separation logic I have defined MySprite behaviour in MySprite and not in GameLayer. GameLayer can do something on m_pMySprite returning and running the sequence object returned from m_pMySprite->DoAction(). Also at the end of the sequence GameLayer restores m_bActionRunning enabling other inputs.
Well, my questions are pretty simple
- is this design pattern logical or it is completely non-sense?
- updateMySpritePosition runs a targeted action that requires m_PositionX incremented by 100, but when the action is created m_PositionX is not incrementd because updateMySpriteInternalState is not executed yet. How can I have such variable incremented instead?
