首页 > 解决方案 > 夹具形状尺寸不遵循精灵的

问题描述

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

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

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

// 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 原始尺寸时保持不变。

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

感谢您的意见。

干杯

西尔万

标签: game-physicsgame-maker

解决方案


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


推荐阅读