-
Notifications
You must be signed in to change notification settings - Fork 1
Behaviors
☕️ Miguel edited this page Nov 17, 2016
·
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 = getBehaviorManager();
GameObject object = getGameWorld().addObject();
behaviorManager.apply(object, new MyBehavior());
protip: extend your behavior from
BehaviorAdapter<GameObject>
to optionally override methods.
braingdx implements already some behaviors which can be used:
- RandomMovementBehavior moves the object randomly in the world. The velocity and random factor can be configured.
-
PointLightBehavior creates a
PointLight
and attaches it to a givenGameObject
.