日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

cocos2d 环绕已知点移动一圈

發布時間:2024/4/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 环绕已知点移动一圈的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。