【问题标题】:box2d (andengine gles2) PhysicsConnector syntax errorbox2d (andengine gles2) PhysicsConnector 语法错误
【发布时间】:2012-12-07 12:16:55
【问题描述】:

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

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

代码:

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

【问题讨论】:

  • 尝试将线条类从 Line 更改为 Shape:Shape line_top = new Line(...);
  • 不起作用!它接受 IAreaShape 对象。 :(
  • 如果您的线路注册物理连接器不是:mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(line_top, wall_top, true, true)); (新物理连接器的第二个参数 - wall_top)?

标签: android box2d andengine physics


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    相关资源
    最近更新 更多