这是完整的代码:
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
我需要做些什么才能使形状在不抖动的情况下向独立方向移动?
您可以做的另一件事是每秒帧。让所有对象进行数学,然后更新它。在所有数学完成之后,这是运行的通常,它的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
我放置:
op[s] = Math.GetRandomNumber(2)
If op[s] = 1 Then
vel[s] = .5
EndIf
If op[s] = 2 Then
vel[s] = -.5
EndIf
在初始化循环中,形状不再抖动了。我的猜测是," vel"变量每次都会重新分配到形状,导致抖动。