【问题标题】:Need some help completing a bumptop-ish selection tool需要一些帮助来完成一个颠簸的选择工具
【发布时间】:2011-04-05 08:27:08
【问题描述】:

我正在创建一个 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); 中使用什么吗?谢谢!

更新:

我会分解的。基本上我正在尝试创建 BumpTop Lasso 或选择工具的原型。

我需要帮助找出哪些对象发生碰撞或在绘制的套索边界内有一个点。

我已经将我目前拥有的内容上传到我的服务器:http://labs.reyco1.com/bumptop/SelectionToolPrototype.html。您可以通过右键单击并选择“查看源代码”来查看源代码。

就像我在之前的帖子中所说,我尝试使用 Bitmapdata 碰撞测试,甚至尝试使用 Collision Detection Kit 均无济于事。提前致谢。

【问题讨论】:

  • 作为非常原始的方式:您可以为每个循环并测量每个组件以适合您的选择矩形。
  • 这有点含糊。哈哈。你能详细说明一下吗?谢谢
  • 您的问题实际上并未具体说明您需要做什么。您能否尝试与您正在制作的整体应用程序分开询问问题的核心? (即“如何在以下条件下在 BitmapData 中进行碰撞测试?”或类似内容)

标签: actionscript-3 flash bumptop


【解决方案1】:

循环遍历您将随机精灵附加到的显示对象,并针对每个精灵使用您的 selectionTool 实例检查它们的 hitTestObject 值。

这里是 hitTestObject() 的 Adob​​e 文档:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-28
    • 2021-05-12
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多