我只有一个简单的精灵 - 我怎样才能让它旋转?
一个好的答案将显示如何旋转动态精灵和 static_mass 精灵
如果精灵是动态/非静态的,就这样做:
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);
免责声明:我正在尝试回答我自己的问题,而这个答案可能缺少重要的细节——它只代表了我到目前为止所知道的。
如果使用 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)))]];
希望这可以帮助有人花了我很长时间才解决这个问题