Skip to content

Character Interaction Animations

Benjamin Israel edited this page Oct 20, 2021 · 1 revision

How to change animations for the character based on interactions:

The players movement animations are controlled in the KeyboardPlayerInputComponent. Here the events for each direction are thrown. If you want to change the output of pressing a key during the main game it should be handled here. Currently local private variables are used to specify the animations that are the be played. For instance private boolean buffed is used to control if buffed animations are played. This is toggled by setBuffed() and can be called from any where using service locator. Provided your animations are named correctly all you need to do to add a new interaction is:

  1. Add a new local boolean to track it.
  2. Add setters for the bool value
  3. Then add your animation name to setAnimation() as a switch.

Provided your animations all begin with the appropriate direction they only need your interaction key at the end. For instance "walking_northeas_[your animation key]". Please also note you need to turn off your animation in another class using service locator and your setter methods. This is an exclusive set up so only one interaction animation can play at once. It will be the first one listed in setAnimation() if more than one is specified.

Why use KeyboardPlayerInputComponent?

This is where the input is handled, it allows a direct method of dealing with input with less calls to outside classes. It allows you to track how each key press is effecting animations and prevents double up calls to the animation event handler. Given the current low number of interactions handled by this class it has a low complexity. If however this expands these controls should be refactored into another class in this package and handled there. This would be a simple expansion given these methods are mostly self contained.

Clone this wiki locally