All Questions

Community

A
ThePirateKing
posted to: The action menu

UIActionMenu Positioning

After following the lesson, my action menu appeared in the top left of screen. I may have missed it, but I think the lesson is missing guidance on how to make sure the menu appears in front of the player's battler.

I looked at the final code, and I found that the UIActionMenu scene node has custom Margins, and Rect variables in the Inspector. So it seems the menu is manually placed.

Are there plans to implement a dynamic position for the menu? This could be useful for when there are multiple party members and the action menu needs to appear in front of specific battlers.

  • Nathan Lovato replied

    I'll address this with the next update. Thanks again for the continuous reports.

    Regarding a dynamic position, you could use the battlers' front anchor covered later in the course. You'd add this line:

    action_menu.rect_position =
      battler.battler_anim.get_front_anchor_global_position() -
      Vector2(action_menu.rect_size.x, action_menu.rect_size.y / 2)

    Here's the start of the _player_select_action_async() function

    func _player_select_action_async(battler: Battler) -> ActionData:
        var action_menu: UIActionMenu = UIActionMenuScene.instance()
        add_child(action_menu)
      action_menu.rect_position = battler.battler_anim.get_front_anchor_global_position() - \ Vector2(action_menu.rect_size.x, action_menu.rect_size.y / 2)