#鼠标 #2d #bevy #gamedev #bevy-plugin

bevy_interact_2d

Bevy插件,用于2D鼠标交互

5个版本

0.9.0 2022年12月28日
0.5.3 2021年5月10日
0.5.2 2021年5月10日
0.5.1 2021年5月5日
0.5.0 2021年5月5日

#819 in 游戏开发

自定义许可证

29KB
318 代码行

Bevy Interact 2D

工作中

Bevy游戏引擎的插件库,用于轻松将鼠标交互添加到2D游戏。

可以帮助你

  • 悬停
  • 点击
  • 拖放

Progress bar example

使用Interact2D

添加交互插件,或者当调试时使用InteractionDebugPlugin

App::build()
  .add_plugin(InteractionPlugin)

创建一个具有多个交互组的交互源摄像头。

commands
  .spawn_bundle(OrthographicCameraBundle::new_2d())
  .insert(InteractionSource {
    groups: vec![Group(0), Group(1)],
    ..Default::default()
  })

创建一个交互实体

commands
  .spawn()
  .insert(Interactable {
    groups: vec![Group(0)],
    bounding_box: (Vec2::new(0., 0.), Vec2::new(10., 10.)),
    ..Default::default()
  })

现在你可以创建一个使用交互状态的系统

fn interaction_system(
  mouse_button_input: Res<Input<MouseButton>>,
  interaction_state: Res<InteractionState>,
) {
  if !mouse_button_input.just_released(MouseButton::Left) {
    return;
  }

  for (entity, coords) in interaction_state.get_group(Group(0)).iter() {
    // Do something
  }
}

依赖

~42–56MB
~811K SLoC