download font

ดาวน์โหลดฟอนต์ download font

download icon

ดาวน์โหลด ไอค่อน จากสะดุ้ง

download template

ดาวน์โหลด เทมเพลตเว็บต่างๆ

Download Vector

ดาวน์โหลดภาพเว็กเตอร์ จากสะดุ้ง

ของเสริม photoshop

brush style patterns

Home » เทคนิค flash cs

เทคนิคสร้าง flash ให้รูปเคลื่อนที่ตามเมาส์ ด้วย actioscript

Submitted by แมวสะดุ้ง on วันอังคาร, 5 สิงหาคม 20084 Comments


คำค้นหา: , , ,

วิธีการทำ flash cs actioscript วัตถุเคลื่อนตามเมาส์

มาดูวิธีการทำและตัวอย่างเลยดีกว่า

1. improt ไฟล์ gif ที่เราต้องการเข้ามา (file>import)

2.นำไฟล์ที่ต้องการใส่ในเลเยอร์1

flash script

3.กด F8 แล้วเลือก movieclip ตั้งชื่อ go_mc
4.ใส่ชื่อตรง instance name

flash script mouse

5. กด F9 แล้วนำ code ไปวาง กด ctrl+enter ดูผลคับ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//First an eventlistener to call the function to make the enemy move, this is an enterframe event.
go_mc.addEventListener(Event.ENTER_FRAME, do_stuff);
// the function
function do_stuff(event:Event):void {
 
// here we do some calculations to make the ememy rotate based on the mouse angle, centered to the go.
var myRadians:Number = Math.atan2(mouseY-go_mc.y, mouseX-go_mc.x);
var myDegrees:Number = Math.round((myRadians*180/Math.PI));
 
// this is the stuff making the go move towards the mouse.
var yChange:Number = Math.round(mouseY-go_mc.y);
var xChange:Number = Math.round(mouseX-go_mc.x);
var yMove:Number = Math.round(yChange/20);
var xMove:Number = Math.round(xChange/20);
 
// Nothing will work without using all this previous calculations, so we set the x and y axis and the rotation.
go_mc.y += yMove;
go_mc.x += xMove;
go_mc.rotation = myDegrees+90;
}

Related Posts

  สามารถนำบทความไปเผยแพร่ต่อได้ แต่ต้องทำ ลิงค์กับมาที่บทความนั้นๆด้วยนะครับ หากไม่ทำตามจะมีความผิดทางกฏหมายตาม พรบ. เกี่ยวกับลิขสิทธิ์ นะครับ


4 Comments »

  • am said:

    ทำให้ไม่หลุดขอบได้ไหมคับ

  • admin said:

    ทำอย่างไรคับไม่หลุดขอบ เวลาเอาเมาส์ออกนอก flash แล้วยังเคลื่อนที่ตามใช่ไหมคับ ถ้าเป็นอย่างนี้คงไม่ได้หรอกคับ เพราะว่า ต้องทำงานในพื้นที่ flash เท่านั้นคับ ถ้าอยู่นอกพื้นที่ flash แล้ว action script จะทำงานไม่ได้คับ เพราะไม่อยู่ในพื้นที่ code ก็ไม่มีการรับข้อมูลและประมวลผลใดๆครับ

  • ฟฟฟ said:

    อ้อ เม้าออกแล้วก็สั่งให้มันไปทำอย่างอื่น เช่นตรงกลางน่าจะได้นะคับ
    แอดมีนสุดหล่อ เหอๆๆ

  • น้องคอม said:

    อยากได้ไฟล์ fla อ่ะคับ

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can add images to your comment by clicking here.