Difference Between CCMoveBy and CCMoveTo in Cocos2D-Android

Difference Between CCMoveTo.action(float f,  CGPoint pos) and CCMoveBy action(float f,  CGPoint pos)

Though the both methods take the similar parameter, but there is a little difference.

CCMoveBy moves a CCNode object to the position x, y. Here x and y are the absolute coordinate. That means, whatever the CCNode is positioned before, it will move the node in the (x, y) position that is passed by as a parameter.

Example-


CCSprite actionNode = CCSprite.sprite("cocos2d.png");

actionNode.setPosition(CGPoint.ccp(10, 10));

addChild(actionNode);

CCMoveTo action = CCMoveTo.action(2.5f, CGPoint.ccp(100, 100));

runAction(action);

The primary position of the actionNode is (10,1 0) . If MoveBy.action() method is performed, the next position of the actionNode will be (100,100) .

CCMoveTo moves a CCNode object to the relative positions. That means if the actionNode’s position is (0, 0) , it will add the (x, y) value given by the parameter with it.

Example-


CCSprite actionNode = CCSprite.sprite("cocos2d.png");

actionNode.setPosition(CGPoint.ccp(10, 10));

addChild(actionNode);

CCMoveTo action = CCMoveTo.action(2.5f, CGPoint.ccp(100, 100));

runAction(action);

The primary position of the actionNode is (10,1 0) . If MoveTo.action() method is performed, the next position of the actionNode will be (110,110) .

Advertisements

6 Comments

  1. This tutorial is completely wrong.

    CCMoveTo move the sprite to the coordinates you’ll pass in.

    CCMoveBy will move the sprite adding x,y to the actual position

    exactly the opposite of what you say.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s