3

Linux (Ubuntu 12.04) 環境で Vala と GTK3 を学習しています。そのために、Game of Life シミュレーションを作成しました。ここまでは順調ですね。私がやりたいのは、各画面更新の間に遅延 (たとえば 2 秒) を挿入することです。私は Glib.TimeoutSource 関数を調査しましたが、私のニーズに対しては複雑すぎるようです。他のオプションはありますか?TimeoutSource が実際に進むべき道である場合、お勧めの例はありますか。ありがとうございました。

マイク

更新:とてつもなく簡単であることが判明しました...

public void onRunButtonClicked(Button source)
{
  Timeout.add_seconds(3, updateDraw);
}

private bool updateDraw()
{
  game.determineBirthsAndDeaths();
  game.applyBirthsAndDeaths();
  queue_draw();
  iterationsLabel.set_text("Iteration: %5d".printf(game.getIterationCount()));      
  return true;
}

最初のメソッドは、タイマーを設定します。2 番目のものは 3 秒ごとに実行されます (この例では)。次に、停止ボタンを追加し、停止ボタンが押されたときに updateDraw メソッドが false を返すようにする必要があります。詳細...

4

1 に答える 1

0
public void onRunButtonClicked(Button source)
{
  Timeout.add_seconds(3, updateDraw);
}

private bool updateDraw()
{
  game.determineBirthsAndDeaths();
  game.applyBirthsAndDeaths();
  queue_draw();
  iterationsLabel.set_text("Iteration: %5d".printf(game.getIterationCount()));      
  return true;
}
于 2013-11-26T18:54:12.343 に答える