0

这是完整的代码:

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

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

4

2 回答 2

0

我放:

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

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

于 2017-02-21T23:00:35.247 回答
0

您可以做的另一件事是每秒处理帧数。让所有的对象做数学然后更新它。这是在完成所有数学运算后运行的,因此通常每秒 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
于 2017-02-22T02:50:25.173 回答