game-physics - 夹具形状尺寸不遵循精灵的
问题描述
我注意到当精灵变高时,夹具形状尺寸会适当增加。相反,当尝试按比例缩小精灵时,夹具形状尺寸会卡在原始精灵尺寸上。
非常感谢您的提示、帮助和支持。为了显示这个故障,下面是 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 原始尺寸时保持不变。
它真的看起来像物理引擎中的一个错误......
感谢您的意见。
干杯
西尔万
解决方案
从函数名称中可能不明显,但每次physics_fixture_set_circle_shape
调用都会在您的夹具中添加另一个圆圈 - 如果您想更改,您需要重新创建它(通过删除 viaphysics_fixture_delete
然后像现有代码一样创建一个新的)几何学。
推荐阅读
- python - 针对 Python 不记名令牌写入访问问题的 ADAL
- python - 凯撒密码将每个字母移动不同的值?
- database - 如何绘制这个数据库模型?
- python - 如何将单独的应用程序合并到一个网页中?
- sql-server - 保留 kronos 导出的前导零
- java - 如何为两个 Android 应用程序制作一个后端和数据库
- laravel - 使用 bootstrap class="custom-select" 多重选择不起作用
- python - 在 Altair (Python) 中标记分层图表
- r - 如何根据R中的列名绘制一行
- javascript - 如何选择一个随机变量,然后从变量列表中选择一个随机变量?