CCRotateTo and CCRotateBy differnce
//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 code prod开发者_如何学Cuce same results...I need to know the difference between using rotateTo and rotateBy... please advise...
CCRotateTo rotates the object to the specified angle, while CCRotateBy rotates the object to its current angle + the specified angle. They would be equivalent if your object's initial rotation is 0. However, if its initial angle was 90, CCRotateTo would rotate it towards angle 45, while CCRotateBy would rotate it towards angle 135.
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 the CCRotateBy action you never need to think about any angles...
精彩评论