1

Bumptop スタイルの選択ツールを作成中です。現在、ツール自体を作成し(実際にはかなりうまく機能しています)、ステージ上にランダムな正方形のアイテムをいくつか広げています。これは、選択ツールを作成するクラスです:

package com.reyco1.medusa.selectiontool
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    
    public class SelectionBase extends Sprite
    {
        private var points:Array = [];
        
        public function SelectionBase()
        {
            super();
            addEventListener(Event.ADDED_TO_STAGE, initialize);
        }
        
        private function initialize(e:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, initialize);
            
            points.push(new Point(mouseX, mouseY));          stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
        }
        
        private function handleMouseMove(e:MouseEvent):void
        {           
            graphics.clear();
            
            graphics.beginFill(0x33CCFF, .5);
            graphics.drawCircle(0, 0, 20);
            graphics.endFill();
            
            graphics.moveTo(0, 0);
            graphics.lineStyle(1.5, 0x33CCFF, .5);
            graphics.lineTo(mouseX, mouseY);
            
            points.push(new Point(mouseX, mouseY));
            
            graphics.beginFill(0x33CCFF, .1);
            graphics.moveTo(points[0].x, points[0].y);
            
            for (var i:uint = 1; i < points.length; i++)
            {
                graphics.lineTo(points[i].x, points[i].y);
            }
            
            graphics.lineTo(points[0].x, points[0].y);
            graphics.endFill();
            
            dispatchEvent(new Event("UPDATE"));
        }
        
        public function clear():void
        {
            stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
            graphics.clear();
        }
    }
}

そして、これはそれを実装するドキュメント クラスです:

package
{
    import com.reyco1.medusa.selectiontool.SelectionBase;
    
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;

    [SWF(width = '1024', height = '768', backgroundColor = '0x000000')]
    public class SelectionToolPrototype extends Sprite
    {
        private var selectionTool:SelectionBase;
        
        public function SelectionToolPrototype()
        {                         
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.quality = StageQuality.MEDIUM;
                    stage.addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
            stage.addEventListener(MouseEvent.MOUSE_UP,     handleUp);  
            
            placeShapesRandomly();
        }
        
        private function placeShapesRandomly():void
        {
            for(var a:Number = 0; a<25; a++)
            {
                var s:Sprite = new Sprite();
                s.graphics.beginFill(Math.random() * 0xCCCCCC);
                s.graphics.drawRect(0, 0, 50, 50);
                s.graphics.endFill();
                s.x = Math.floor(Math.random() * 900 - 40) + 40;
                s.y = Math.floor(Math.random() * 700 - 40) + 40;
                s.rotation =  Math.floor(Math.random() * 360 - 40) + 40;
                s.buttonMode = true;
                addChild(s);
            }
        }
        
        private function handleUp(e:MouseEvent):void
        {
            selectionTool.removeEventListener("UPDATE", handleToolUpdate);
            removeChild(selectionTool);
            selectionTool = null;
        }
        
        private function handleDown(e:MouseEvent):void
        {
            selectionTool = new SelectionBase();
            selectionTool.addEventListener("UPDATE", handleToolUpdate);
            selectionTool.x = mouseX;
            selectionTool.y = mouseY;
            addChild(selectionTool);
        }
        
        private function handleToolUpdate(e:Event):void
        {
            // logic to determin if items are within selection goes here        
        }
    }
}

BitmapData を使用して衝突検出を使用し、CDK などの衝突ライブラリを使用してみましたが、何も動作しません。で何を使用すればよいか考えている人はいhandleToolUpdate(e:MouseEvent);ますか?ありがとう!

アップデート:

私はそれを分解します。基本的に、バンプトップ ラッソまたは選択ツールのプロトタイプを作成しようとしています。

どのオブジェクトが衝突しているか、描画されたなげなわの境界内にポイントがあるかを見つけるのに助けが必要です。

これまでに持っているものを、http: //labs.reyco1.com/bumptop/SelectionToolPrototype.htmlのサーバーにアップロードしました。右クリックして「ソースを表示」を選択すると、ソースが表示されます。

以前の投稿で述べたように、Bitmapdata 衝突テストを使用してみました。衝突検出キットを使用しても無駄でした。前もって感謝します。

4

1 に答える 1

0

ランダムスプライトをアタッチしている表示オブジェクトをループし、それぞれに使用して、selectionToolインスタンスに対してhitTestObjectの値を確認します。

hitTestObject()のAdobeドキュメントは次のとおりです。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject%28%29

于 2011-07-14T14:33:43.913 に答える