vba - imple game lags when i release a key and quickly press another key -
i wanted make classic brick game in visual basic. while coding movement of rectangle hits ball, got problem. rectangle lags when releasing key. when press a, release , simulteneously press d, recatangle hangs moment , goes right.
here part of program.
private sub timer1_tick(byval sender system.object, byval e system.eventargs) handles timer1.tick if rectangleleft = true , rectangleshape1.left >= me.clientrectangle.left + 2 rectangleshape1.left -= 2 end if if rectangleright = true , rectangleshape1.right <= me.clientrectangle.right - 2 rectangleshape1.left += 2 end if end sub private sub form1_keydown(byval sender system.object, byval e system.windows.forms.keyeventargs) handles mybase.keydown if e.keycode = keys.a rectangleright = false rectangleleft = true end if if e.keycode = keys.d rectangleleft = false rectangleright = true end if end sub private sub form1_keyup(byval sender system.object, byval e system.windows.forms.keyeventargs) handles mybase.keyup rectangleleft = false rectangleright = false end sub
end class strong text
the lag caused repeat delay bios/windows feature; controlled via control panel. need use timer check status of desired key position , process movement when key in depressed position.
use win32 api method in timer loop: public declare function getkeypress lib "user32" alias "getasynckeystate" (byval key integer) integer
dim integer = getkeypress(keys.a)
i 0 when not pressed , -32768 when pressed
Comments
Post a Comment