我已經創建了一個body,並且我創建了兩個獨立的燈具,一個燈具創建一個矩形形狀,另一個燈具創建一個圓形。但是,當我使用.createfixture將圓放在矩形的中心時,我想要矩形頂部的圓像火柴一樣。在libgdx中,你如何在矩形上添加一個圓形?
這裏是我的代碼不知道該怎麼辦...
rectangleBodyDef = new BodyDef();
rectangleBodyDef.type = BodyType.DynamicBody;
rectangleBodyDef.position.set(10,20);
rectangleBody = world.createBody(rectangleBodyDef);
rectangleBodyShape = new PolygonShape();
rectangleBodyShape.setAsBox(2f, 0.75f);
rectangleBodyFixtureDef = new FixtureDef();
rectangleBodyFixtureDef.shape = rectangleBodyShape;
rectangleBodyFixtureDef.restitution = 0.8f;
rectangleBody.createFixture(rectangleBodyFixtureDef);
/**********************CREATING THE SECOND BODY (CIRCLE BODY) ************/
circleShape = new CircleShape();
circleShape.setRadius(0.75f);
circleFixtureDef = new FixtureDef();
circleFixtureDef.shape = circleShape;
circleFixtureDef.restitution = 0.8f;
rectangleBody.createFixture(circleFixtureDef);
你是怎麼設置的這個位置有fixtureDef是可能的,你能告訴我一行代碼,請這樣做 – user3197976
我推薦使用Google搜索「Box2D創建夾具」並進行嘗試。 –
我到處搜索了這就是爲什麼我要求在論壇上,我已經做了一個嘗試,如上面的代碼中所示,你說你可以用fixturedef設置位置,但這是可能的,因爲我已經嘗試過,它只是顯示爲錯誤在日食。 – user3197976