Animation : ActionScript Lab Solutions

Starting code : thecar_finish.fla ๑ เปลี่ยนการเคลื่อนไหวเป็นวิถึโค้งแบบแอร์มีต แก้ไขใน moveBezier
var x = (2*t*t*t-3*t*t+1) * cp[0]._x + (-2*t*t*t+3*t*t) * cp[3]._x + (t*t*t-2*t*t+t) * (cp[1]._x-cp[0]._x)*a + (t*t*t-t*t) * (cp[3]._x-cp[2]._x)*a; var y = (2*t*t*t-3*t*t+1) * cp[0]._y + (-2*t*t*t+3*t*t) * cp[3]._y + (t*t*t-2*t*t+t) * (cp[1]._y-cp[0]._y)*a + (t*t*t-t*t) * (cp[3]._y-cp[2]._y)*a;
โดยที่ a เป็นค่าคงที่ค่าหนึ่ง เป็นขนาดของเวกเตอร์ (ให้เป็น 1 ก็ได้) ๒ ปรับโค้ดให้มีการเคลื่อนที่ไปกลับตามโค้ง พหุนามบี โดยแต่ละรอบเพิ่มความเร็วขึ้น สองเท่า หากไปจากซ้ายไปขวา และ ลดลงหนึ่งส่วนสามหากเคลื่อนขวาไปซ้าย ข้อนี้ยังตีโจทย์ไม่แตก แต่ขอเอาโค้ดโมโม่มาใช้ ซึ่งไม่น่าจะผิด :P แก้ไข moveCar เฉพาะส่วน case 2
case 2: ncp = Array(t4_mc,t3_mc,t2_mc,t1_mc); if (t*3 < 1) { return moveBSpline(cp,t*3); } else if (cp[0]._x+4*cp[1]._x+cp[2]._x > cp[1]._x+4*cp[2]._x+cp[3]._x) { if (t*3 < 1.5) return moveBSpline(ncp,2*(t*3-1)); else return moveBSpline(cp,2/3*(t*3-1.5)); } else { if (t*3 < 2.5) return moveBSpline(ncp,2/3*(t*3-1)); else return moveBSpline(cp,2*(t*3-2.5)); } break;
๓ ปรับโค้ดกำหนดรถไว้ที่คอนโทรลพ้อยน์ทุกอัน และเคลื่อนไหวตามกันเป็นแถวขบวน ข้อนี้ถึกที่สุด อธิบายคร่าวๆ ไปลองยำเอาเอง 1.ก๊อปรถเพิ่มมาอีกสามคัน ตั้งชื่อว่า thecar_mc2 3 และ 4 2.สร้างจุดไว้ลากเส้นได้อย่างถูกต้อง var p1=Array(t1_mc._x,t1_mc._y); ทำของ 2 3 4 ด้วย 3.สร้าง controlpt 2 3 4 โดยสลับค่าใน array เช่น controlpt2 = Array(t2_mc,t3_mc,t4_mc,t1_mc); 4.เพิ่ม pos,pos2 ของคันที่ 2 3 4 (อย่าลืมเปลี่ยน controlpt) 5.เปลี่ยนสี่บรรทัดนี้
_root.lineTo(pos.x,pos.y); this.thecar_mc._x = pos.x; this.thecar_mc._y = pos.y; this.thecar_mc._rotation = vectorToDegree(pos,pos2); เป็น if(time>0.01){ this.moveTo(p1.x,p1.y); _root.lineTo(pos.x,pos.y); this.thecar_mc._x = pos.x; this.thecar_mc._y = pos.y; this.thecar_mc._rotation = vectorToDegree(pos,pos2); ...(อีกสามคันที่เหลือ) } p1.x=pos.x; (คันที่ 2 3 4 ด้วย) p1.y=pos.y; (คันที่ 2 3 4 ด้วย)
ซ้อมทำก่อนเข้าสอบด้วยนะพวกเธอว์ *Flash CS3 Portable : http://www.4shared.com/file/31584562/2842c746/Adobe_Flash_CS3_Portable.html?s=1