Description of the problem:
Hi there, I have encountered a simple question but cannot find out what’s wrong.
I want to use the keyboard to adjust both position(using “w” “s” “a” “d”) and orientation(using"left" “right”) of the stimulus (a bar).
The orientation of the bar could follow my keyboard input precisely, but the position couldn’t. For instance, If I press the key “a”, the bar won’t move. While if I press the key “left” next, the bar’s orientation will change, of course, it’s position will change as well (because the key “a” has been pressed before).
It seems that the position of the bar is not updating every frame, while the orientation is updating?
Here is my JS code, I inserted this piece into the “stimulus presenting each frame” routine.
var thisResp
if (bar.status === PsychoJS.Status.STARTED){
thisResp = psychoJS.eventManager.getKeys();
// adjust orientation
if ("left" == thisResp[0]) {
bar.ori += 4;
}
if ("right" == thisResp[0]) {
bar.ori -= 4;
}
// adjust position
if ("a" == thisResp[0]) {
bar.pos[0] -= 1;
}
if ("d" == thisResp[0]) {
bar.pos[0] += 1;
}
if ("w" == thisResp[0]) {
bar.pos[1] += 1;
}
if ("s" == thisResp[0]) {
bar.pos[1] -= 1;
}
}
Thank you very much!!