我正在尝试编写一个显示加速轮的代码。只要用户按下“a”,车轮就会逆时针加速。问题是它转向正确的方向,但它没有加速。这是我正在使用的代码(在 PTB-3 和 Windows XP 中):
img=imread('c:\images.jpg');
[yimg,ximg,z]=size(img);
rot_spd = 1;
larrow = KbName('a'); % modify this for Windows
rarrow = KbName('b');
[w,rect]=Screen('OpenWindow',0,[0 0 0]);
sx = 400; % desired x-size of image (pixels)
sy = yimg*sx/ximg; % desired y-size--keep proportional
t = Screen('MakeTexture',w,img);
bdown=0;
th = 0; % initial rotation angle (degrees)
HideCursor
while(~any(bdown)) % exit loop if mouse button is pressed
[x,y,bdown]=GetMouse;
[keyisdown,secs,keycode] = KbCheck;
if(keycode(larrow))
th = th - rot_spd-1; % accelerate counterclockwise
th
end
if(keycode(rarrow))
th = th + rot_spd+1; % accelerate clockwise
th
end
destrect=[x-sx/2,y-sy/2,x+sx/2,y+sy/2];
Screen('DrawTexture',w,t,[],destrect,th);
Screen('Flip',w);
end
Screen('Close',w)
ShowCursor
如果有人知道它为什么不加速,我会非常感激。