java – 多个夹具在一个身体或多个身体?
|
假设我想在屏幕上创建1000个或甚至5000个静态体线.我想知道的是,将所有这些线(灯具)附接到单个主体上,或将每个夹具放置在自己的身体上有什么区别.两种方法之间是否存在性能差异,还是一种方法提供更多的功能或控制其他方法? 下面显示了两种方法的区别. 将每条线连接到一个单一的身体上: // Create our body definition
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// Create a body from the defintion and add it to the world
Body groundBody = world.createBody(groundBodyDef);
for (int i = 0; i < 1000; i++) {
// Create our line
EdgeShape ground = new EdgeShape();
ground.set(x1,y1,x2,y2);
groundBody.createFixture(ground,0.0f);
ground.dispose();
}
将每条线连接到自己的身体: // Create our body definition
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
for (int i = 0; i < 1000; i++) {
// Create a body from the defintion and add it to the world
Body groundBody = world.createBody(groundBodyDef);
// Create our line
EdgeShape ground = new EdgeShape();
ground.set(x1,0.0f);
ground.dispose();
}
这个代码示例特别在libGDX中,但是我想象这是一个相当基本的box2D概念,即使没有libGDX体验也可以回答. 可能的功能差异的一个例子是,如果所有行都附加到单个主体,并且我们调用world.destroyBody(groundBody);它也会销毁所有行,但是如果每行都附加到不同的身体,我们只会破坏一条线. 即使这样做有很大的不同吗?我们可以简单地调用groundBody.destroyFixture(fixture);如果它们都连接到单个身体,则销毁一条线. 解决方法从 Box2D Manual(7.3车身厂):
这确实比较好.很明显吗取决于,如果你有很多身体与一个夹具,你使他们的一个单一的身体,但可能不是大多数游戏. 我会建议您使用更容易实现的功能,只有当您真正需要它时,才能使其更具性能. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
