libGDX:挂绳 [英] libGDX: Hanging Rope
问题描述
我是新到Android libGDX游戏引擎和搜索形式多天做出挂绳,
I am new to android libGDX game engine and searching form many days to make a hanging rope,
我也读了所有的Box2D的文档,有一种方法的 ropJoint 但考虑使用它没有足够的解释。
I also read out all the Box2D documentation, There is a method ropJoint but no enough explanation given to use it.
任何机构可以帮我做这样一个绳子。 在Box2D的挂绳
Can any body help me to make a rope like this one. Hanging Rope in Box2d
我也试图寻找一些好的libGDX本书为Android,但无法找到。
I also tried to search for some good libGDX book for android but couldn't find.
需要你的帮助,请你的青睐。
your help is required, please do the favor.
推荐答案
只要创建一个循环某些矩形体(setAsBox在Box2D的),并与旋转接头相互连接(循环之前和循环调用初始化里面做一个RevoluteJointDef(。 ))。
Just create some rectangle bodies (setAsBox in box2d) in a loop and connect each other with revolute joints (Make a RevoluteJointDef before loop and inside loop call initialize(..)).
这是我的code:
RevoluteJointDef jd = new RevoluteJointDef();
Body prevBody = startBody;
for(int i=0; i<ringCount; i++)
{
BodyDef bd = new BodyDef();
bd.type = BodyType.DynamicBody;
bd.angle = angle-MathUtils.PI/2;
bd.position.set(position.x + i*MathUtils.cos(angle)*EACH_RING_DISTANCE,
position.y + i*MathUtils.sin(angle)*EACH_RING_DISTANCE);
Body body = world.createBody(bd);
body.createFixture(eachRingFD);
Vector2 anchor = new Vector2(bd.position.x - MathUtils.cos(angle)*EACH_RING_DISTANCE/2f,
bd.position.y - MathUtils.sin(angle)*EACH_RING_DISTANCE/2f);
jd.initialize(prevBody, body, anchor);
prevBody = body;
}
//connect a hanging shape to rope here if exists
这篇关于libGDX:挂绳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!