【问题标题】:fixture shape dimensions do not follow the sprite ones夹具形状尺寸不遵循精灵的
【发布时间】:2021-03-24 08:25:49
【问题描述】:

我注意到当精灵变高时,夹具形状尺寸会适当增加。 相反,当尝试缩小精灵时,夹具形状尺寸会卡在原始精灵尺寸上。

非常感谢您的提示、帮助和支持。 为了显示这个故障,下面是 GML sn-ps:

在“创建”事件处理程序中:

// which controller
controllerID = 0;

// Configure the fixture
fix = physics_fixture_create();
physics_fixture_set_circle_shape(fix,  sprite_width / 2);
physics_fixture_set_density(fix, .01);
physics_fixture_set_restitution(fix, 1.);
physics_fixture_set_friction(fix, 0.5);

//Bind the fixture to the current instance
//my_fix = physics_fixture_bind(fix, object_index);
my_fix = physics_fixture_bind(fix, id);

在“开始步骤”事件处理程序中:

var aButton = gamepad_button_check_pressed(controllerID, gp_face1 );
if ( aButton != 0)
{
    image_xscale =     image_xscale*.9;
    image_yscale =     image_xscale;

    physics_remove_fixture(id, my_fix);

    // Configure the fixture
    physics_fixture_set_circle_shape(fix,  sprite_width / 2);

    //Bind the fixture to the current instance
    my_fix = physics_fixture_bind(fix, id);
}

var bButton = gamepad_button_check_pressed(controllerID, gp_face2 );
if ( bButton != 0)
{
    image_xscale =     image_xscale*1.1;
    image_yscale =     image_xscale;

    physics_remove_fixture(id, my_fix);

    // Configure the fixture
    physics_fixture_set_circle_shape(fix,  sprite_width / 2);

    //Bind the fixture to the current instance
    my_fix = physics_fixture_bind(fix, id);
}

当精灵收缩时,很容易检查夹具形状尺寸是否遵循精灵尺寸:只需将physics_world_draw_debug(phy_debug_render_shapes)放入“绘图事件”处理程序中。 我们可以看到,fixture 的形状尺寸随着 sprite 的扩展而增长,但当 sprite 尺寸回到 sprite 原始尺寸时保持不变。

它看起来真的像物理引擎中的一个错误......

感谢您的 cmets。

干杯

西尔万

【问题讨论】:

    标签: game-physics game-maker


    【解决方案1】:

    最后,我从论坛和 YoyoGame 编辑器客户支持中得到了答案。 这里是论坛的链接: https://forum.yoyogames.com/index.php?threads/collision-bounding-box-doesnt-scale-with-image.23941/

    这里是客户服务的答案: 感谢您报告此问题,但这不是错误或我们需要解决的问题,因为您已在该对象上启用了使用物理选项,因此会使用其中的设置创建夹具。您应该在使用自己的灯具时取消选择该选项 通过 UI 创建的夹具并不是主要的,而是附加的。我能够简单地取消激活项目中对象上的 Uses Physics 复选框,并且缩放对象正常工作。这可以通过使用physics_draw_debug()在绘制事件中绘制物理调试信息来确认;在抽奖活动中。 启用 Uses Physics EN后,外圈是 UI 添加的夹具:

    使用 Uses Physics DIS启用,仅通过代码添加的夹具对应一个圆圈:

    【讨论】:

      【解决方案2】:

      从函数名称中可能不明显,但每个physics_fixture_set_circle_shape 调用都会为您的夹具添加另一个圆圈 - 您需要重新创建它(通过删除 physics_fixture_delete 然后创建一个新的你现有的代码)如果你想改变几何。

      【讨论】:

      • 感谢您的回答。我终于找到了问题的根源,请参阅下面的回答。
      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多