生活随笔
收集整理的這篇文章主要介紹了
cocos2d 环绕已知点移动一圈
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
| 答案1: 問題解決? 將step改為如下即可 -(void)step:(ccTime)dt { ????if (rotate == 360) { ????????rotate = 0; ????} ????rotate += 5; ????float fradian = rotate * PI / 180; ????NSLog(@"%f??%f",rotate,fradian); ????id ac0 = [CCMoveTo actionWithDuration:0.01? ???????????????????????????????? position:*****(centerx + radius * sinf(fradian), ??????????????????????????????????????????????centery + radius * cosf(fradian))]; ????id ac1 = [CCRotateTo actionWithDuration:0.01 angle:(int)(rotate)]; ????[sparrowhead runAction:[CCSpawn actions:ac0,ac1,nil]]; } 答案2: 根據算法,寫成一個cocos2d的action
| ? /** Round circle a CCNode object clockwise a number of degrees by modiying it's rotation attribute.*/@interface CCRoundBy : CCActionInterval <NSCopying>{????BOOL turn;// Forward or Reverse round????float startAngle;// default????float radius;// Round circle radius????CGPoint center;// Round circle center point}/** creates the action */+(id) actionWithDuration:(ccTime)duration turn:(BOOL)a center:(CGPoint)point radius:(float)r;/** initializes the action */-(id) initWithDuration:(ccTime)duration turn:(BOOL)a center:(CGPoint)point radius:(float)r;@end |
| ? //// CCRoundBy//#pragma mark -#pragma mark CCRoundBy?@implementation CCRoundBy+(id) actionWithDuration: (ccTime) t turn:(BOOL) a center:(CGPoint)point radius:(float)r{????????return [[[self alloc] initWithDuration:t turn:a center:point radius:r] autorelease];}?-(id) initWithDuration: (ccTime) t turn:(BOOL) a center:(CGPoint)point radius:(float)r{????if( (self=[super initWithDuration: t]) ) {????????turn = a;????????radius = r;????????center = point;????}????return self;}?-(id) copyWithZone: (NSZone*) zone{????CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] turn: turn center:center radius:radius];????return copy;}?-(void) startWithTarget:(id)aTarget{????[super startWithTarget:aTarget];????startAngle = [target_ rotation];????if (turn) {????????((CCNode *)target_).position = *****Add(center, *****(-radius, 0));????}????else {????????((CCNode *)target_).position = *****Add(center, *****(radius, 0));????}????}?-(void) update: (ccTime) t{????????// XXX: shall I add % 360????float rotate =??(startAngle + 360.0f * t );????if (turn) {????????rotate *= -1;????}????[target_ setRotation:rotate];????????float fradian = rotate * M_PI / 180.0f;????CGPoint pos = *****(center.x + radius * sinf(fradian),??????????????????????center.y + radius * cosf(fradian));????[target_ setPosition: pos];}?-(CCActionInterval*) reverse{????????BOOL result = !turn;????return [[self class] actionWithDuration:duration_ turn:result center:center radius:radius];}?@end |
? |
?
類別:Uitouch||添加到搜藏?|分享到i貼吧|瀏覽(346)|評論?(0) 最近讀者:
轉載于:https://www.cnblogs.com/wujian1360/archive/2012/03/10/2389613.html
總結
以上是生活随笔為你收集整理的cocos2d 环绕已知点移动一圈的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。