Forums » C++ Framework » Problem with initWithTarget function »
| zz zz | Problem with initWithTarget function | ||
|---|---|---|---|
|
Added by zz zz over 2 years ago
Hi, I have a problem with initWithTarget function, which You have translated from Objective-C. The problem is that this function look very different (for me) in Objective-C. I want to rewrite this tutorial: http://www.raywenderlich.com/352/how-to-make-a-simple-iphone-game-with-cocos2d-tutorial id actionMove = [CCMoveTo actionWithDuration:actualDurationposition:ccp(-target.contentSize.width/2, actualY)]; id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)]; [target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]]; I have only rewritten two functions, first and the third, I don't know how to translate to C++ the second. The translated lines of code: CCMoveTo *actionMove = CCMoveTo::actionWithDuration(actualDuration, ccp(-target->getContentSize().width/2, actualY)); target->runAction(CCSequence::actions(actionMove, actionMoveDone)); and the attempt to translate the second line...: SelectorProtocol *selectorProtocol = new SelectorProtocol(); CCCallFuncN *actionMoveDone = CCCallFuncN::actionWithTarget(selectorProtocol, SEL_CallFuncN(target)); (I don't even know at all what You mean by "SelectorProtocol", it is some class to join the game node and the action (function), right?) Please, help me and translate this one line of code to the C++ in the right way. |
||
| Strawberry Milkshake | RE: Problem with initWithTarget function | ||
|
Added by Strawberry Milkshake over 2 years ago
Try this instead:
target->runAction( CCSequence::actions(
CCMoveTo::actionWithDuration(actualDuration, ccp(-target->getContentSize().width/2, actualY)),
CCCallFuncN::actionWithTarget(this, callfuncN_selector(HelloWorld::spriteMoveFinished)),
0l) );
What "id" is depends on the context. The CCMoveTo action could be represented by a CCFiniteTimeAction (which is the argument for CCSequence::actions), for example. You can find more examples in the "tests" program, it's all in there :) Also, don't forget to terminate the list of actions with a null pointer (nil in Objective-C, in C++ usually written as 0l, 0 or NULL). |
||
| zz zz | RE: Problem with initWithTarget function | ||
|
Added by zz zz over 2 years ago
Thanks very much! ;) |
(1-2/2)