performSelector equivalent


#1

Hi

What would be the cocos2d-X equivalent of this very handy objective-C method ?

[self performSelector:@selector(myMethod:) withObject:myObject afterDelay:1.0f];

Thanks in advance


#2

You might need
CCDelayTime::actionWithDuration
CCCallFunc::actionWithTarget
callfunc_selector()

not sure though


#3

This blog explains a way of doing this and I have used it with no problems:

http://gameit.ro/2011/09/performing-a-selector-after-a-delay-in-cocos2d-x/

Francis


#4

It works ! Thanks a lot. Any way to call a function with a parameter this way ?


#5

Hi,

Rather than using the built in ‘runAction’ in my obj-c I used a selector directly with
the perfromSelector:withObject: and returned a bool.

I can’t see any documentation on how to do this.

Help will be appreciated

LB


#6

Hello Again,

So got something hanging together, bit of a fiddle.

obj-c : I had a selector that takes a parameter and then returns a value.

c++ : Looks like you can’t return a value, so you need to modify the parameter…

   // Call a selector directly and give it a parameter which is return value
   //
   CCCallFuncND *callSelectorAction = CCCallFuncND::actionWithTarget(obj, sel, (void*)&retBool);
   callSelectorAction->execute();

    // Normally with action stuff you'd do this...
    //
    CCCallFunc *callSelectorAction = CCCallFunc::actionWithTarget( object, callback);
    object->runAction(CCSequence::actions(callSelectorAction,NULL));

LB


#7

Leo Lou wrote:

You might need
CCDelayTime::actionWithDuration
CCCallFunc::actionWithTarget
callfunc_selector()
>
not sure though

ccDelayTime delay = ccDelayTime::create;
ccCallFunc
func = ccCallFunc::create(this, toBeCalledFunc);
cocos2d::CCSequence * seq = CCSequence::createWithTwoActions(delay, func);
object->runAction(seq);