简体   繁体   English

访问box2d实体

[英]accessing box2d bodies

Since now, I've been accessing box2d bodies (to change or to get their values) with this for loop copied from the web: 从现在开始,我一直使用从网上复制的for循环来访问box2d主体(以更改或获取其值):

for (var b = world.GetBodyList(); b != null; b = b.GetNext())

works fine but... Is there any other faster way to do so? 工作正常,但是...还有其他更快的方法吗? Can't I just store a reference to the bodies in an array so then have always access to it? 我是否可以仅将对实体的引用存储在数组中,以便始终可以访问它?

Thanks! 谢谢!

I don't know which version of Box2DJs you're using but you can do something like this: 我不知道您使用的是哪个版本的Box2DJ,但是您可以执行以下操作:

var myBodies = [];
var myBox = new b2BoxDef(); // or whatever the name of your body creation function is
myBodies.push(myBox);
console.log(myBodies[0]); // reference to your Box2D object

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

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