CCRotateTo and CCRotateBy are different

//CCRotateBy id action=[CCRotateBy actionWithDuration:1.0 angle:45]; [player runAction:action]; //CCRotateTo id action=[CCRotateTo actionWithDuration:1.0 angle:45]; [player runAction:action]; 

the above two codes give the same results ... I need to know the difference between using rotateTo and rotateBy ... please advise ...

+4
source share
2 answers

CCRotateTo rotates the object by the specified angle, while CCRotateBy rotates the object by its current angle + given angle. They would be equivalent if the initial rotation of the object is 0. However, if its initial angle is 90, CCRotateTo will rotate it to angle 45, and CCRotateBy will rotate it to angle 135.

+14
source

CCRotateBy is also very handy when it comes to ever rotating sprites:

 CCSprite *halo = [CCSprite spriteWithFile:@"halo.png"]; [halo setOpacity:160]; CCRotateTo * rotRight = [CCRotateBy actionWithDuration:0.5 angle:40.0]; [halo runAction:[CCRepeatForever actionWithAction:rotRight]]; 

with CCRotateBy action, you never need to think about any angles ...

+2
source

Source: https://habr.com/ru/post/1343409/


All Articles