Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. CCSpriteSheet *sheet = (CCSpriteSheet*) [self getChildByTag:kTagSpriteSheet];
  2. CCSprite *pigeonSprite = [CCSprite spriteWithSpriteSheet:sheet rect:CGRectMake(0,0,40,32)];
  3. [sheet addChild:pigeonSprite z:0 tag:kPigeonSprite];
  4.  
  5. pigeonSprite.position = ccp( p.x, p.y);
  6.  
  7. bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
  8. bodyDef.userData = sprite;
  9. b2Body *body = world->CreateBody(&bodyDef);
  10.  
  11. b2CircleShape dynamicCircle;
  12. dynamicCircle.m_radius = .25f;
  13. dynamicCircle.m_p.Set(0.0f, 1.0f);
  14.  
  15. // Define the dynamic body fixture.
  16. b2FixtureDef circleDef;
  17. circleDef.shape = &dynamicCircle;
  18. circleDef.density = 1.0f;
  19. circleDef.friction = 0.3f;
  20.  
  21. body->CreateFixture(&circleDef);
  22.  
  23. b2Vec2 vertices[3];
  24. vertices[0].Set(-0.5f, 0.0f);
  25. vertices[1].Set(0.5f, 0.0f);
  26. vertices[2].Set(0.0f, 1.0f);
  27. b2PolygonShape triangle;
  28. triangle.Set(vertices, 3);
  29.  
  30. b2FixtureDef triangleDef1;
  31. triangleDef1.shape = ▵
  32. triangleDef1.density = 1.0f;
  33. triangleDef1.friction = 0.3f;
  34.  
  35. body->CreateFixture(&triangleDef1);
  36.  
  37. // To be called each time physics should be updated.
  38. void physicsStep(float32 timeStep, int32 velocityIterations, int32 positionIterations) {
  39. // This is the usual update routine.
  40. world.Step(timeStep, velocityIterations, positionIterations);
  41. world.ClearForces();
  42.  
  43. // SpriteClass can be replaced with any class you favor.
  44. // Assume there is a known pointer to the b2Body. Otherwise you'll have to get that,
  45. // or iterate over all bodies in the world.
  46. SpriteClass *sprite = (SpriteClass*)body->GetUserData();
  47.  
  48. // Once you have the pointer you can transfer all the data.
  49. sprite.position = body->GetPosition();
  50. sprite.angle = body->GetAngle();
  51. // ... and so on
  52. }
  53.  
  54. sprite = static_cast<CCSprite*>body->GetUserData();
  55. sprite->setPosition(vec2(body->GetPosition().x*PTM_RATIO, body->GetPosition().y*PTM_RATIO));
  56. sprite->setRotation(-CC_Radian_to_Degree(body->GetAngle));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement