我刚刚开始研究SmallBASIC,我想我可以通过使用一个可变的变量来制作一个简单的播放器控制器,这个变量决定了对象在图形窗口中的像素量。这就是我所做的:
tutle = 300
GraphicsWindow.BrushColor = "Green"
GraphicsWindow.FillEllipse(tutle, 300, 55, 65)
If GraphicsWindow.LastKey = "A" Then
tutle = tutle + 5
EndIf 我听说Last Key是你按下或释放的最后一个键,但这似乎不起作用。我确定我把KeyDown搞错了。我能做些什么来修复它?
发布于 2016-04-18 04:23:21
Zock,你这样做,你将继续画椭圆,所以你的椭圆将会重现你创建的其他椭圆。我已经用这个形状做了多个游戏。U使用形状而不是图形窗口。它更快,更整洁,更容易理解。
发布于 2016-04-17 23:32:48
您的代码只运行一次。您需要经常检查是否有击键。不止一次。
tutle = 300
GraphicsWindow.BrushColor = "Green"
While 1 = 1 '< Every time the code gets to the EndWhile, it goes strait back up to the While statement.
Program.Delay(10)'<Small delay to make it easier on the PC, and to make the shape move a reasonable speed.
If GraphicsWindow.LastKey = "A" Then
tutle = tutle + 5
EndIf
GraphicsWindow.FillEllipse(tutle, 300, 55, 65)
EndWhile发布于 2016-04-23 02:09:00
在使用LastKey时,还有另一个需要牢记的问题。它返回最后一个键,即使该键是在五个小时前按下的。一旦你按下"A“键,循环就会一直记录按下的键,直到另一个键被按下。那么该键将一直持续到第三个键被按下。
要获得单次按键,请按住它,直到松开它,然后在该点停止,您需要跟踪按键事件。
GraphicsWindow.Show()
circ = Shapes.AddEllipse(10,10)
x = GraphicsWindow.Width / 2
y = GraphicsWindow.Height / 2
GraphicsWindow.KeyDown = onKeyDown
GraphicsWindow.KeyUp = onKeyUp
pressed = "False"
While "True"
If pressed Then
If GraphicsWindow.LastKey = "Up" then
y = y - 1
endif
EndIf
Shapes.Move(circ,x,y)
Program.Delay(20)
EndWhile
Sub onKeyDown
pressed = "True"
EndSub
Sub onKeyUp
pressed = "False"
EndSubhttps://stackoverflow.com/questions/36663998
复制相似问题