WEB开发网
开发学院图形图像Flash Flash AS3基础教程:物理基础之速度向量(Velocity... 阅读

Flash AS3基础教程:物理基础之速度向量(Velocity)

 2009-10-23 00:00:00 来源:WEB开发网   
核心提示: FollowMouse类(鼠标跟随)package { import flash.display.Sprite; import flash.events.Event; public class FollowMouse extends Sprite { privat

FollowMouse类(鼠标跟随)

package {
        import flash.display.Sprite;
        import flash.events.Event;
        public class FollowMouse extends Sprite {
                private var arrow:Arrow;
                private var speed:Number = 5;
                public function FollowMouse() {
                        init();
                }
                private function init():void {
                        arrow = new Arrow();
                        addChild(arrow);
                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
                }
                private function onEnterFrame(event:Event):void {
                        var dx:Number = mouseX - arrow.x;
                        var dy:Number = mouseY - arrow.y;
                        var angle:Number = Math.atan2(dy, dx);
                        arrow.rotation = angle * 180 / Math.PI;
                        var vx:Number = Math.cos(angle) * speed;
                        var vy:Number = Math.sin(angle) * speed;
                        arrow.x += vx;
                        arrow.y += vy;
                }
        }
}

上一页  1 2 3 4 5 

Tags:Flash AS 基础

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接