Keyboard Input

edited July 2015 in Questions about Code

Hello, I am making a small game just for practice, and I noticed that while testing the game, the keyboard controls are very unresponsive. often if I switch from 1 key to another the character will stop dead for a little while before it starts moving in the new direction. I was just wondering if anyone had any advice for this? this is the portion where all the relevant commands are being handled.

`class person{ float x, y, speedX, speedY;

person(float _x, float _y){ x = _x; y = _y; }

void graphics(){ stroke(0); fill(255, 0, 0); ellipse(x, y, 50, 50); fill(0); ellipse(x + 17, y - 10, 10, 10); ellipse(x + 5, y - 10, 10, 10); ellipse(x+15, y + 5, 15, 5); }

void move(){ speedX = 5; speedY = 5; if ((keyPressed == true) && (key == 'w')){ y = y - speedY; }

if ((keyPressed == true) && (key == 's')){
y = y + speedY;
}

if((keyPressed == true) && (key == 'a')){
 x = x - speedX; 
}

if((keyPressed == true) && (key == 'd')){
  x = x + speedX;
}

}

void boundary(){ if (x > 600 || x < 0){ speedX = 0; }

else{ speedX = 5; }

if (y > 400 || y < 0){ speedY = 0; }

else{ speedY = 5; } }

}`

Sign In or Register to comment.