So in my little side-scroller Java game I’m attempting to make collisions for my character against walls. I am using keybindings instead of key listeners because of the focusing issues it often caused. Here’s the code I’m having trouble with:
Action moveleft = new AbstractAction(){
public void actionPerformed(ActionEvent e)
{
if (moving==true&&offsetX!=2){
offsetX=offsetX+2;
}
}
};
The problem is that when a key is held down to make the character move, in the actionperformed method, it doesn’t recheck the conditional statement that determines whether moving is true or false when the key is held down. This results in the character moving indefinitely through all walls until the key is released.
So why is this? What can I do to remedy it? If any more code is required from my program I can provide! Thanks!