如何使形状独立移动而不会抖动?

How do I make shapes move independently without jitter?

完整代码如下:

GraphicsWindow.Clear()
GraphicsWindow.CanResize = "false"
GraphicsWindow.Height = Desktop.Height-200
GraphicsWindow.Width = Desktop.Width-200

scount = Math.GetRandomNumber(25)
For s = 1 To scount
  Shx[s] = Math.GetRandomNumber(GraphicsWindow.Width-100)
  Shy[s] = Math.GetRandomNumber(GraphicsWindow.Height-100)
  shsize[s] = Math.GetRandomNumber(50)
  Sh[s] = Shapes.AddEllipse(shsize[s],shsize[s])
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor

loop:
For s = 1 to scount
  op[s] = Math.GetRandomNumber(2)
  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf
  Shx[s] = Shx[s] + vel[s]
  Shy[s] = Shy[s] + vel[s]  
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor
Goto loop

我猜问题出在这里:

op[s] = Math.GetRandomNumber(2)
  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf

我需要怎么做才能让形状在独立的方向上移动而不抖动?

我输入:

op[s] = Math.GetRandomNumber(2)
 If op[s] = 1 Then
vel[s] = .5
 EndIf
If op[s] = 2 Then
 vel[s] = -.5
EndIf

在初始化循环中,形状不再抖动。我的猜测是 "vel" 变量每次都被重新分配给形状,导致抖动。

您可以做的另一件事是每秒处理帧数。让所有对象进行数学计算然后更新它。 tHis 是 运行 在完成所有数学运算之后就像 通常它每秒 60 帧,所以 1/60 得到每帧的秒数。您还需要一个计时器来检查流逝的时间,这样您就可以给计算机时间在适当的时间移动每个形状。如果您需要更多代码,我很乐意提供。

  GraphicsWindow.Clear()
GraphicsWindow.CanResize = "false"
GraphicsWindow.Height = Desktop.Height-200
GraphicsWindow.Width = Desktop.Width-200

scount = Math.GetRandomNumber(25)
For s = 1 To scount
  Shx[s] = Math.GetRandomNumber(GraphicsWindow.Width-100)
  Shy[s] = Math.GetRandomNumber(GraphicsWindow.Height-100)
  shsize[s] = Math.GetRandomNumber(50)
  Sh[s] = Shapes.AddEllipse(shsize[s],shsize[s])
  Shapes.Move(Sh[s],Shx[s],Shy[s])
   op[s] = Math.GetRandomNumber(2)
EndFor

loop:
Time = Clock.ElapsedMilliseconds
For s = 1 to scount

  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf
  Shx[s] = Shx[s] + vel[s]
  Shy[s] = Shy[s] + vel[s]  
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor
frames()
Goto loop

Sub frames
     timeend = Clock.ElapsedMilliseconds
  TextWindow.WriteLine((timeend - Time )/1000)
  framelength = 60
  Timeperframe = 1/framelength
  while (((timeend - Time )/1000) <  Timeperframe)
    timeend = Clock.ElapsedMilliseconds

  EndWhile
  Time = Clock.ElapsedMilliseconds

  endsub