1

我正在使用 AndEngine/Box2D 在 Android 操作系统上开发游戏。当用户触摸屏幕时,它使用三角形示例创建一个三角形:

private static Body createTriangleBody(final PhysicsWorld pPhysicsWorld, final IAreaShape pAreaShape, final BodyType pBodyType, final FixtureDef pFixtureDef) {
    /* Remember that the vertices are relative to the center-coordinates of the Shape. */
    final float halfWidth = pAreaShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
    final float halfHeight = pAreaShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;

    final float top = -halfHeight;
    final float bottom = halfHeight;
    final float left = -halfHeight;
    final float centerX = 0;
    final float right = halfWidth;

    final Vector2[] vertices = {
            new Vector2(centerX, top),
            new Vector2(right, bottom),
            new Vector2(left, bottom)
    };

    return PhysicsFactory.createPolygonBody(pPhysicsWorld, pAreaShape, vertices, pBodyType, pFixtureDef);
}

但是,三角形附近的触摸没有记录(正如我使用 Log 发现的那样),这意味着您很快就会用可用的三角形填满屏幕。蓝色是三角形,红色是未注册触摸的位置:

在此处输入图像描述

任何想法为什么没有在这些范围内注册触摸?

这是另一个图表: 在此处输入图像描述

所以场景最终可能看起来像这样。当用户按住时,三角形的大小会增加。当用户抬起手指时,三角形停止增长并落到屏幕底部。尽管原始三角形的大小与红色三角形大致相同,但在标有“X”的区域中并未记录触摸。

4

1 回答 1

0

使用 OnAreaTouchListener 检测对象上的触摸,使用 OnSceneTouchListener 检测外部对象的触摸 - 这是您需要用于检测红色区域内的触摸的方法。

于 2012-07-30T12:16:16.510 回答