I loaded a TriMesh array with all move of my character
follow de code:
morph[0] - walk
morph[1] - walk
morph[2] - walk
morph[3] - running
morph[4] - running
morph[5] - running
how can I do to press a key, like 'w' for instance, and the character change walk move to run move?
I need to change the move of my character in the main class? How I do that?
my code:
public class MorphPersonagens{
public TriMesh morph[] = new TriMesh[6];
public TriMesh aux = new TriMesh();
public KeyframeController kc = new KeyframeController();
public FileInputStream leJME[] = new FileInputStream[6];
public FileInputStream leJMEAux;
public Node recebeJME[] = new Node[6];
public float f = -0.3f;
public int posInicial = 0;
public int posFinal = 6;
public MorphPersonagens(){}
public TriMesh[] personagem(){
KeyframeController kc = new KeyframeController();
try{
for (int i = posInicial; i < posFinal; i++){
leJME[i] = new FileInputStream("c:/projeto/personagens/lyan/obj/lyan"+i+".jme");
}
//FileInputStream para carregar o JME base
leJMEAux = new FileInputStream("c:/projeto/personagens/lyan/obj/lyan1.jme");
//Usa o metodo loadBinaryFormat para carregar os arquivos .JME dentro do Node
JmeBinaryReader carregaJME = new JmeBinaryReader();
try{
// Node base para o TriMesh
Node recebeAux = (Node)carregaJME.loadBinaryFormat(leJMEAux);
// "FOR" para colocar os .JME dentro da Node
for (int i = 0; i < 6; i++){
recebeJME[i] = (Node)carregaJME.loadBinaryFormat(leJME[i]);
}
for(int i = 0; i < 3; i++){
morph[i] = (TriMesh)recebeJME[i].getChild(0);
// indica a velocidade da morfagem
}
Take a look at the source code for SimpleGame. It registers keys for the camera and other things. That should explain pretty well how to use the built-in keyboard and mouse events in jME.
Refer to SimpleGame as an example. Take a look at the references to KeyBindingManager in initSystem(). Also, I assume you already realize this, but if you don't, you should not use SimpleGame for anything but initial testing. Your actual game should be an extension of BaseGame or AbstractGame. SimpleGame is just a class that allows you have basic controls to fly around and look at the scene, not intended to be the basis for building a game.
I do understand, but if you reference the SimpleGame to figure out how it does key binding you can use that to write your own key binding that does your animation instead of moving forward. I'm assuming you already know how to change the animation sequence, you just need to figure out a way to trigger it on a keypress…that's what I'm pointing you to.
I think his question is more along the lines of how to start and stop an animation controller. You refer to Morph alot, do you have a controller already or have you simply loaded several models representing frames of animation and you want to know how to make them flow together as an animation?
When I press the key "w", for instance…I change the "posInicial" to 3 and "posFinal" to 6. Where the variables "posInicial" and "posFinal", corresponds to the array interval that contains the TriMeshs of the walking animation. I must send the "base" object that contains the new animation to "rootNode" in the main class…but I have a problem, when I do that (rootNode.setChild(0, base)), a "NullPointerExceptionn" occurs…Thats is my problem…