1

単純なスプライトがあります-どうすれば回転させることができますか?

良い答えは、動的スプライトとstatic_massスプライトの両方を回転させる方法を示します

4

2 に答える 2

1

スプライトが動的/非静的である場合は、次のようにします。

 cpBodySetAngVel(ObjSmSprite.shape->body,0.25); 

静的なボディの場合、次のようなことができます。

[ObjSmStaticSprite.shape runAction:[CCRepeatForever actionWithAction:
                         [CCSequence actions:
                          [CCRotateTo actionWithDuration:2 angle:180],
                          [CCRotateTo actionWithDuration:2 angle:360],
                          nil]

                         ]];


smgr.rehashStaticEveryStep = YES; //Setting this would make the smgr recalculate all static shapes positions every step

要約すると、ここに回転する静的スプライトがあり、次に回転する動的スプライトがあります。

  // Add Backboard
    cpShape *shapeRect = [smgr addRectAt:cpvWinCenter mass:STATIC_MASS width:200 height:10 rotation:0.0f ];// We're upgrading this 
  cpCCSprite * cccrsRect = [cpCCSprite spriteWithShape:shapeRect file:@"rect_200x10.png"];
    [self addChild:cccrsRect];

  // Make static object update moves in chipmunk
  // Since Backboard is static, and since we're going to move it, it needs to know about spacemanager so its position gets updated inside chipmunk.
  // Setting this would make the smgr recalculate all static shapes positions every step
//  cccrsRect.integrationDt = smgr.constantDt;
//  cccrsRect.spaceManager = smgr;
  // Alternative method: smgr.rehashStaticEveryStep = YES;
  smgr.rehashStaticEveryStep = YES;

  // Spin the backboard
  [cccrsRect runAction:[CCRepeatForever actionWithAction:
                         [CCSequence actions:
                          [CCRotateTo actionWithDuration:2 angle:180],
                          [CCRotateTo actionWithDuration:2 angle:360],
                          nil]

                         ]];


  // Add the hoop
  cpShape *shapeHoop = [smgr addCircleAt:ccp(winSize.width/2.0f,winSize.height/2.0f - 55.0f) mass:1.0 radius: 50 ];
  cpCCSprite * cccrsHoop = [cpCCSprite spriteWithShape:shapeHoop file:@"hoop_100x100.png"];
    [self addChild:cccrsHoop];
  cpBodySetAngVel(cccrsHoop.shape->body,0.25); 

免責事項:私は自分の質問に答えようとしていますが、この答えには重要な微妙な点が欠けている可能性があります。これは、これまでのところ私が知っていることを表しているにすぎません。

于 2010-04-22T14:17:41.763 に答える
1

cocos2dを使用している場合

このコードをチェックマークで使用して、常に位置を更新します。_number1.positionは更新する位置であるため、_number1が移動すると、_logo2は回転してそれに向かいます_logo2.rotation = CC_RADIANS_TO_DEGREES(-ccpToAngle(ccpSub(_number1.position、_logo2.position) ));

タッチで_logo1ローテーションを更新し、このコードをタッチイベントハンドラーに配置します

_logo2.rotation = CC_RADIANS_TO_DEGREES(-ccpToAngle(ccpSub(location, _logo2.position)));

これをアクションとして使用する

[_logo2 runAction:[CCRotateTo actionWithDuration:0.0 angle:CC_RADIANS_TO_DEGREES(-ccpToAngle(ccpSub(location, _logo2.position)))]];

これが誰かが私にそれを解決するのに何年もかかったのを助けることを願っています

于 2011-03-04T17:48:54.550 に答える