在使用SpaceManager时,如何使sprite在cocos2D中旋转 [英] How do you make a sprite rotate in cocos2D while using SpaceManager

查看:146
本文介绍了在使用SpaceManager时,如何使sprite在cocos2D中旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是有一个简单的sprite - 我怎么能让它旋转?

I just have a simple sprite - how can I get it to rotate?

一个好的答案会显示如何旋转动态sprite和static_mass sprite

A good answer would show how to rotate both a dynamic sprite and a static_mass sprite

推荐答案

如果Sprite是动态/非静态的,只需这样做:

If the sprite is dynamic / non-static, just do like so:

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

对于静态主体,您可以这样做:

For a static body, you can do something like this:

[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); 



免责声明:我想回答自己的问题,这个答案可能缺少重要的细节 - 它只是代表我知道,到目前为止。

Disclaimer: I'm trying to answer my own question, and this answer might be missing important subtleties - it just represents what I know, so far.

这篇关于在使用SpaceManager时,如何使sprite在cocos2D中旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆