1

我刚开始研究 SmallBASIC,我想我可以通过使用一个可变变量来制作一个简单的播放器控制器,该变量确定对象在图形窗口中的像素数量。这就是我所做的:

tutle = 300

GraphicsWindow.BrushColor = "Green"
GraphicsWindow.FillEllipse(tutle, 300, 55, 65)

If GraphicsWindow.LastKey = "A" Then
  tutle = tutle + 5
  EndIf 

我听说 Last Key 是您按下或释放的最后一个键,但这似乎不起作用。我确定我把 KeyDown 弄错了。我能做些什么来修复它?

4

4 回答 4

1

Zock 你这样做了,你将继续绘制椭圆,这样你的椭圆将与你创建的其他椭圆重叠。我已经制作了多个带有形状的游戏。U 使用形状而不是图形窗口。它更快、更清晰、更容易理解。

于 2016-04-17T20:23:20.840 回答
0

使用 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"
EndSub
于 2016-04-22T18:09:00.413 回答
0

您的代码只运行一次。您需要不断检查击键。不止一次。

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-17T15:32:48.460 回答
-1

你会使用形状,而不是图形。图形绘制静态的“贴纸”。

    Turtle = Shapes.AddRectangle(100, 100)
GraphicsWindow.KeyDown = move
x =0
y = 0
Shapes.Move(Turtle, x, y)
Sub move
  key = GraphicsWindow.LastKey
  Text.ConvertToLowerCase(key)
  If key = "S" Then
    x = x
    y = y +1 ' values are reveresed for y.
    Shapes.Move(Turtle, x, y )
   EndIf 


  endsub

希望有帮助。

于 2016-04-16T21:30:02.737 回答