如何手动改变物体的特性?
我有一些正在成长的身体。我把这个身体添加到了世界上。
...
someBody = world->CreateBody(&bodyDef);
someFixture = tapBody->CreateFixture(&someFixtureDef);
...
我想我不需要在这里粘贴所有代码。
所以我给世界添加了身体。问题是如何改变已经在世界上的身体的位置、恢复原状?我可以在这里这样做吗? (因为当我尝试更改 tick
方法中的某些内容时出现错误)。
-(void) tick: (ccTime) dt
{
world->Step(dt, velocityIterations, positionIterations);
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
}
}
I have some body which grows. I added this body to the world.
...
someBody = world->CreateBody(&bodyDef);
someFixture = tapBody->CreateFixture(&someFixtureDef);
...
I think I do not need to paste all code here.
So I added body to the world. The question is how to change position, restitution... of the body which is already in the world? Am I allowed to do that here? (because I am getting errors when I try to change something in the tick
method).
-(void) tick: (ccTime) dt
{
world->Step(dt, velocityIterations, positionIterations);
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您可以通过破坏并创建一个新的固定装置来完成您所需要的,而不是破坏和重新创建整个身体...
对于任何错字抱歉...还没有测试过任何这些...
Maybe instead of destroying and recreating the entire body you could accomplish what you need by destroying and creating a new fixture...
Sorry for any typos... haven't tested any of this...
首先,在勾选方法中,确保您正在设置速度和位置迭代,然后查看所有改变它们的物体:
查看 box2d 文档中移动 box2d 物体的方法,例如 ->ApplyLinearImpuse ->ApplyForce ...如果您想显式设置位置和角度,请查看 ->SetTransform()
我希望这会有所帮助!
塔姆斯
First in the tick method make sure that you are setting the velocity and position iterations and then look through all of the bodies altering them:
Look at the methods in box2d documentation to move a box2d body, for example->ApplyLinearImpuse ->ApplyForce...If you want to explicitly set the position and angle, then look at ->SetTransform()
I hope this helps!
Tams