Movement problem
in
Programming Questions
•
5 months ago
When I move an object using the arrow keys it lags for a bit some times, e.g. if the object was moving left for a few sec and I click down arrow key, it will move the dirrectionOffset in a downard position once (move down by 3 px in this case), then lag for a while and then continue moving down ( 3px each time).
Any idea what could be causing this ?
void move() {
if (keyPressed==true) {
if (key==CODED) {
if (keyCode==UP) {
dy = -directionOffset;
}
else if (keyCode==DOWN) {
dy = directionOffset;
}
else if (keyCode==LEFT) {
dx = -directionOffset;
}
else if (keyCode==RIGHT) {
dx = directionOffset;
}
}
}
x = x + dx;
dx = 0;
y = y + dy;
dy = 0;
}
1