在local3DToGlobal调用后,hitTestPoint中断

时间:2012-11-02 19:16:37

标签: actionscript-3 flash

已解决(我认为,请参见编辑)

在displayObject的父调用local3DToGlobal之后,

hitTestPoint只给我一个false。我让父母调用它,因为我发现坐标是正确的(不知道为什么,来自http://actionscript.org/forums/showthread.php3?t=190115的想法) 有什么想法吗?

import flash.display.Shape;
import flash.geom.Point;

var circle:Shape = new Shape();
circle.graphics.beginFill(0x0000FF);
circle.graphics.drawCircle(40, 40, 40);

circle.z= 30;

addChild(circle);

stage.addEventListener(KeyboardEvent.KEY_UP, checkIt);

function checkIt(e:Event){

trace(circle.hitTestPoint(40,40,true));


var pos3D= new Vector3D(circle.x,circle.y,circle.z);
var globalLoc;

//This line doesn't break hitTestPoint, but it doesn't give the correct
//global x,y projected coordinates of the circle
globalLoc=circle.local3DToGlobal(pos3D);
trace (globalLoc);


//This line breaks the hitTest but is the only way I can get the correct
//global x,y projected coordinates of the circle.
globalLoc=circle.parent.local3DToGlobal(pos3D)
trace (globalLoc);


trace(circle.hitTestPoint(40,40,true));
}

stop();
编辑:想看到奇怪的东西?我为圆圈添加了一个容器。现在进行两次检查(按任意键两次):你得到

false(就像上次一样)


是真的(好的,更好的)

真(奇怪)


true(...)

是真的(......?)

import flash.display.Shape;
import flash.geom.Point;
import flash.display.MovieClip;

var circle:Shape = new Shape();
circle.graphics.beginFill(0x0000FF);
circle.graphics.drawCircle(40, 40, 40);

circle.z= 30;

var cont = new MovieClip();
addChild(cont);
cont.addChild(circle);

stage.addEventListener(KeyboardEvent.KEY_UP, checkIt);

function checkIt(e:Event){

    trace(circle.hitTestPoint(40,40,true));


    var pos3D= new Vector3D(circle.x,circle.y,circle.z);
    var globalLoc;

    //This line doesn't break hitTestPoint, but it doesn't give the correct
    //global x,y projected coordinates of the circle
    globalLoc=circle.local3DToGlobal(pos3D);
    trace (globalLoc);


    //This line breaks the hitTest but is the only way I can get the correct
    //global x,y projected coordinates of the circle.
    globalLoc=circle.parent.local3DToGlobal(pos3D)
    trace (globalLoc);


    trace(circle.hitTestPoint(40,40,true));
}

stop();

编辑: 解决方案我认为:

在函数

之外声明pos3D和globalLoc

将圆圈放入容器中。

抱歉,我没有该示例的固定代码,只是在整个项目中实现了它。

奇怪的东西,AS3。

0 个答案:

没有答案