2017-02-20 9 views
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 

私は形状がジッタそれらなしで独立した方向に移動させるために行うには何が必要ですか?

答えて

0

もう1つのことは、毎秒フレームを行うことです。すべてのオブジェクトが数学をしてそれを更新するようにしてください。のようにすべての数学が完了した後に実行されます。通常60フレーム/秒ですので、1フレームあたりの秒数は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 
+0

を行う必要はありませんそのように、私はあなたが何をすべきか、より良いと思う作品毎秒のフレームにかかわらずベロシティを同じに保つには、毎秒のフレームに基づいてベロシティを編集するだけです。したがって、フレームにかかわらず毎秒5ピクセルの動きが常に必要であると言うと、5 /フレームとそれは1秒あたりに移動するピクセルの量です。したがって、1秒間に10フレームの場合は、フレームごとに0.5ピクセルを移動し、合計秒間に5ピクセルを加算します。 :-Dこれが役立つことを願っています。 – Matthew

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」変数が毎回シェイプに再割り当てされ、ジッタが発生するということです。

+0

、あなたはまた、メインループであれば一部を行っている可能性が、それはあなたがしたい場合は、if文を毎回 – Matthew

関連する問題