2017-01-08 28 views
0

我一直在尝试模拟在Small Basic中跳跃,我原本虽然很简单但比我预期的更复杂。每当我尝试在for循环中使用动画(或移动)时,程序似乎总是将我在开始时分配的任何延迟放在一起,然后是单个动画/移动。例如:如何在Small Basic中堆叠动画

GraphicsWindow.Height = 480 
GraphicsWindow.Width = 640 

pX = 300 
pY = 220 

GraphicsWindow.KeyDown = KeyPressed 

player = Shapes.AddEllipse(40, 40) 
Shapes.Move(player, 300, 220) 

Sub KeyPressed 
    If GraphicsWindow.LastKey = "Space" Then 
    For i = 1 To 10 
     pY = pY - (10 - i) 
     Shapes.Move(player, pX, pY) 
     Program.Delay(100) 
    EndFor 
    EndIf 
EndSub 

我希望这个计划,以增加圆为什么一定的下降速度位置,而是等待1秒(在循环毫秒的总数),然后在向上移动的整个方式一旦。我怎样才能达到我想要的并解决这个问题?

+0

的原因是,它等待整个子执行然后对其进行更新。你想要的是sub有一个单一的语句,并在调用子程序的for循环中有数学运算。 – Matthew

回答

0

原因是因为,它等待整个子执行然后它更新它。你想要的是sub有一个单一的语句,并在调用子程序的for循环中有数学运算。

0

+马修有正当理由。 Small Basic中的线程有点怪异且不可预知,并且是的......带有移动命令的线程在按键事件完成之后才会看到移动请求。

这里是你的代码的版本放入主线程的举动:

GraphicsWindow.Height = 480 
GraphicsWindow.Width = 640 

pX = 300 
pY = 220 

GraphicsWindow.KeyDown = KeyPressed 

player = Shapes.AddEllipse(40, 40) 
Shapes.Move(player, 300, 220) 

top: 
If moving = "true" then 
    For i = 1 To 10 
    pY = pY - (10 - i) 
    Shapes.Move(player, pX, pY) 
    Program.Delay(100) 
    EndFor 
    moving = "false" 
endif 
Goto top 

Sub KeyPressed 
    If GraphicsWindow.LastKey = "Space" Then 
    moving = "true" 
    EndIf 
EndSub