SmallBASIC播放器控制器

时间:2016-04-16 12:09:24

标签: controller smallbasic

我刚刚开始研究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 个答案:

答案 0 :(得分:1)

Zock你这样做,你将继续绘制椭圆,这样你的椭圆将是你创建的椭圆形的剩余部分。我用形状制作了多个游戏。你使用的形状不是图形窗口。它更快,更清洁,更容易理解。

答案 1 :(得分: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

答案 2 :(得分:0)

使用LastKey时要记住另一个问题。即使五小时前按下该键,它也会返回最后一个键。一旦按下你的&#34; A&#34;按键,循环将继续注册按键,直到按下不同的键。然后该键将持续到按下第三个键。

要按一下键,按住它直到它被释放,然后停止,你需要跟踪关键事件。

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

答案 3 :(得分:-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

希望有所帮助。

相关问题