Actionscript 3 As3-x27;不能真正工作(嵌套)

Actionscript 3 As3-x27;不能真正工作(嵌套),actionscript-3,nested,collision,movieclip,hittest,Actionscript 3,Nested,Collision,Movieclip,Hittest,我有一辆坦克 我有一个英雄(可控制的角色) 油箱有一个嵌套的活动唇,其表面积非常薄 然而,当它甚至没有碰到英雄时,它会检测到碰撞 public class tank_sight extends MovieClip { private var _root:MovieClip; public function tank_sight() { addEventListener(Event.ADDED, beginClass); } priva

我有一辆坦克

我有一个英雄(可控制的角色)

油箱有一个嵌套的活动唇,其表面积非常薄

然而,当它甚至没有碰到英雄时,它会检测到碰撞

public class tank_sight extends MovieClip
{
    private var _root:MovieClip;

    public function tank_sight() 
    {
        addEventListener(Event.ADDED, beginClass);
    }

    private function beginClass(event:Event):void
    {
        _root = MovieClip(root);
        addEventListener(Event.ENTER_FRAME, loop);
    }

    private function loop(event:Event):void
    {
        if(this.hitTestObject(_root.hero.hitbox))
        {
            this.gotoAndStop(2);
            trace("HIT");
            fire();
        }
        else
        {
            this.gotoAndStop(1);
        }
    }

    private function fire():void
    {
        var shell:Shell = new Shell(x, y, rotation - 180);
        _root.addChild(shell);
    }
}
怎么了?我不明白

编辑:视线是旋转的,所以这可能就是原因。我尝试在player类上使用以下代码:

    point = _root.tanks.barrel.sight.localToGlobal(new Point());

        if(this.hitTestPoint(point.x, point.y, false))
                {
                    trace("HIT");
                }

但是它不起作用。。它从不跟踪“命中”,除非我在某些时候站在某个奇怪的位置。

hitTestObject
也适用于嵌套对象(显示具有不同父对象的对象),您应该检查游戏的逻辑,并进行一些测试

简单的例子:

var squareHolder:Sprite = new Sprite();
var squareInner:Shape = new Shape();
var hitHolder:Sprite = new Sprite();
var hitCircle:Shape = new Shape();

hitCircle.graphics.beginFill(0x990000);
hitCircle.graphics.drawCircle(0, 0, 20);

squareInner.graphics.beginFill(0x009900);
squareInner.graphics.drawRect(0, 0, 40, 40);

addChild(squareHolder);
squareHolder.addChild(squareInner);
squareHolder.x = 200;
squareHolder.y = 100;
squareInner.x = 50;
squareInner.y = 50;

stage.addChild(hitHolder);
hitHolder.addChild(hitCircle);
hitCircle.transform.matrix = new Matrix(1, 0.5, 0.5, 1, 30, 30);

stage.addEventListener(MouseEvent.MOUSE_MOVE, function (e:MouseEvent):void {
    hitHolder.x = e.stageX;
    hitHolder.y = e.stageY;

    if (hitCircle.hitTestObject(squareInner)) {
        trace("Ding!");
    }
});

无论你如何使用hitCircle(visible=false,trasparent fill,transformations),它都会起作用。

当你指的是我游戏的逻辑时,你到底是什么意思?我搞不清楚我写的代码出了什么问题。。它应该有用!