call function after sequence in cocos2dx

  • abhishek
    Likes 0

    Problem Description

    i want to play a sequence of animations on a sprite.
    and once the actions are done, i want to call a function.

    here is the sample code i have written as of now:

    auto move1 = MoveBy::create(0.05, Point(card1->getBoundingBox().size.width*0.05, 0));
    auto move2 = MoveBy::create(0.05, Point(-card1->getBoundingBox().size.width*0.05, 0));
    auto action = Sequence::create(move1, move2, move2, move1, NULL);
    card1->runAction(action);


    so once the sequence is complete, i want to call a function say fn_check
    how can i do this?

    any help will be very much appreciated
    :)

  • Sonar Systems admin
    Likes 0

    Go to our Cocos API Guide – http://cocos.sonarlearning.co.uk/v1.0/docs/actions

     

    Go to the bottom, you need to use Call Func and Sequences, let us know if you need any more help :D

  • abhishek
    Likes 0

    hi,
    i checked the link and the section you told me about.
    so this is the code you are referring to:

    CallFunc *functionAction = CallFunc::create( functionToCall );
    nodeName->runAction( functionAction );
    
    but i still dont know how to use this code in my current piece of code.
    
    this is my code:
    auto move1 = MoveBy::create(0.05, Point(card1->getBoundingBox().size.width*0.05, 0));
    auto move2 = MoveBy::create(0.05, Point(-card1->getBoundingBox().size.width*0.05, 0));
    auto action = Sequence::create(move1, move2, move2, move1, NULL);
    card1->runAction(action);
    
    so according to your code syntax above, where do i include functionAction?

     

  • abhishek
    Likes 0

    another question if you dont mind..
    i used this line of code in cocos2d-x v2.2 to dynamically change image of a sprite, the image was saved in sprite sheet:

    sp_baby1->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(ccsf("baby4_happy_%d.png",baby1)));

    but now i am using cocos2d-x v3.0 and this line does not work anymore.
    i want to be able to change the image of a sprite dynamically. and the images are in a sprite sheet.
    for example: baby_1 to baby_10
    now depending upon the value of myInt (could be between 1 to 10), i want to set the image of my sprite.
    how can i do this?
    could you please help?
    thanks 


    This reply has been verified.

Login to reply