Cocos2d、Box2D 静止直到输入

发布于 2025-01-02 06:14:21 字数 731 浏览 0 评论 0原文

大家好,我有一个问题,如何创建一个在按下它之前不会具有物理功能的身体?我的 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:)];

球会在游戏开始时从屏幕边缘掉落,但这不是我想要的。我希望它保持在同一位置,直到我按下它。无论如何,我可以保留该对象,直到我给出一些输入吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦开始←不甜 2025-01-09 06:14:21

还没有尝试过,但切换 setActive 属性似乎很完美。

tailBody->setActive(NO);

在此处查看“激活”部分:http://www.box2d.org/manual.html# _Toc258082973

Haven't tried it but toggling the setActive property seems perfect.

tailBody->setActive(NO);

Check out the 'activation' section here: http://www.box2d.org/manual.html#_Toc258082973

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文