Animated Model Problem

well, i think, this is a very fundamental question of java, but, i cannt figure out the solution. :frowning:

I have two animated models, that has been registered like this,

[java] XControl = node_rabbit.getControl(AnimControl.class);


XChannel = XControl.XChannel();

XChannel.setAnim("standing"); [/java]


[java] YControl = node_turtle.getControl(AnimControl.class);


YChannel = YControl.YChannel();

YChannel.setAnim("standing"); [/java]

But, I have only one onAnimCycleDone & onAnimChange method, if i use this line,

[java]public class Main extends SimpleApplication implements AnimEventListener[/java]

I know cannt use this line and I have to implement these two methods independently, for per model.But the problem is I dont know how to do it. :frowning:

Making SimpleApplication implement AnimEventListener is just a convenient way of demonstrating for the test cases, and should never really be used in an actual game.

You can create your own classes for each Listener : class XAnimListener implements AnimEventListener and class YAnimListener implements AnimEventListener.

Each one of them will have the onAnimCycleDone and onAnimChange methods.

You’ll probably have to pass somes attributes to the constructor though.

then in your code you just have to use them like this :

YControl = node_turtle.getControl(AnimControl.class);

YControl.addListener(new YAnimListener());

YChannel = YControl.YChannel();


Or, you can make inner classes

YControl.addListener(new AnimEventListener() {

public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName) {

//your code


public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {

//your code



This way is convenient, but don’t really recommend it for an actual game, it can make classes become a mess to maintain, and classes are fragmented anyway at compilation.

But it works.

1 Like

Thanks, its working :slight_smile: