Key Binding issues in game
I have some code that should do key binding if it's written correctly, and everything compiles just fine, but now I can't move in my game again, and I don't know what's wrong..
Here's some code from my Player class:
Code:
public void moveRight(ActionEvent e)
{
movex=1;
mcounter = 1;
SIDE = 1;
}
public void moveLeft(ActionEvent e)
{
movex=-1;
mcounter = -1;
SIDE = 0;
}
public void moveUp(ActionEvent e)
{
movey = 20;
}
public void moveDown(ActionEvent e)
{
standingUp = false;
}
and some from my Inner class:
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
public class Inner extends JPanel implements ActionListener
{
public Player playuh;
public InputMap inputmap;
public ActionMap actionmap;
Action moveright = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
playuh.moveRight(e);
}
};
Action moveleft = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
playuh.moveLeft(e);
}
};
Action moveup = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
playuh.moveUp(e);
}
};
Action movedown = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
playuh.moveDown(e);
}
};
Inner()
{
super();
setBackground(Color.BLACK);
setFocusable(true);
addMouseListener(new RAdapter());
playuh = new Player();
setDoubleBuffered(true);
setSize(600,465);
inputmap = getInputMap(WHEN_IN_FOCUSED_WINDOW);
inputmap.put(KeyStroke.getKeyStroke("d"), "one");
inputmap.put(KeyStroke.getKeyStroke("a"), "two");
inputmap.put(KeyStroke.getKeyStroke("w"), "three");
inputmap.put(KeyStroke.getKeyStroke("s"), "four");
actionmap = getActionMap();
actionmap.put("one", moveright);
actionmap.put("two", moveleft);
actionmap.put("three", moveup);
actionmap.put("four", movedown);
}