简体   繁体   English

Cocos2d,Box2D静止物体直到输入

[英]Cocos2d, Box2D Still body till input

Hey guys i have a question here, How do i create a body that will not have physic function until i press it? 嘿,我在这里有一个问题,我如何创建一个在按下之前不具有物理功能的身体? i have this code in my init 我在初始化中有此代码

CCSprite *tail = [CCSprite spriteWithFile:@"Ball.jpg"];
[self addChild:tail z:1];

b2BodyDef tailBodyDef;
tailBodyDef.type = b2_dynamicBody;
tailBodyDef.position.Set(100/PTM_RATIO, 100/PTM_RATIO);
tailBodyDef.userData = tail;
tailBody = world->CreateBody(&tailBodyDef);

b2CircleShape circle;
circle.m_radius = 26.0/PTM_RATIO;

b2FixtureDef tailShapeDef;
tailShapeDef.shape = &circle;
tailShapeDef.density = 1.0f;
tailShapeDef.friction = 0.2f;
tailShapeDef.restitution = 0.8f;
tailBody->CreateFixture(&tailShapeDef);

[self schedule: @selector(tick:)];

The ball will drop off the the edge of screen at the start of game, but thats not what i want. 游戏开始时,球将掉落在屏幕边缘,但这不是我想要的。 i want it to stay at the same position until i press it. 我希望它保持在相同的位置,直到我按它为止。 is there anyway i could hold the object back until i give some input? 无论如何,我可以保留对象,直到我提供一些输入?

Haven't tried it but toggling the setActive property seems perfect. 还没有尝试过,但是切换setActive属性似乎很完美。

tailBody->setActive(NO);

Check out the 'activation' section here: http://www.box2d.org/manual.html#_Toc258082973 在此处查看“激活”部分: http : //www.box2d.org/manual.html#_Toc258082973

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM