android - box2d (andengine gles2) PhysicsConnector 语法错误

标签 android box2d andengine physics

我已经在我的动态圆体球上施加了重力。当它到达屏幕底部时,它会离开屏幕。我想为我的物理世界划定界限。

我分别创建了 4 条线和 4 个线体。但是当我尝试注册物理连接器时,它适用于我的盒子体和 Sprite 但不适用于我的线体:(

代码:

Line line_top = new Line(0, 0, CAMERA_WIDTH, 0, this.getVertexBufferObjectManager());
    Line line_left = new Line(0, 0, 0, CAMERA_HEIGHT, this.getVertexBufferObjectManager());
    Line line_right = new Line(CAMERA_WIDTH, 0, CAMERA_WIDTH, CAMERA_HEIGHT, this.getVertexBufferObjectManager());
    Line line_bottom = new Line(0, CAMERA_HEIGHT, CAMERA_WIDTH, CAMERA_HEIGHT, this.getVertexBufferObjectManager());
    line_top.setColor(1, 1, 1); // RGB
    line_left.setColor(1, 1, 1);
    line_right.setColor(1, 1, 1);
    line_bottom.setColor(1, 1, 1);

    Body wall_top = PhysicsFactory.createLineBody(mPhysicsWorld, line_top, FIXTURE_DEF);
    Body wall_left = PhysicsFactory.createLineBody(mPhysicsWorld, line_left, FIXTURE_DEF);
    Body wall_right = PhysicsFactory.createLineBody(mPhysicsWorld, line_right, FIXTURE_DEF);
    Body wall_bottom = PhysicsFactory.createLineBody(mPhysicsWorld, line_bottom, FIXTURE_DEF);

这对我来说很好

mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(playButtonSprite, BoxBody2, true, true));

但是当我将我的行作为参数传递时

mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(line_top, BoxBody, true, true));

它显示了这个错误

The constructor PhysicsConnector(Line, Body, boolean, boolean) is undefined

最佳答案

我的游戏中有类似的东西(屏幕边界作为物理对象)。显然,我也遇到了这个问题,PhysicsConnector 不接受 Line - 所以我改用了 Rectangle。您可以创建一个宽度为 1 的矩形,例如,与 line_top 等效的矩形将是:

Rectangle rect_top = new Rectangle(0, 0, CAMERA_WIDTH, 1);

关于android - box2d (andengine gles2) PhysicsConnector 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13762943/

相关文章:

java - Android 自动授予权限

android - 在我的 android 项目中使用 android box 2d

javascript - 用于网络游戏的完全可复制的 Javascript Physic 2D 引擎

android - Sprite 移动速度在所有设备上都不是恒定的 - Andengine

java - 如何将arrayList的元素传递给可变参数函数

android - 我们可以在 sqlite 数据库中打开多少游标?

android - 可扩展 ListView 组中的 2 行

Android onConfigurationChanged : how to save and restore fragment back stack?

Box2d 将地面摩擦力设置为最大 - 无滑动

java - 我的 disposeSplashScene 中出现奇怪的警告