4. เลือกปฏิบัติ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 4-9  ตัวอย่างการใช้ตัวดำเนินการตรรกะในการทดสอบการชนผนังวินโดว์
if ((x-r) <= 0) {   
  dx = -dx;
}
if ((x+r)>=w.getWidth()) {   
  dx = -dx;
}
if ((y-r) <= 0) {   
  dy = -dy;
}
if ((y+r)>=w.getHeight()){   
  dy = -dy;
}

if ((x-r)<=0 || (x+r)>=w.getWidth()) { dx = -dx; } if ((y-r)<=0 || (y+r)>=w.getHeight()) { dy = -dy; }
©2009 S.Prasitjutrakul