画线碰撞?

ws

我已经在框架上进行了操作,我想做的是当我绘制的形状与碰撞时hitTest触发一个我唯一的问题是,当行点击它时,我无法直接注册,它仅在下一次click事件之后注册。我遇到的另一个问题是点击框,其比符号的实际图像大很多倍。gotoAndStop(<lose frame>)touchTesthitTesttouchTest

var myshape:Shape;
myshape = new Shape();
myshape.graphics.lineStyle(5, 0xC807DE);
var alreadyDrawn:Shape;
alreadyDrawn = new Shape();

stage.addEventListener(MouseEvent.MOUSE_DOWN, activateDraw);
function activateDraw(event:MouseEvent):void
{
    myshape.graphics.moveTo(mouseX,mouseY);
    addChild(myshape);

    stage.addEventListener(MouseEvent.MOUSE_MOVE, lineDraw);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
}

function lineDraw(event:MouseEvent):void
{
    myshape.graphics.lineTo(mouseX,mouseY);
    checkIt();
}
function stopDraw(event:MouseEvent):void
{
    alreadyDrawn.graphics.copyFrom(myshape.graphics);
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, lineDraw);
    stage.removeEventListener(MouseEvent.MOUSE_UP, stopDraw);
}

function checkIt()
{
    if (alreadyDrawn.hitTestObject(touchTest) == true)
    {
        trace("wall");
        myshape.graphics.clear();
        myshape.graphics.lineStyle(5, 0xC807DE);
        alreadyDrawn.graphics.clear(); // clear this too
        stopDraw(null); // stop active draw, if any
    }
}
你好

您可以先copyFrom在函数中使用method lineDraw,因为alreadyDrawn必须在测试之前将其绘制出来!

function lineDraw(event:MouseEvent):void
{
    myshape.graphics.lineTo(mouseX,mouseY);
    alreadyDrawn.graphics.copyFrom(myshape.graphics);
    checkIt();
}

这种方法有效,但是由于hitTest认为rectangle包含,因此无法正确进行alreadyDrawn您必须考虑point要测试的是您的mouse

function checkIt():void
{
    if (touchTest.hitTestPoint(mouseX, mouseY, true))
    {
        trace("wall");
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章