Results 1 to 3 of 3
Thread: Key Binding issues in game
- 01-17-2011, 12:13 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 57
- Rep Power
- 0
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:
Java 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:
Java 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); }
- 01-17-2011, 12:18 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 57
- Rep Power
- 0
Nevermind, I found out that the chars I was using were not the registered chars for W, A, S, D. I changed that and now my code works :D
-
Similar Threads
-
JSP and javascript binding???
By paulb in forum JavaServer Pages (JSP) and JSTLReplies: 5Last Post: 01-02-2011, 08:33 PM -
Help: Key Binding
By mine0926 in forum New To JavaReplies: 0Last Post: 08-06-2010, 04:52 AM -
dynamic binding
By apparao in forum New To JavaReplies: 1Last Post: 02-16-2010, 08:41 AM -
[SOLVED] Key binding Q
By playwin2 in forum New To JavaReplies: 3Last Post: 11-04-2008, 06:04 AM -
Spring binding in jsp
By Pierre Javason in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-05-2008, 12:21 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks