【发布时间】:2015-02-13 16:08:03
【问题描述】:
我在渲染使用 Box2D Editor 创建的 json 对象时遇到问题。 我的问题是即使物体隔垫(根据网上找到的教程正确),在舞台上也看不到。
private void createBottle() {
// 0. Create a loader for the file saved from the editor.
BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("ball.json"));
// 1. Create a BodyDef, as usual.
BodyDef bd = new BodyDef();
bd.position.set(spaceShip.getX(), spaceShip.getY());
bd.type = BodyDef.BodyType.DynamicBody;
// 2. Create a FixtureDef, as usual.
FixtureDef fd = new FixtureDef();
fd.density = 1;
fd.friction = 0.5f;
fd.restitution = 0.3f;
// 3. Create a Body, as usual.
bottleModel = world.createBody(bd);
// 4. Create the body fixture automatically by using the loader.
loader.attachFixture(bottleModel, "test01", fd, 8);
}
在创建方法中我有这个:
createBottle();
在渲染方法中:
Vector2 bottlePos = bottleModel.getPosition().sub(bottleModelOrigin);
bottleSprite.setPosition(bottlePos.x, bottlePos.y);
bottleSprite.setOrigin(bottleModelOrigin.x, bottleModelOrigin.y);
bottleSprite.setRotation(bottleModel.getAngle() * MathUtils.radiansToDegrees);
bottleSprite.draw(batch);
我不明白为什么没有添加它,我在屏幕上看不到....我有其他项目分配了 z 位置...但是什么都不想出现。
我的目标是进入box2d编辑器制作的迷宫,并会移动到一个带有虚拟摇杆的指挥物体,这就是我正在做的游戏......
如果有人想告诉我如何成功导入,那是你第一次使用带有 import json 的外部编辑器。
编辑
在将我的问题发布到 . 但是错误出现在 Vector2 上……。教程也很清楚,但不起作用……即使在网上,我也看到了他们说不起作用的其他示例……没有资源运行?我还没找到
【问题讨论】:
标签: java json libgdx box2d physics-engine