I’ve got a work around for follow action with an initial offset.Offset can be horizontal(x) offset or vertical(y) offset.By providing an offset,the follow action will not jump to the centre of the followed node when following the node but it will follow the node from the provided offset.The implementation is as follows-
In CCAction.h modify the create method as-
Follow* create(Node *followedNode,const Rect& rect=Rect::ZERO,float offsetX=0.0,float offsetY=0.0);
bool initWithTarget(Node *followedNode, const Rect& rect = Rect::ZERO,float offsetX=0.0,float offsetY=0.0);
In CCAction.cpp modify the implementation of above two methods as-
Follow* Follow::create(Node followedNode, const Rect& rect/ = Rect::ZERO*/,float offsetX,float offsetY)
Follow *follow = new (std::nothrow) Follow();
if (follow && follow->initWithTarget(followedNode, rect,offsetX,offsetY))
bool Follow::initWithTarget(Node followedNode, const Rect& rect/ = Rect::ZERO*/,float offsetX,float offsetY)
Size winSize = Director::getInstance()->getWinSize();
_halfScreenSize = _fullScreenSize * 0.5f;
I’ve indicated the lines to be added or changed to the existing follow action code in the above implementations in bold.I’ve not included the complete implementation for simplicity.
I feel this feature can be added in future cocos 2dx releases.
Cocos 2dx developers what do you think about this approach?