2013年3月15日 星期五

<分享>How to use timer component into C# script

目標 : Using timer component into C# script.

檔案 : https://dl.dropbox.com/u/29860061/bounce%20point.gh


流程步驟 :

1.在全域區塊(global variable)中設定需要被內部區塊改變的變數。

2.創建初始點,我們即將改變點的x,y座標。

Point3d myPoint = new Point3d(xx, yy, 0);

3.隨著timer 的計數器增加,點座標的x,y值會依據使用者設定的speedx/speedy 增加。

xx += speedx;
yy += speedy;



4.設定彈跳範圍,如果彈跳超出範圍則程式需要改變speedx/speedy 的方向。
if(xx > boundX )
if(xx < 0 )
if(yy > boundy )
if(yy < 0 )


5.清除紀錄,如果使用者重新執行bounce point,請程式清除上一次的點座標,並使x,y座標返回預設值。

   ListPts.Clear();
   xx = yy = 0;



Main Code:


if(start){

      Point3d myPoint = new Point3d(xx, yy, 0);
      ListPts.Add(myPoint);

      xx += speedx;
      yy += speedy;

      if(xx > boundX ){
        xx = boundX;
        speedx *= -1;
      }

      if(xx < 0 ){
        xx = 0;
        speedx *= -1;
      }

      if(yy > boundy ){
        yy = boundy;
        speedy *= -1;
      }

      if(yy < 0 ){
        yy = 0;
        speedy *= -1;
      }

    }else{
      ListPts.Clear();
      xx = yy = 0;
    }

    A = ListPts;

影片:


結果圖片:


GH C# Definition

timer count A

timer count B

timer count C

沒有留言:

張貼留言