Skip to content

Behaviors

miguel edited this page Jul 9, 2018 · 3 revisions

Behavior is fundamental to make things happen in your game. braingdx provides an easy way to implement behaviors for game objects:

// MyBehavior.java
public class MyBehavior implements Behavior {

   @Override
   public void onAttach(GameObject object) {
      // do something when this behavior gets attached
   }

   @Override
   public void onDetach(GameObject object) {
      // do something when object gets removed
   }

   @Override
   public void update(GameObject object, float delta) {
      // Update the game object here
   }

   @Override
   public void update(GameObject object, GameObject other, float delta) {
      // Compare this object to another one, collision detection, AI etc.
   }
}

/* ... */

// in your AbstractScreen implementation
BehaviorManager behaviorManager = context.getBehaviorManager();
GameObject object = context.getGameWorld().addObject();
behaviorManager.apply(object, new MyBehavior());

protip: extend your behavior from BehaviorAdapter<GameObject> to optionally override methods.

List of available behaviors

braingdx implements already some behaviors which can be used:

Clone this wiki locally