CCScaleTo causes CCSprite to move, apart from scaling it

I am pretty new to Cocos2d and I am trying to implement scaling a sprite up and down. I am using CCEaseInOut to perform the task. My code snippet looks as follows:

barrel setAnchorPoint:ccp(0.5,0.5)];
id scaleUpAction =  [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:.35 scaleX:1.5 scaleY:1.5] rate:1.0];
id scaleDownAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:.35 scaleX:1.0 scaleY:1.0] rate:1.0];
CCSequence *scaleSeq = [CCSequence actions:scaleUpAction, scaleDownAction, nil];
[barrel runAction:scaleSeq];

barrel is of type CCNode.

I have tried to set the anchorPoint to (0.5,0.5) considering the scaling might be happening around the centre. But, that doesn't seem to help.

I have seen a similar question: CCSprite is moved when using CCScaleTo or CCScaleBy. Unfortunately, there is no answer in that link that solves the problem.

It would be great if someone could point me in the right direction.

Note: It might be useful to mention that the barrel object is being used as a box2d object. Could the problem be arising from there? Cheers!

Note: I have following already in my code:

NSObject* bodyUserDataA = (__bridge NSObject*)contact->GetFixtureA()->GetBody()->GetUserData(); if ([bodyUserDataA isKindOfClass:[ODPPBarrel class]]) { barrel = (ODPPBarrel *)bodyUserDataA; }

Answers


Always try NOT to change the anchorpoints of a node unless it is a must requirement. By default the anchorpoint for all nodes are set to 0.5 only.

id scaleUpAction =  [CCScaleTo actionWithDuration:.35 scale:1.5];
id scaleDownAction = [CCScaleTo actionWithDuration:.35 scale:1.0];
CCSequence *scaleSeq = [CCSequence actions:scaleUpAction, scaleDownAction, nil];

Now if barrel is of type CCSprite and used in b2Body's userdata field then: get the body (e.g. myBody) from the box2d world.

CCSPrite *tmpSPrite = (CCSPrite *)myBody->getUserData;
if(tmpSprite)
  [tmpSPrite runAction:scaleSeq];

Need Your Help