Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ccScaleBy and ccScaleTo in cocos2d?

I am scaling my sprite object in cocos2d using the CCScaleTo method. It is not perfect scaling so I use this code:

id action1=[CCScaleTo actionWithDuration:0.5 scale:1.25];
id action2=[CCScaleBy actionWithDuration:0.5 scale:.25];
id action3=[CCScaleTo actionWithDuration:0.5 scale:1.25];
id action4=[CCScaleTo actionWithDuration:0.5 scale:.25];

[timeUpImg runAction:[CCSequence actions:action1,action2,action3,action4,nil]];

This is working perfectly.

I don't know the difference between ccScaleBy and CCScaleTo and also how to use the "reverse" method. Can someone explain it please?

like image 574
banu Avatar asked Aug 09 '11 04:08

banu


1 Answers

CCScaleTo scales the node/sprite to an absolute scale factor while CCScaleBy scales it by a factor relative to current scale.

For example, suppose a node currently has scale 0.25:

  • [CCScaleTo actionWithDuration:0.5 scale:2.0] will modify the scale to 2.0 (simply ignores the current scale)

  • [CCScaleBy actionWithDuration:0.5 scale:2.0] will modify the scale to 0.5 (0.25 * 2.0)

On the second question, the reverse method returns an instance of CCAction subclass that gives the reverse effect of the original action. For example: [[CCScaleBy actionWithDuration:0.5 scale:2.0] reverse] will return [CCScaleBy actionWithDuration:0.5 scale:0.5], and [[CCScaleBy actionWithDuration:0.5 scale:4.0] reverse] will return [CCScaleBy actionWithDuration:0.5 scale:0.25]

like image 106
Lukman Avatar answered Sep 27 '22 20:09

Lukman