Problem with Action Sequence inside Layer, which is added to the PlaysSceneLayer


#1

Hi Guys,

I just started with cocos2d-x and ran into an problem using CCSequence, maybe somebody can give me a hint or solution,
’cause i have no idea what is happening there. My Game has a PlayScene with an PlaysSceneLayer.
There is another layer, which it’s added to the PlaySceneLayer, to show some animated Text.
The Action and Logic to animate these Texts I’d like to handle inside this Layer.
But that is not working properly. When i call “runAction” inside a added Layer, CCCallFunc is working, but NO CCSpawn or CCSequence.
Let me show you some Code:

In the Constructor i initialize the Layer for the text and call the method, that should run my Action.

PlaySceneLayer::PlaySceneLayer(void)
{
  notificationLayer = new NotificationLayer();
  addChild(notificationLayer);
  CCPoint *location = new CCPoint(100, 100);
  notificationLayer->addNote("test", location);
}

The “addNote” Method i declared in my Custom Layer:

void NotificationLayer::addNote(const char *note,CCPoint *position){
  CCLog("NotificationLayer::addNote(const char: %s)", note);
  CCLabelTTF *label = CCLabelTTF::labelWithString(note, CCSizeMake(200, 62), CCTextAlignmentCenter, Resources::FONT, 50);
  label->setPosition(*position);
  this->addChild(label);
    // CCCallFunc IS WORKING WELL!!!
  // action = CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callBack));

  // CCSpawn or CCSequence IS NOT WORKING!!!
  action = CCSequence::actions(CCDelayTime::actionWithDuration(1),
                               CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callback)),
                               NULL);
    runAction(action);
}

Do you have an idea why CCSequence is not working in this case?

Thank you,
casualistic


#2

I haven’t invoked layer~~>runAction, normally sprite~~>runAction instead.
If you add NotificationLayer directly to CCScene, will CCSequence work on NotificationLayer?


#3

You said CCCallFunc was working, and CCCallFunc is inside CCSequence,
so why did you say CCSequence not working?


#4

Thank you for the very quick response. Now I’m adding my custom Layer directly to PlayScene with the same result.
CCFunc is working as a action of CCSequence, but CCSequence is working only with one Action. (The callback function does a simple CCLog())
Take a look:

// IS WORKING
action = CCSequence::actions(CCCallFuncN::actionWithTarget( this, callfuncN_selector(NotificationLayer::callback) ), 
                                                    NULL);

// IS NOT WORKING
 action = CCSequence::actions(CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callback)),
                               CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callback2)),
                               NULL);

// IS ALSO WORKING
action = CCSpawn::actions(CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callback)),
                               CCCallFunc::actionWithTarget(this, callfunc_selector(NotificationLayer::callback2)),
                               NULL);

Then i tried an action with duration. The following code snippet i put into the main PlaySceneLayer, where everything is working fine, and
into my Layer, where this code is not working. (I tested both ways: the layer as the only node of the PlayScene and as a node of the PlaySceneLayer)

CCLabelTTF *testLabel = CCLabelTTF::labelWithString("Test Label", CCSizeMake(200, 62), CCTextAlignmentCenter, "Arial", 50);
  this->addChild(testLabel);
  CCAction *action = CCRotateBy::actionWithDuration( 2,  720);
  testLabel->runAction(action);

Do you have any idea, maybe it has something to do with the time Step oder Update of my layer?

Best
casualistic

s. Thanks for your awsome work on cocos2d-x and that you spend your time on our questions


#5

I think you can refer ActionSequence2 in ActionsTest.cpp.


#6

I did a simple mistake and forgot to call the super CCLayer::onEnter(). That’s why i could not shedule the delayed Actions.


#7

Martin Mulzer wrote:

I did a simple mistake and forgot to call the super CCLayer::onEnter(). That’s why i could not shedule the delayed Actions. Now everything is working fine.