【AS3代码】两种碰撞检测的方法

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.utils.getTimer;
    
    public class Main extends Sprite
    {    
        var yueya:crescent = new crescent();
        var xingxing:star = new star();
        var messageText1:TextField = new TextField();
        var messageText2:TextField = new TextField();
        
        public function Main():void
        {
            init();
        }
        private function init():void
        {
            stage.addEventListener(Event.ENTER_FRAME,aa);
            this.addChild(yueya);
            this.addChild(xingxing);
            
            this.addChild(messageText1);
            messageText2.y = 20;
            this.addChild(messageText2);
        }
        public function aa(e:Event):void
        {
            //滑动检查鼠标是否和影片剪辑碰撞没
            if(yueya.hitTestPoint(this.mouseX,this.mouseY,true))
            {
                messageText1.text = "鼠标碰到月牙了!!";
            }
            else
            {
                messageText1.text = "鼠标没有碰到月牙!!!!!";
            }
            
            //让星星坐标跟随鼠标
            xingxing.x = this.mouseX;
            xingxing.y = this.mouseY;
            
            if(xingxing.hitTestObject(yueya))
            {
                messageText2.text = "星星碰到月牙了!!";
            }
            else
            {
                messageText2.text = "星星没有碰到月牙!!!!!";
            }
        }
        
    }
}
posted @ 2012-07-04 11:21  王翔(kingfly)  阅读(2693)  评论(0编辑  收藏  举报