Moving sprite with keyboard slight problem
i got an image and i can move it with my keyboard (left/up/down/right)
when i LONGPRESS an arrow key like how you usually do this -> wwwwwwwwwwwwwwwwwww,
it does move 1 pixel away, then stops for a second or so, then continues moving.
what i want is it keeps moving on :/
please help!
if my explanation is smoggy, try to type a letter with just a single press and you will see it stops and types again... >.<
Re: Moving sprite with keyboard slight problem
I see the problem.
So you need to translate this wwwwwwwwwwwwwwwwwww (resembling directional input) which is a series of key presses (caused by a long press, yes, but it is what it is), into an on and off.
What have you tried?
Some way to make it go when the button is pressed down, and only stop when the button is released.
Re: Moving sprite with keyboard slight problem
in a keylistener i did this
Code :
public void KeyPressed(KeyEvent ke){
if(ke.getKeyCode()==KeyEvent.VK_LEFT){
direction[3] = 1;
}
/*
same with other 3 keys
*/
}
public void KeyReleased(KeyEvent ke){
if(ke.getKeyCode()==KeyEvent.VK_LEFT){
direction[3] = 0;
}
/*
same with other 3 keys
*/
}
in a timer with actionlistener i have this
Code :
lbl_map.setLocation(lbl_map.getX()+direction[0]-direction[2], lbl_map.getY()+direction[1]-direction[3]);
:/
Re: Moving sprite with keyboard slight problem
Post a SSCCE, I do not see why that does what you describe.