Game Development Reference
In-Depth Information
4. In the same method, add this instance as AnimEventListener to AnimCon-
trol to receive events when animations change or cycle, as shown in the follow-
ing code:
animControl.addListener(this);
5. To be able to set specific animations from other classes, we add a method called
setAnimation , which takes an animation and Channel (enum) as the input,
as shown in the following code:
public void setAnimation(Animation animation, Channel
channel){
switch(channel){
case Upper:
setAnimation(animation, upperChannel);
break;
...
}
}
6. In the onAction method, the control can receive input directly from In-
putListener and apply the logic on its own before setting the animation, as
shown in the following code:
public void onAction(String name, boolean isPressed,
float tpf) {
if (name.equals("StrafeLeft")) {
leftStrafe = isPressed;
}
...
} else if (name.equals("Jump") && isPressed) {
jumpStarted = true;
setAnimation(Animation.JumpStart);
}
if(jumpStarted || firing){
// Do nothing
} else if(forward || backward || rightStrafe ||
leftStrafe) {
setAnimation(Animation.Walk);
} else {
Search WWH ::




Custom Search