【问题标题】:How can I access the physics fixtures in Game Maker in order to draw them?如何访问 Game Maker 中的物理装置以绘制它们?
【发布时间】:2016-11-29 21:08:11
【问题描述】:

我是 Game Maker 的新手。我创建了一个基于物理的小游戏的机制,并使用了 YoYo Games 教程中概述的方法来创建复杂的物理对象 (http://www.yoyogames.com/blog/70)。为了快速上手,我使用了physics_world_draw_debug 来绘制我的对象 (http://www.yoyogames.com/blog/71),我认为切换到“真实”的多边形绘制会很容易(就像 Game Maker 中的几乎所有其他东西一样)。

我的代码看起来有点像这样(从教程中复制):

var fixture = physics_fixture_create();
physics_fixture_set_polygon_shape(fixture);

// four points, making up a convex shape
physics_fixture_add_point(fixture, x0, y0);
physics_fixture_add_point(fixture, x1, y1);
physics_fixture_add_point(fixture, x2, y2);
physics_fixture_add_point(fixture, x3, y3);

physics_fixture_set_density(fixture, 0.8);
physics_fixture_set_restitution(fixture, 0.1);
physics_fixture_set_linear_damping(fixture, 0.5);
physics_fixture_set_angular_damping(fixture, 0.5);
physics_fixture_set_friction(fixture, 0.5);
physics_fixture_bind(fixture, id);
physics_fixture_delete(fixture);

此代码针对每个对象运行多次,具有不同的 x 和 y 值。

但我找不到一种方法来查询其装置当前状态的物理对象。我可能可以为每个对象保存组成我的固定装置的所有点的坐标的副本,但是我也必须做所有的数学运算,旋转它们并平移它们。基本上和physics_world_draw_debug做同样的工作。

有没有更简单的方法来绘制由多个夹具组成的物理对象?通过获取当前坐标或调用一些内置的 draw_fixture_with_color 函数或类似的方法?

【问题讨论】:

    标签: game-physics game-maker


    【解决方案1】:

    我在 YoYoGames 论坛上交叉发布了这个问题,得到了以下两个答案:

    1) flyingsaucerinvasion:

    尝试其他功能,physics_draw_debug,或使用“d3d_transform 旋转和平移”。

    完整答案在这里:https://forum.yoyogames.com/index.php?threads/how-can-i-access-the-physics-fixtures-in-order-to-draw-them.3399/#post-25899

    2) Yal:

    使用精灵表示的简单对象,并通过关节将它们连接在一起。

    完整答案在这里:https://forum.yoyogames.com/index.php?threads/how-can-i-access-the-physics-fixtures-in-order-to-draw-them.3399/#post-28429

    【讨论】:

      猜你喜欢
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      相关资源
      最近更新 更多