I am trying to convert some Cocos2d-iphone code to Cocos2d-x code and could use a little assistance. In the Cocos2d-iphone code, it contains the following definition:
@interface CCPanZoomControllerScale : CCScaleTo {
CCPanZoomController *_controller;
CGPoint _point;
}+(id) actionWithDuration:(ccTime)duration scale:(float)s controller:(CCPanZoomController*)controller point:(CGPoint)pt;
@end
@implementation CCPanZoomControllerScale
+(id) actionWithDuration:(ccTime)duration
scale:(float)s
controller:(CCPanZoomController*)controller
point:(CGPoint)pt
{
return [[[self alloc] initWithDuration:duration scale:s controller:controller point:pt] autorelease];
}
In trying to convert this (statement in bold) to C++, I believe it should be a static method. Also, the Cocos2d-x documentation recommends returning bool, because id doesn't exist in C++. However in the method implementation I'm not sure what to return. Do I just return true?
static bool actionWithDuration(ccTime duration, float scale, PanZoomController* controller, CCPoint point){
return true;
}
In objective-C, you can return the self object in static methods also(means in class methods).But in c++, If you want to return the current object, you need to create the object for current class and need to return that object only. we con't able to use the "this" directly. So, make this method as non-static and return the current class object "this".
You can specify the method declaration as shown below.
CCAction* className::actionWithDuration(ccTime duration, float scale, PanZoomController *controller, CCPoint point)
{
return (your class object);
}
Whenever you want to call this method, Create the object for that particular class and call this method on the object for example,
PanZoomController *controller = new PanZoomController();
CCPanZoomControllerScale *scaleController = new CCPanZoomControllerScale();
sprite -> runAction(scaleController -> actionWithDuration(duration, scale, controller, pt));
I think this can be helpful for you.